nexmon – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | office | 1 | #include "config.h" |
2 | |||
3 | #include <locale.h> |
||
4 | #include <glib.h> |
||
5 | |||
6 | typedef struct |
||
7 | { |
||
8 | const gchar *string; |
||
9 | const gchar *prefix; |
||
10 | gboolean should_match; |
||
11 | } SearchTest; |
||
12 | |||
13 | static void |
||
14 | test_search (void) |
||
15 | { |
||
16 | SearchTest tests[] = |
||
17 | { |
||
18 | /* Test word separators and case */ |
||
19 | { "Hello World", "he", TRUE }, |
||
20 | { "Hello World", "wo", TRUE }, |
||
21 | { "Hello World", "lo", FALSE }, |
||
22 | { "Hello World", "ld", FALSE }, |
||
23 | { "Hello-World", "wo", TRUE }, |
||
24 | { "HelloWorld", "wo", FALSE }, |
||
25 | |||
26 | /* Test composed chars (accentued letters) */ |
||
27 | { "Jörgen", "jor", TRUE }, |
||
28 | { "Gaëtan", "gaetan", TRUE }, |
||
29 | { "élève", "ele", TRUE }, |
||
30 | { "Azais", "AzaÏs", FALSE }, |
||
31 | { "AzaÏs", "Azais", TRUE }, |
||
32 | |||
33 | /* Test decomposed chars, they looks the same, but are actually |
||
34 | * composed of multiple unicodes */ |
||
35 | { "Jorgen", "Jör", FALSE }, |
||
36 | { "Jörgen", "jor", TRUE }, |
||
37 | |||
38 | /* Turkish special case */ |
||
39 | { "İstanbul", "ist", TRUE }, |
||
40 | { "Diyarbakır", "diyarbakir", TRUE }, |
||
41 | |||
42 | /* Multi words */ |
||
43 | { "Xavier Claessens", "Xav Cla", TRUE }, |
||
44 | { "Xavier Claessens", "Cla Xav", TRUE }, |
||
45 | { "Foo Bar Baz", " b ", TRUE }, |
||
46 | { "Foo Bar Baz", "bar bazz", FALSE }, |
||
47 | |||
48 | { NULL, NULL, FALSE } |
||
49 | }; |
||
50 | guint i; |
||
51 | |||
52 | setlocale(LC_ALL, ""); |
||
53 | |||
54 | g_debug ("Started"); |
||
55 | for (i = 0; tests[i].string != NULL; i ++) |
||
56 | { |
||
57 | gboolean match; |
||
58 | gboolean ok; |
||
59 | |||
60 | match = g_str_match_string (tests[i].prefix, tests[i].string, TRUE); |
||
61 | ok = (match == tests[i].should_match); |
||
62 | |||
63 | g_debug ("'%s' - '%s' %s: %s", tests[i].prefix, tests[i].string, |
||
64 | tests[i].should_match ? "should match" : "should NOT match", |
||
65 | ok ? "OK" : "FAILED"); |
||
66 | |||
67 | g_assert (ok); |
||
68 | } |
||
69 | } |
||
70 | |||
71 | int |
||
72 | main (int argc, |
||
73 | char **argv) |
||
74 | { |
||
75 | g_test_init (&argc, &argv, NULL); |
||
76 | |||
77 | g_test_add_func ("/search", test_search); |
||
78 | |||
79 | return g_test_run (); |
||
80 | } |