Mercurial > irccd
annotate tests/test-jsapi-unicode.c @ 1083:da8f962a6540
irccd: fix invalid PONG response
author | David Demelier <markand@malikania.fr> |
---|---|
date | Tue, 20 Jul 2021 11:06:22 +0200 |
parents | 8f8ce47aba8a |
children | f06e9761cc90 |
rev | line source |
---|---|
963
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
1 /* |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
2 * test-jsapi-unicode.c -- test Irccd.Unicode API |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
3 * |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
4 * Copyright (c) 2013-2021 David Demelier <markand@malikania.fr> |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
5 * |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
6 * Permission to use, copy, modify, and/or distribute this software for any |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
7 * purpose with or without fee is hereby granted, provided that the above |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
8 * copyright notice and this permission notice appear in all copies. |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
9 * |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
17 */ |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
18 |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
19 /* |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
20 * /!\ Be sure that this file is kept saved in UTF-8 /!\ |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
21 */ |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
22 |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
23 #define GREATEST_USE_ABBREVS 0 |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
24 #include <greatest.h> |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
25 |
1037
8f8ce47aba8a
make: switch to GNU make
David Demelier <markand@malikania.fr>
parents:
985
diff
changeset
|
26 #include <irccd/config.h> |
963
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
27 #include <irccd/js-plugin.h> |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
28 #include <irccd/plugin.h> |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
29 |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
30 static struct irc_plugin *plugin; |
965
a518664b20a0
irccd: move javascript API from library to frontend
David Demelier <markand@malikania.fr>
parents:
963
diff
changeset
|
31 static duk_context *ctx; |
963
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
32 |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
33 static void |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
34 setup(void *udata) |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
35 { |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
36 (void)udata; |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
37 |
1037
8f8ce47aba8a
make: switch to GNU make
David Demelier <markand@malikania.fr>
parents:
985
diff
changeset
|
38 plugin = js_plugin_open("example", TOP "/tests/data/example-plugin.js"); |
965
a518664b20a0
irccd: move javascript API from library to frontend
David Demelier <markand@malikania.fr>
parents:
963
diff
changeset
|
39 ctx = js_plugin_get_context(plugin); |
963
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
40 } |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
41 |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
42 static void |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
43 teardown(void *udata) |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
44 { |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
45 (void)udata; |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
46 |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
47 irc_plugin_finish(plugin); |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
48 |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
49 plugin = NULL; |
965
a518664b20a0
irccd: move javascript API from library to frontend
David Demelier <markand@malikania.fr>
parents:
963
diff
changeset
|
50 ctx = NULL; |
963
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
51 } |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
52 |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
53 GREATEST_TEST |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
54 basics_is_letter(void) |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
55 { |
965
a518664b20a0
irccd: move javascript API from library to frontend
David Demelier <markand@malikania.fr>
parents:
963
diff
changeset
|
56 duk_peval_string_noresult(ctx, "result = Irccd.Unicode.isLetter(String('é').charCodeAt(0));"); |
a518664b20a0
irccd: move javascript API from library to frontend
David Demelier <markand@malikania.fr>
parents:
963
diff
changeset
|
57 GREATEST_ASSERT(duk_get_global_string(ctx, "result")); |
a518664b20a0
irccd: move javascript API from library to frontend
David Demelier <markand@malikania.fr>
parents:
963
diff
changeset
|
58 GREATEST_ASSERT(duk_get_boolean(ctx, -1)); |
963
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
59 |
965
a518664b20a0
irccd: move javascript API from library to frontend
David Demelier <markand@malikania.fr>
parents:
963
diff
changeset
|
60 duk_peval_string_noresult(ctx, "result = Irccd.Unicode.isLetter(String('€').charCodeAt(0));"); |
a518664b20a0
irccd: move javascript API from library to frontend
David Demelier <markand@malikania.fr>
parents:
963
diff
changeset
|
61 GREATEST_ASSERT(duk_get_global_string(ctx, "result")); |
a518664b20a0
irccd: move javascript API from library to frontend
David Demelier <markand@malikania.fr>
parents:
963
diff
changeset
|
62 GREATEST_ASSERT(!duk_get_boolean(ctx, -1)); |
963
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
63 |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
64 GREATEST_PASS(); |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
65 } |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
66 |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
67 GREATEST_TEST |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
68 basics_is_lower(void) |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
69 { |
965
a518664b20a0
irccd: move javascript API from library to frontend
David Demelier <markand@malikania.fr>
parents:
963
diff
changeset
|
70 duk_peval_string_noresult(ctx, "result = Irccd.Unicode.isLower(String('é').charCodeAt(0));"); |
a518664b20a0
irccd: move javascript API from library to frontend
David Demelier <markand@malikania.fr>
parents:
963
diff
changeset
|
71 GREATEST_ASSERT(duk_get_global_string(ctx, "result")); |
a518664b20a0
irccd: move javascript API from library to frontend
David Demelier <markand@malikania.fr>
parents:
963
diff
changeset
|
72 GREATEST_ASSERT(duk_get_boolean(ctx, -1)); |
963
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
73 |
965
a518664b20a0
irccd: move javascript API from library to frontend
David Demelier <markand@malikania.fr>
parents:
963
diff
changeset
|
74 duk_peval_string_noresult(ctx, "result = Irccd.Unicode.isLower(String('É').charCodeAt(0));"); |
a518664b20a0
irccd: move javascript API from library to frontend
David Demelier <markand@malikania.fr>
parents:
963
diff
changeset
|
75 GREATEST_ASSERT(duk_get_global_string(ctx, "result")); |
a518664b20a0
irccd: move javascript API from library to frontend
David Demelier <markand@malikania.fr>
parents:
963
diff
changeset
|
76 GREATEST_ASSERT(!duk_get_boolean(ctx, -1)); |
963
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
77 |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
78 GREATEST_PASS(); |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
79 } |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
80 |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
81 GREATEST_TEST |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
82 basics_is_upper(void) |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
83 { |
965
a518664b20a0
irccd: move javascript API from library to frontend
David Demelier <markand@malikania.fr>
parents:
963
diff
changeset
|
84 duk_peval_string_noresult(ctx, "result = Irccd.Unicode.isUpper(String('É').charCodeAt(0));"); |
a518664b20a0
irccd: move javascript API from library to frontend
David Demelier <markand@malikania.fr>
parents:
963
diff
changeset
|
85 GREATEST_ASSERT(duk_get_global_string(ctx, "result")); |
a518664b20a0
irccd: move javascript API from library to frontend
David Demelier <markand@malikania.fr>
parents:
963
diff
changeset
|
86 GREATEST_ASSERT(duk_get_boolean(ctx, -1)); |
963
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
87 |
965
a518664b20a0
irccd: move javascript API from library to frontend
David Demelier <markand@malikania.fr>
parents:
963
diff
changeset
|
88 duk_peval_string_noresult(ctx, "result = Irccd.Unicode.isUpper(String('é').charCodeAt(0));"); |
a518664b20a0
irccd: move javascript API from library to frontend
David Demelier <markand@malikania.fr>
parents:
963
diff
changeset
|
89 GREATEST_ASSERT(duk_get_global_string(ctx, "result")); |
a518664b20a0
irccd: move javascript API from library to frontend
David Demelier <markand@malikania.fr>
parents:
963
diff
changeset
|
90 GREATEST_ASSERT(!duk_get_boolean(ctx, -1)); |
963
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
91 |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
92 GREATEST_PASS(); |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
93 } |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
94 |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
95 GREATEST_SUITE(suite_basics) |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
96 { |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
97 GREATEST_SET_SETUP_CB(setup, NULL); |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
98 GREATEST_SET_TEARDOWN_CB(teardown, NULL); |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
99 GREATEST_RUN_TEST(basics_is_letter); |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
100 GREATEST_RUN_TEST(basics_is_lower); |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
101 GREATEST_RUN_TEST(basics_is_upper); |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
102 } |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
103 |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
104 GREATEST_MAIN_DEFS(); |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
105 |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
106 int |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
107 main(int argc, char **argv) |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
108 { |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
109 GREATEST_MAIN_BEGIN(); |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
110 GREATEST_RUN_SUITE(suite_basics); |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
111 GREATEST_MAIN_END(); |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
112 |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
113 return 0; |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
114 } |