-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
IPv4Adjuster.test.es
100 lines (94 loc) · 1.67 KB
/
IPv4Adjuster.test.es
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
import {CAUSE} from "libs/constants";
import IPv4Adjuster from "libs/IPv4Adjuster";
{
describe("required", testRequired);
describe("default", testDefault);
describe("empty", testEmpty);
describe("allowEmpty", testAllowEmpty);
describe("IPv4", testIPv4);
}
/**
* required value
*/
function testRequired()
{
const objIPv4Adjuster = new IPv4Adjuster();
it("should cause error(s)", () =>
{
expect(() =>
{
objIPv4Adjuster.adjust(undefined);
}).toThrow(CAUSE.REQUIRED);
});
}
/**
* default value
*/
function testDefault()
{
const objIPv4Adjuster = new IPv4Adjuster().default("1.1.1.1");
it("should be adjusted", () =>
{
expect(objIPv4Adjuster.adjust(undefined)).toEqual("1.1.1.1");
});
}
/**
* empty value
*/
function testEmpty()
{
const objIPv4Adjuster = new IPv4Adjuster();
it("should cause error(s)", () =>
{
expect(() =>
{
objIPv4Adjuster.adjust("");
}).toThrow(CAUSE.EMPTY);
});
}
/**
* empty value (allowd)
*/
function testAllowEmpty()
{
const objIPv4Adjuster = new IPv4Adjuster().allowEmpty("1.1.1.1");
it("should be OK", () =>
{
expect(objIPv4Adjuster.adjust("")).toEqual("1.1.1.1");
});
}
/**
* IPv4 string
*/
function testIPv4()
{
const objIPv4Adjuster = new IPv4Adjuster();
it("should be OK", () =>
{
const values = [
"0.0.0.0",
"192.168.0.1",
"255.255.255.255",
];
for(const value of values)
{
expect(objIPv4Adjuster.adjust(value)).toEqual(value);
}
});
it("should cause error(s)", () =>
{
const values = [
"0.0.0.",
"0.0.0.0.",
"255.255.255.256",
"999.255.255.255",
];
for(const value of values)
{
expect(() =>
{
objIPv4Adjuster.adjust(value);
}).toThrow(CAUSE.IPV4);
}
});
}