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, ']');
32 /* Basic link matches */
33 "http://foo.com", "[http://foo.com]",
34 "http://foo.com\nhttp://bar.com", "[http://foo.com]\n[http://bar.com]",
35 "http://foo.com/test?id=bar?", "[http://foo.com/test?id=bar]?",
36 "git://foo.com", "[git://foo.com]",
37 "git+ssh://foo.com", "[git+ssh://foo.com]",
38 "mailto:user@server.com", "[mailto:user@server.com]",
39 "www.foo.com", "[www.foo.com]",
40 "ftp.foo.com", "[ftp.foo.com]",
41 "user@server.com", "[user@server.com]",
42 "first.last@server.com", "[first.last@server.com]",
43 "http://foo.com. bar", "[http://foo.com]. bar",
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://apos'foo.com", "[http://apos'foo.com]",
48 "mailto:bar'?user@server.com", "[mailto:bar'?user@server.com]",
50 /* They are not links! */
51 "http://", "http[:/]/", /* Hm... */
53 "w.foo.com", "w.foo.com",
54 "@server.com", "@server.com",
55 "mailto:user@", "mailto:user@",
56 "mailto:user@.com", "mailto:user@.com",
57 "user@.com", "user@.com",
59 /* Links inside (), {}, [], <>, "" or '' */
60 /* FIXME: How to test if the ending ] is matched or not? */
61 "Foo (www.foo.com)", "Foo ([www.foo.com])",
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 "[www.foo.com]"",
66 "Foo (www.foo.com/bar(123)baz)", "Foo ([www.foo.com/bar(123)baz])",
67 "<a href=\"http://foo.com\">bar</a>", "<a href="[http://foo.com]">bar</a>",
68 "Foo (user@server.com)", "Foo ([user@server.com])",
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 "[user@server.com]"",
73 "<a href='http://apos'foo.com'>bar</a>", "<a href='[http://apos'foo.com]'>bar</a>",
74 "Foo 'bar'?user@server.com'", "Foo '[bar'?user@server.com]'",
81 /* Smileys and links mixed */
82 ":)http://foo.com", "[:)][http://foo.com]",
83 "a :) b http://foo.com c :( d www.test.com e", "a [:)] b [http://foo.com] c [:(] d [www.test.com] e",
85 /* '\r' should be stripped */
86 "badger\n\rmushroom", "badger\nmushroom",
87 "badger\r\nmushroom", "badger\nmushroom",
89 /* FIXME: Known issue: Brackets should be counted by the parser */
90 //"Foo www.bar.com/test(123)", "Foo [www.bar.com/test(123)]",
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 (:))", "Foo ([:)])",
94 //"Foo <a href=\"http://foo.com\">:)</a>", "Foo <a href=\"[http://foo.com]\">[:)]</a>",
98 EmpathyStringParser parsers[] =
100 {empathy_string_match_link, test_replace_match},
101 {empathy_string_match_smiley, test_replace_match},
102 {empathy_string_match_all, empathy_string_replace_escaped},
108 for (i = 0; tests[i] != NULL; i += 2)
113 string = g_string_new (NULL);
114 empathy_string_parser_substr (tests[i], -1, parsers, string);
116 ok = !tp_strdiff (tests[i + 1], string->str);
117 DEBUG ("'%s' => '%s': %s", tests[i], string->str, ok ? "OK" : "FAILED");
120 g_string_free (string, TRUE);
130 test_init (argc, argv);
132 g_test_add_func ("/parsers", test_parsers);
134 result = g_test_run ();