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]",
48 /* They are not links! */
49 "http://", "http[:/]/", /* Hm... */
51 "w.foo.com", "w.foo.com",
52 "@server.com", "@server.com",
53 "mailto:user@", "mailto:user@",
54 "mailto:user@.com", "mailto:user@.com",
55 "user@.com", "user@.com",
57 /* Links inside (), {}, [], <> or "" */
58 /* FIXME: How to test if the ending ] is matched or not? */
59 "Foo (www.foo.com)", "Foo ([www.foo.com])",
60 "Foo {www.foo.com}", "Foo {[www.foo.com]}",
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/bar(123)baz)", "Foo ([www.foo.com/bar(123)baz])",
65 "<a href=\"http://foo.com\">bar</a>", "<a href="[http://foo.com]">bar</a>",
66 "Foo (user@server.com)", "Foo ([user@server.com])",
67 "Foo {user@server.com}", "Foo {[user@server.com]}",
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]"",
77 /* Smileys and links mixed */
78 ":)http://foo.com", "[:)][http://foo.com]",
79 "a :) b http://foo.com c :( d www.test.com e", "a [:)] b [http://foo.com] c [:(] d [www.test.com] e",
81 /* '\r' should be stripped */
82 "badger\n\rmushroom", "badger\nmushroom",
83 "badger\r\nmushroom", "badger\nmushroom",
85 /* FIXME: Known issue: Brackets should be counted by the parser */
86 //"Foo www.bar.com/test(123)", "Foo [www.bar.com/test(123)]",
87 //"Foo (www.bar.com/test(123))", "Foo ([www.bar.com/test(123)])",
88 //"Foo www.bar.com/test{123}", "Foo [www.bar.com/test{123}]",
89 //"Foo (:))", "Foo ([:)])",
90 //"Foo <a href=\"http://foo.com\">:)</a>", "Foo <a href=\"[http://foo.com]\">[:)]</a>",
94 EmpathyStringParser parsers[] =
96 {empathy_string_match_link, test_replace_match},
97 {empathy_string_match_smiley, test_replace_match},
98 {empathy_string_match_all, empathy_string_replace_escaped},
104 for (i = 0; tests[i] != NULL; i += 2)
109 string = g_string_new (NULL);
110 empathy_string_parser_substr (tests[i], -1, parsers, string);
112 ok = !tp_strdiff (tests[i + 1], string->str);
113 DEBUG ("'%s' => '%s': %s", tests[i], string->str, ok ? "OK" : "FAILED");
116 g_string_free (string, TRUE);
126 test_init (argc, argv);
128 g_test_add_func ("/parsers", test_parsers);
130 result = g_test_run ();