summaryrefslogtreecommitdiffstats
blob: 332d16742a8ae294329f15c261947568bbef80cc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
/*
 * Copyright (c) 2010 Remko Tronçon
 * Licensed under the GNU General Public License v3.
 * See Documentation/Licenses/GPLv3.txt for more information.
 */

#include <cppunit/extensions/HelperMacros.h>
#include <cppunit/extensions/TestFactoryRegistry.h>

#include "SwifTools/Linkify.h"

using namespace Swift;

class LinkifyTest : public CppUnit::TestFixture {
		CPPUNIT_TEST_SUITE(LinkifyTest);
		CPPUNIT_TEST(testLinkify_URLWithResource);
		CPPUNIT_TEST(testLinkify_URLWithEmptyResource);
		CPPUNIT_TEST(testLinkify_BareURL);
		CPPUNIT_TEST(testLinkify_URLSurroundedByWhitespace);
		CPPUNIT_TEST(testLinkify_MultipleURLs);
		CPPUNIT_TEST(testLinkify_CamelCase);
		CPPUNIT_TEST(testLinkify_HierarchicalResource);
		CPPUNIT_TEST(testLinkify_Anchor);
		CPPUNIT_TEST(testLinkify_Plus);
		CPPUNIT_TEST(testLinkify_Tilde);
		CPPUNIT_TEST(testLinkify_Authentication);
		CPPUNIT_TEST_SUITE_END();

	public:
		void testLinkify_URLWithResource() {
			String result = Linkify::linkify("http://swift.im/blog");

			CPPUNIT_ASSERT_EQUAL(
					String("<a href=\"http://swift.im/blog\">http://swift.im/blog</a>"),
					result);
		}

		void testLinkify_URLWithEmptyResource() {
			String result = Linkify::linkify("http://swift.im/");

			CPPUNIT_ASSERT_EQUAL(
					String("<a href=\"http://swift.im/\">http://swift.im/</a>"),
					result);
		}


		void testLinkify_BareURL() {
			String result = Linkify::linkify("http://swift.im");

			CPPUNIT_ASSERT_EQUAL(
					String("<a href=\"http://swift.im\">http://swift.im</a>"),
					result);
		}

		void testLinkify_URLSurroundedByWhitespace() {
			String result = Linkify::linkify("Foo http://swift.im/blog Bar");

			CPPUNIT_ASSERT_EQUAL(
					String("Foo <a href=\"http://swift.im/blog\">http://swift.im/blog</a> Bar"),
					result);
		}

		void testLinkify_MultipleURLs() {
			String result = Linkify::linkify("Foo http://swift.im/blog Bar http://el-tramo.be/about Baz");

			CPPUNIT_ASSERT_EQUAL(
					String("Foo <a href=\"http://swift.im/blog\">http://swift.im/blog</a> Bar <a href=\"http://el-tramo.be/about\">http://el-tramo.be/about</a> Baz"),
					result);
		}

		void testLinkify_CamelCase() {
			String result = Linkify::linkify("http://fOo.cOm/bAz");

			CPPUNIT_ASSERT_EQUAL(
					String("<a href=\"http://fOo.cOm/bAz\">http://fOo.cOm/bAz</a>"),
					result);
		}

		void testLinkify_HierarchicalResource() {
			String result = Linkify::linkify("http://foo.com/bar/baz/");

			CPPUNIT_ASSERT_EQUAL(
					String("<a href=\"http://foo.com/bar/baz/\">http://foo.com/bar/baz/</a>"),
					result);
		}

		void testLinkify_Anchor() {
			String result = Linkify::linkify("http://foo.com/bar#baz");

			CPPUNIT_ASSERT_EQUAL(
					String("<a href=\"http://foo.com/bar#baz\">http://foo.com/bar#baz</a>"),
					result);
		}

		void testLinkify_Plus() {
			String result = Linkify::linkify("http://foo.com/bar+baz");

			CPPUNIT_ASSERT_EQUAL(
					String("<a href=\"http://foo.com/bar+baz\">http://foo.com/bar+baz</a>"),
					result);
		}

		void testLinkify_Tilde() {
			String result = Linkify::linkify("http://foo.com/~kev/");

			CPPUNIT_ASSERT_EQUAL(
					String("<a href=\"http://foo.com/~kev/\">http://foo.com/~kev/</a>"),
					result);
		}

		void testLinkify_Authentication() {
			String result = Linkify::linkify("http://bob:bla@swift.im/foo/bar");

			CPPUNIT_ASSERT_EQUAL(
					String("<a href=\"http://bob:bla@swift.im/foo/bar\">http://bob:bla@swift.im/foo/bar</a>"),
					result);
		}
};

CPPUNIT_TEST_SUITE_REGISTRATION(LinkifyTest);