Fix a typo in the Galician user help translation
[empathy-mirror.git] / tests / empathy-parser-test.c
blob843bf368cf6ea0b81677d765d1e2d8dc6d0d15e4
1 #include "config.h"
3 #include <stdlib.h>
4 #include <stdio.h>
5 #include <string.h>
6 #include <telepathy-glib/telepathy-glib.h>
7 #include <tp-account-widgets/tpaw-string-parser.h>
9 #include "empathy-string-parser.h"
10 #include "test-helper.h"
12 #define DEBUG_FLAG EMPATHY_DEBUG_TESTS
13 #include "empathy-debug.h"
15 static void
16 test_replace_match (const gchar *text,
17 gssize len,
18 gpointer match_data,
19 gpointer user_data)
21 GString *string = user_data;
23 g_string_append_c (string, '[');
24 g_string_append_len (string, text, len);
25 g_string_append_c (string, ']');
28 static void
29 test_parsers (void)
31 gchar *tests[] =
33 /* Basic link matches */
34 "http://foo.com", "[http://foo.com]",
35 "http://foo.com\nhttp://bar.com", "[http://foo.com]\n[http://bar.com]",
36 "http://foo.com/test?id=bar?", "[http://foo.com/test?id=bar]?",
37 "git://foo.com", "[git://foo.com]",
38 "git+ssh://foo.com", "[git+ssh://foo.com]",
39 "mailto:user@server.com", "[mailto:user@server.com]",
40 "www.foo.com", "[www.foo.com]",
41 "ftp.foo.com", "[ftp.foo.com]",
42 "user@server.com", "[user@server.com]",
43 "first.last@server.com", "[first.last@server.com]",
44 "http://foo.com. bar", "[http://foo.com]. bar",
45 "http://foo.com; bar", "[http://foo.com]; bar",
46 "http://foo.com: bar", "[http://foo.com]: bar",
47 "http://foo.com:bar", "[http://foo.com:bar]",
48 "http://apos'foo.com", "[http://apos'foo.com]",
49 "mailto:bar'?user@server.com", "[mailto:bar'?user@server.com]",
51 /* They are not links! */
52 "http://", "http[:/]/", /* Hm... */
53 "www.", "www.",
54 "w.foo.com", "w.foo.com",
55 "@server.com", "@server.com",
56 "mailto:user@", "mailto:user@",
57 "mailto:user@.com", "mailto:user@.com",
58 "user@.com", "user@.com",
60 /* Links inside (), {}, [], <>, "" or '' */
61 /* FIXME: How to test if the ending ] is matched or not? */
62 "Foo (www.foo.com)", "Foo ([www.foo.com])",
63 "Foo {www.foo.com}", "Foo {[www.foo.com]}",
64 "Foo [www.foo.com]", "Foo [[www.foo.com]]",
65 "Foo <www.foo.com>", "Foo &lt;[www.foo.com]&gt;",
66 "Foo \"www.foo.com\"", "Foo &quot;[www.foo.com]&quot;",
67 "Foo (www.foo.com/bar(123)baz)", "Foo ([www.foo.com/bar(123)baz])",
68 "<a href=\"http://foo.com\">bar</a>", "&lt;a href=&quot;[http://foo.com]&quot;&gt;bar&lt;/a&gt;",
69 "Foo (user@server.com)", "Foo ([user@server.com])",
70 "Foo {user@server.com}", "Foo {[user@server.com]}",
71 "Foo [user@server.com]", "Foo [[user@server.com]]",
72 "Foo <user@server.com>", "Foo &lt;[user@server.com]&gt;",
73 "Foo \"user@server.com\"", "Foo &quot;[user@server.com]&quot;",
74 "<a href='http://apos'foo.com'>bar</a>", "&lt;a href=&apos;[http://apos'foo.com]&apos;&gt;bar&lt;/a&gt;",
75 "Foo 'bar'?user@server.com'", "Foo &apos;[bar'?user@server.com]&apos;",
77 /* Basic smileys */
78 "a:)b", "a[:)]b",
79 ">:)", "[>:)]",
80 ">:(", "&gt;[:(]",
82 /* Smileys and links mixed */
83 ":)http://foo.com", "[:)][http://foo.com]",
84 "a :) b http://foo.com c :( d www.test.com e", "a [:)] b [http://foo.com] c [:(] d [www.test.com] e",
86 /* '\r' should be stripped */
87 "badger\n\rmushroom", "badger\nmushroom",
88 "badger\r\nmushroom", "badger\nmushroom",
90 /* FIXME: Known issue: Brackets should be counted by the parser */
91 //"Foo www.bar.com/test(123)", "Foo [www.bar.com/test(123)]",
92 //"Foo (www.bar.com/test(123))", "Foo ([www.bar.com/test(123)])",
93 //"Foo www.bar.com/test{123}", "Foo [www.bar.com/test{123}]",
94 //"Foo (:))", "Foo ([:)])",
95 //"Foo <a href=\"http://foo.com\">:)</a>", "Foo <a href=\"[http://foo.com]\">[:)]</a>",
97 NULL, NULL
99 TpawStringParser parsers[] =
101 {tpaw_string_match_link, test_replace_match},
102 {empathy_string_match_smiley, test_replace_match},
103 {tpaw_string_match_all, tpaw_string_replace_escaped},
104 {NULL, NULL}
106 guint i;
108 DEBUG ("Started");
109 for (i = 0; tests[i] != NULL; i += 2)
111 GString *string;
112 gboolean ok;
114 string = g_string_new (NULL);
115 tpaw_string_parser_substr (tests[i], -1, parsers, string);
117 ok = !tp_strdiff (tests[i + 1], string->str);
118 DEBUG ("'%s' => '%s': %s", tests[i], string->str, ok ? "OK" : "FAILED");
119 g_assert (ok);
121 g_string_free (string, TRUE);
126 main (int argc,
127 char **argv)
129 int result;
131 test_init (argc, argv);
133 g_test_add_func ("/parsers", test_parsers);
135 result = g_test_run ();
136 test_deinit ();
138 return result;