-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtest.js
67 lines (58 loc) · 2.46 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
const test = require('node:test')
const assert = require('node:assert')
const { isValidEmail } = require('.')
test('basic emails', () => {
assert.strictEqual(isValidEmail('aaa@bbb.com'), true)
assert.strictEqual(isValidEmail('kjetilk@hotmail.com'), true)
assert.strictEqual(isValidEmail('koh.lis@gmail.com'), true)
assert.strictEqual(isValidEmail('koh.lis+test@gmail.com'), true)
assert.strictEqual(isValidEmail('errxn@yahoo.com'), true)
assert.strictEqual(isValidEmail('qrczak@icloud.com'), true)
assert.strictEqual(isValidEmail('crimsane@msn.com'), true)
assert.strictEqual(isValidEmail('pgolle@optonline.net'), true)
assert.strictEqual(isValidEmail('stakasa@msn.com'), true)
assert.strictEqual(isValidEmail('denism@me.com'), true)
assert.strictEqual(isValidEmail('matsn@verizon.net'), true)
assert.strictEqual(isValidEmail('formis@msn.com'), true)
assert.strictEqual(isValidEmail('kewley@att.net'), true)
assert.strictEqual(isValidEmail('elmer@att.net'), true)
})
test('valid characters', () => {
assert.strictEqual(
isValidEmail(
"abcdefg.hijklmnopqrstuvwxyz!#$%&'*/=?^_+-`{|}~0123456789@acme-inc.com"
),
true
)
assert.strictEqual(isValidEmail('denism[]@me.com'), false)
})
test('Only one @ allowed', () => {
assert.strictEqual(isValidEmail('denism@@me.com'), false)
assert.strictEqual(isValidEmail('@me.com'), false)
assert.strictEqual(isValidEmail('fooobar@'), false)
})
test('accents are not allowed', () => {
assert.strictEqual(isValidEmail('denismé@me.com'), false)
assert.strictEqual(isValidEmail('françois@me.com'), false)
})
test('period character', () => {
assert.strictEqual(isValidEmail('a..a@test.jp'), true)
assert.strictEqual(isValidEmail('a..@test.jp'), true)
assert.strictEqual(isValidEmail('.a@test.jp'), false)
})
test('base64', () => {
assert.strictEqual(isValidEmail('TWFuIGlzIGRpc3Rpbmd1aXNoZWQsIG5vdCB'), false)
})
test('spaces are not allowed', () => {
assert.strictEqual(isValidEmail('xxx yyy@gmail.com'), false)
assert.strictEqual(isValidEmail(' aaa@dot.com'), false)
assert.strictEqual(isValidEmail('aaa@dot.com\t'), false)
})
test('comments are not allowed', () => {
assert.strictEqual(isValidEmail('john.doe@(comment)example.com'), false)
assert.strictEqual(isValidEmail('john.doe@example.com(comment)'), false)
})
test('domains without extension are rejected', () => {
assert.strictEqual(isValidEmail('foo.bar@gmail'), false)
assert.strictEqual(isValidEmail('a.b@microsoft'), false)
})