5 #include "test-helper.h"
7 #include <telepathy-glib/util.h>
9 #define DEBUG_FLAG EMPATHY_DEBUG_TESTS
10 #include <libempathy/empathy-debug.h>
12 #include <libempathy-gtk/empathy-string-parser.h>
15 test_replace_match (const gchar *text,
20 GString *string = user_data;
22 g_string_append_c (string, '[');
23 g_string_append_len (string, text, len);
24 g_string_append_c (string, ']');
28 test_replace_verbatim (const gchar *text,
33 GString *string = user_data;
35 g_string_append_len (string, text, len);
43 /* Basic link matches */
44 "http://foo.com", "[http://foo.com]",
45 "http://foo.com\nhttp://bar.com", "[http://foo.com]\n[http://bar.com]",
46 "http://foo.com/test?id=bar?", "[http://foo.com/test?id=bar]?",
47 "git://foo.com", "[git://foo.com]",
48 "git+ssh://foo.com", "[git+ssh://foo.com]",
49 "mailto:user@server.com", "[mailto:user@server.com]",
50 "www.foo.com", "[www.foo.com]",
51 "ftp.foo.com", "[ftp.foo.com]",
52 "user@server.com", "[user@server.com]",
53 "first.last@server.com", "[first.last@server.com]",
54 "http://foo.com. bar", "[http://foo.com]. bar",
55 "http://foo.com; bar", "[http://foo.com]; bar",
56 "http://foo.com: bar", "[http://foo.com]: bar",
57 "http://foo.com:bar", "[http://foo.com:bar]",
59 /* They are not links! */
60 "http://", "http[:/]/", /* Hm... */
62 "w.foo.com", "w.foo.com",
63 "@server.com", "@server.com",
64 "mailto:user@", "mailto:user@",
65 "mailto:user@.com", "mailto:user@.com",
66 "user@.com", "user@.com",
68 /* Links inside (), {}, [], <> or "" */
69 /* FIXME: How to test if the ending ] is matched or not? */
70 "Foo (www.foo.com)", "Foo ([www.foo.com])",
71 "Foo {www.foo.com}", "Foo {[www.foo.com]}",
72 "Foo [www.foo.com]", "Foo [[www.foo.com]]",
73 "Foo <www.foo.com>", "Foo <[www.foo.com]>",
74 "Foo \"www.foo.com\"", "Foo \"[www.foo.com]\"",
75 "Foo (www.foo.com/bar(123)baz)", "Foo ([www.foo.com/bar(123)baz])",
76 "<a href=\"http://foo.com\">bar</a>", "<a href=\"[http://foo.com]\">bar</a>",
77 "Foo (user@server.com)", "Foo ([user@server.com])",
78 "Foo {user@server.com}", "Foo {[user@server.com]}",
79 "Foo [user@server.com]", "Foo [[user@server.com]]",
80 "Foo <user@server.com>", "Foo <[user@server.com]>",
81 "Foo \"user@server.com\"", "Foo \"[user@server.com]\"",
88 /* Smileys and links mixed */
89 ":)http://foo.com", "[:)][http://foo.com]",
90 "a :) b http://foo.com c :( d www.test.com e", "a [:)] b [http://foo.com] c [:(] d [www.test.com] e",
92 /* FIXME: Known issue: Brackets should be counted by the parser */
93 //"Foo www.bar.com/test(123)", "Foo [www.bar.com/test(123)]",
94 //"Foo (www.bar.com/test(123))", "Foo ([www.bar.com/test(123)])",
95 //"Foo www.bar.com/test{123}", "Foo [www.bar.com/test{123}]",
96 //"Foo (:))", "Foo ([:)])",
97 //"Foo <a href=\"http://foo.com\">:)</a>", "Foo <a href=\"[http://foo.com]\">[:)]</a>",
101 EmpathyStringParser parsers[] =
103 {empathy_string_match_link, test_replace_match},
104 {empathy_string_match_smiley, test_replace_match},
105 {empathy_string_match_all, test_replace_verbatim},
109 gboolean failed = FALSE;
112 for (i = 0; tests[i] != NULL; i += 2)
117 string = g_string_new (NULL);
118 empathy_string_parser_substr (tests[i], -1, parsers, string);
120 ok = !tp_strdiff (tests[i + 1], string->str);
121 DEBUG ("'%s' => '%s': %s", tests[i], string->str, ok ? "OK" : "FAILED");
125 g_string_free (string, TRUE);
137 test_init (argc, argv);
139 g_test_add_func ("/parsers", test_parsers);
141 result = g_test_run ();