-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathtest.js
81 lines (66 loc) · 2.9 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
var assert = require("assert");
var jppr = require("./index")
describe( "a better jp phone regex", function() {
describe("fixed phones", function() {
it("should match to valid fixed phone numbers", function() {
assert.equal(true, jppr.fixed.test("03-1111-1111"));
assert.equal(true, jppr.fixed.test("044-111-1111"));
assert.equal(true, jppr.fixed.test("0466-11-1111"));
assert.equal(true, jppr.fixed.test("01267-1-1111"));
})
it("should ignore hyphens", function() {
assert.equal(true, jppr.fixed.test("039999-1111"));
assert.equal(true, jppr.fixed.test("03-11119999"));
assert.equal(true, jppr.fixed.test("0312345678"));
})
it("should not match to invalid fixed phone numbers", function() {
assert.equal(false, jppr.fixed.test("03-111-1111"));
assert.equal(false, jppr.fixed.test("045-1111-1111"));
assert.equal(false, jppr.fixed.test("1111-11-111"));
assert.equal(false, jppr.fixed.test("03-0111-1111")); // 030-* is invalid
})
})
describe("mobile phones", function() {
it("should match to valid fixed phone numbers", function() {
assert.equal(true, jppr.mobile.test("090-1111-1111"));
assert.equal(true, jppr.mobile.test("070-1111-1111"));
})
it("should not match to invalid fixed phone numbers", function() {
assert.equal(false, jppr.mobile.test("090-111-1111"));
assert.equal(false, jppr.mobile.test("070-11111-1111"));
assert.equal(false, jppr.mobile.test("03-1111-1111"));
})
})
describe("ip phones", function() {
it("should match to valid fixed phone numbers", function() {
assert.equal(true, jppr.ip.test("050-1111-1111"));
})
it("should not match to invalid fixed phone numbers", function() {
assert.equal(false, jppr.ip.test("050-111-1111"));
assert.equal(false, jppr.ip.test("010-11111-1111"));
})
})
describe("all", function() {
it("should match to valid fixed phone numbers", function() {
assert.equal(true, jppr.all.test("050-1111-1111"));
assert.equal(true, jppr.all.test("090-1111-1111"));
})
it("should not match to invalid fixed phone numbers", function() {
assert.equal(false, jppr.all.test("111-1111"));
assert.equal(false, jppr.all.test("11-1111-1111"));
assert.equal(false, jppr.all.test("050-111-1111"));
assert.equal(false, jppr.all.test("010-11111-1111"));
assert.equal(false, jppr.all.test("020-1111-1111"));
})
it("should ignore missing hyphens", function() {
assert.equal(true, jppr.all.test("039999-1111"));
assert.equal(true, jppr.all.test("0501111-1111"));
assert.equal(true, jppr.all.test("01267-1-1111"));
})
it("should not ignore extra hyphens", function() {
assert.equal(false, jppr.all.test("0-39999-1111"));
assert.equal(false, jppr.all.test("0501-111-1111"));
assert.equal(false, jppr.all.test("0126711-111"));
})
})
})