5 #include "test-helper.h"
7 #define DEBUG_FLAG EMPATHY_DEBUG_TESTS
8 #include <libempathy/empathy-debug.h>
10 #include <libempathy-gtk/empathy-ui-utils.h>
13 test_replace_match (const gchar *text,
18 GString *string = user_data;
20 g_string_append_c (string, '[');
21 g_string_append_len (string, text, len);
22 g_string_append_c (string, ']');
26 test_replace_verbatim (const gchar *text,
31 GString *string = user_data;
33 g_string_append_len (string, text, len);
42 /* Basic link matches */
43 "http://foo.com", "[http://foo.com]",
44 "git://foo.com", "[git://foo.com]",
45 "git+ssh://foo.com", "[git+ssh://foo.com]",
46 "mailto:user@server.com", "[mailto:user@server.com]",
47 "www.foo.com", "[www.foo.com]",
48 "ftp.foo.com", "[ftp.foo.com]",
49 "user@server.com", "[user@server.com]",
50 "http://foo.com. bar", "[http://foo.com]. bar",
51 "http://foo.com; bar", "[http://foo.com]; bar",
52 "http://foo.com: bar", "[http://foo.com]: bar",
53 "http://foo.com:bar", "[http://foo.com:bar]",
55 /* They are not links! */
56 "http://", "http[:/]/", /* Hm... */
58 "w.foo.com", "w.foo.com",
59 "@server.com", "@server.com",
60 "mailto:user@", "mailto:user@",
61 "mailto:user@.com", "mailto:user@.com",
62 "user@.com", "user@.com",
64 /* Links inside (), {}, [] or "" */
65 /* FIXME: How to test if the ending ] is matched or not? */
66 "Foo (www.foo.com)", "Foo ([www.foo.com])",
67 "Foo {www.foo.com}", "Foo {[www.foo.com]}",
68 "Foo [www.foo.com]", "Foo [[www.foo.com]]",
69 "Foo \"www.foo.com\"", "Foo \"[www.foo.com]\"",
70 "Foo (www.foo.com/bar(123)baz)", "Foo ([www.foo.com/bar(123)baz])",
71 "<a href=\"http://foo.com\">bar</a>", "<a href=\"[http://foo.com]\">bar</a>",
78 /* Smileys and links mixed */
79 ":)http://foo.com", "[:)][http://foo.com]",
80 "a :) b http://foo.com c :( d www.test.com e", "a [:)] b [http://foo.com] c [:(] d [www.test.com] e",
82 /* FIXME: Known issues. Brackets should be counted by the parser */
83 //"Foo www.bar.com/test(123)", "Foo [www.bar.com/test(123)]",
84 //"Foo (www.bar.com/test(123))", "Foo ([www.bar.com/test(123)])",
85 //"Foo www.bar.com/test{123}", "Foo [www.bar.com/test{123}]",
86 //"Foo (:))", "Foo ([:)])",
87 //"Foo <a href=\"http://foo.com\">:)</a>", "Foo <a href=\"[http://foo.com]\">[:)]</a>",
91 EmpathyStringParser parsers[] =
93 {empathy_string_match_link, test_replace_match},
94 {empathy_string_match_smiley, test_replace_match},
95 {empathy_string_match_all, test_replace_verbatim},
100 for (i = 0; tests[i] != NULL; i += 2)
104 string = g_string_new (NULL);
105 empathy_string_parser_substr (tests[i], -1, parsers, string);
107 DEBUG ("'%s' => '%s'", tests[i], string->str);
108 g_assert_cmpstr (tests[i + 1], ==, string->str);
110 g_string_free (string, TRUE);
120 test_init (argc, argv);
122 g_test_add_func ("/parsers", test_parsers);
124 result = g_test_run ();