/
test.js
149 lines (128 loc) · 3.12 KB
/
test.js
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
"use strict"
// import test from 'ava'
// import fn from '.'
const test = require("ava")
const fn = require(".")
// failures
test("zero-0", (t) => {
const { url, email, error } = fn()
t.truthy(error)
t.falsy(url)
t.falsy(email)
})
test("zero-1", (t) => {
const { url, email, error } = fn(" ")
t.truthy(error)
t.falsy(url)
t.falsy(email)
})
test("zero-2", (t) => {
const { url, email, error } = fn(".")
t.truthy(error)
t.falsy(url)
t.falsy(email)
})
test("zero-2b", (t) => {
const { url, email, error } = fn("gg.")
t.truthy(error)
t.falsy(url)
t.falsy(email)
})
test("zero", (t) => {
const { url, email, error } = fn("joe@bob.ca/john")
t.truthy(error)
t.falsy(url)
t.falsy(email)
})
test("zero-4", (t) => {
const { url, email, error } = fn("bob")
t.truthy(error)
t.falsy(url)
t.falsy(email)
})
test("zero-5", (t) => {
const { url, email, error } = fn("Public Profilehttps://www.linkedin.com/in")
t.truthy(error)
t.falsy(url)
t.falsy(email)
})
// successes
test("url with path, missing http", (t) => {
const { url, email, error } = fn("bob.ca")
t.falsy(error)
t.is(url, "http://bob.ca")
t.falsy(email)
})
test("url with path, with http (v2)", (t) => {
const { url, email, error } = fn("http://bob.ca")
t.falsy(error)
t.is(url, "http://bob.ca")
t.falsy(email)
})
test("url with path, with https", (t) => {
const { url, email, error } = fn("https://bob.ca")
t.falsy(error)
t.is(url, "https://bob.ca")
t.falsy(email)
})
test("url with path, missing http (v3)", (t) => {
const { url, email, error } = fn("bob.ca/joe")
t.falsy(error)
t.is(url, "http://bob.ca/joe")
t.falsy(email)
})
test("url: lowercase domain", (t) => {
const { url, email, error } = fn("Bob.ca/joe")
t.falsy(error)
t.is(url, "http://bob.ca/joe")
t.falsy(email)
})
test("url: lowercase domain, cased path", (t) => {
const { url, email, error } = fn("Bob.ca/Joe")
t.falsy(error)
t.is(url, "http://bob.ca/Joe")
t.falsy(email)
})
test("url containing a @ in the path", (t) => {
const { url, email, error } = fn("bob.ca/joe@john")
t.falsy(error)
t.is(url, "http://bob.ca/joe@john")
t.falsy(email)
})
test("plain email", (t) => {
const { url, email, error } = fn("joe@bob.ca")
t.falsy(error)
t.falsy(url)
t.is(email, "joe@bob.ca")
})
test("idn url fixed", (t) => {
const { url, email, error } = fn("www.êxample.com")
t.falsy(error)
t.is(url, "http://www.xn--xample-hva.com")
t.falsy(email)
})
test("idn email", (t) => {
const { url, email, error } = fn("joe@xn--xample-hva.com")
t.falsy(error)
t.falsy(url)
t.is(email, "joe@xn--xample-hva.com")
})
test("idn url", (t) => {
const { url, email, error } = fn("http://xn--xample-hva.com")
t.falsy(error)
t.is(url, "http://xn--xample-hva.com")
t.falsy(email)
})
test("tiny url", (t) => {
const { url, email, error } = fn("g.g")
t.falsy(error)
t.is(url, "http://g.g")
t.falsy(email)
})
// FIXME: should not error, êxample should be "punycoded"
test.skip("idn email fixed", (t) => {
const { url, email, error } = fn("joe@www.êxample.com")
t.falsy(error)
t.falsy(url)
t.is(email, "joe@xn--xample-hva.com")
})