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"
16 test_replace_match (const gchar
*text
,
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
, ']');
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... */
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 <[www.foo.com]>",
66 "Foo \"www.foo.com\"", "Foo "[www.foo.com]"",
67 "Foo (www.foo.com/bar(123)baz)", "Foo ([www.foo.com/bar(123)baz])",
68 "<a href=\"http://foo.com\">bar</a>", "<a href="[http://foo.com]">bar</a>",
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 "Foo \"user@server.com\"", "Foo "[user@server.com]"",
74 "<a href='http://apos'foo.com'>bar</a>", "<a href='[http://apos'foo.com]'>bar</a>",
75 "Foo 'bar'?user@server.com'", "Foo '[bar'?user@server.com]'",
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>",
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
},
109 for (i
= 0; tests
[i
] != NULL
; i
+= 2)
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");
121 g_string_free (string
, TRUE
);
131 test_init (argc
, argv
);
133 g_test_add_func ("/parsers", test_parsers
);
135 result
= g_test_run ();