-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathunit.js
111 lines (100 loc) · 4.52 KB
/
unit.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
var MatchingUnit = function ( unit ){
unit.test("group: /*c/", function () {
var pattern = "*c";
unit.forbid('""', match(pattern, "") );
unit.assert('"c"', match(pattern, "c") );
unit.forbid('"caa"', match(pattern, "caa") );
unit.assert('"aac"', match(pattern, "aac") );
unit.forbid('"aca"', match(pattern, "aca") );
});
unit.test("group: /c*/", function () {
var pattern = "c*";
unit.forbid('""', match(pattern, "") );
unit.assert('"c"', match(pattern, "c") );
unit.assert('"caa"', match(pattern, "caa") );
unit.forbid('"aac"', match(pattern, "aac") );
unit.forbid('"aca"', match(pattern, "aca") );
});
unit.test("group: /*c*/", function () {
var pattern = "*c*";
unit.forbid('""', match(pattern, "") );
unit.assert('"c"', match(pattern, "c") );
unit.assert('"caa"', match(pattern, "caa") );
unit.forbid('"aaa"', match(pattern, "aaa") );
unit.assert('"aac"', match(pattern, "aac") );
unit.assert('"aca"', match(pattern, "aca") );
});
unit.test("group: /ab./", function () {
var pattern = "ab.";
unit.assert('"aba"', match(pattern, "aba") );
unit.assert('"abc"', match(pattern, "abc") );
unit.forbid('"abcc"', match(pattern, "abcc") );
unit.forbid('"abab"', match(pattern, "abab") );
unit.forbid('""', match(pattern, "") );
unit.forbid('"a"', match(pattern, "a") );
unit.forbid('"cb"', match(pattern, "cb") );
unit.forbid('"ab"', match(pattern, "ab") );
unit.forbid('"cabc"', match(pattern, "cabc") );
unit.forbid('"cabcc"', match(pattern, "cabcc") );
});
unit.test("group: /.ab/", function () {
unit.forbid('""', match(".ab", "") );
unit.forbid('"a"', match(".ab", "a") );
unit.forbid('"cb"', match(".ab", "cb") );
unit.forbid('"ab"', match(".ab", "ab") );
unit.assert('"cab"', match(".ab", "cab") );
unit.forbid('"cabcc"', match(".ab", "cabcc") );
unit.assert('"cab"', match(".ab", "cab") );
});
unit.test("group: /a*c/", function () {
var pattern = "a*c";
unit.assert('"abc"', match(pattern, "abc") );
unit.assert('"abbc"', match(pattern, "abbc") );
unit.forbid('"abbcb"', match(pattern, "abbcb") );
unit.forbid('"babbcb"', match(pattern, "babbcb") );
unit.forbid('"babb"', match(pattern, "babbcb") );
unit.forbid('"abbb"', match(pattern, "babbcb") );
unit.forbid('"bbbc"', match(pattern, "babbcb") );
});
unit.test("group: /.*c/", function () {
var pattern = ".*c";
unit.forbid('"c"', match(pattern, "c") );
unit.forbid('"cb"', match(pattern, "cb") );
unit.assert('"bc"', match(pattern, "bc") );
unit.assert('"bbc"', match(pattern, "bbc") );
unit.assert('"bbbc"', match(pattern, "bbbc") );
unit.forbid('"bbbcb"', match(pattern, "bbbcb") );
});
unit.test("group: /a.*c/", function () {
var pattern = "a.*c";
unit.assert('"abc"', match(pattern, "abc") );
unit.assert('"abdc"', match(pattern, "abdc") );
unit.assert('"abbdc"', match(pattern, "abbdc") );
});
unit.test("group: /a.c*f/", function () {
var pattern = "a.c*f";
unit.assert('"abcf"', match(pattern, "abcf") );
unit.assert('"abcdef"', match(pattern, "abcdef") );
unit.assert('"azcrwgfdjkgfdkjhdfjkfhf"', match(pattern, "azcrwgfdjkgfdkjhdfjkfhf") );
unit.forbid('"bbcdef"', match(pattern, "bbcdef") );
});
unit.test("group: /.a*.j*/", function () {
var pattern = ".a*.j*";
unit.assert('"cadeajmn"', match(pattern, "cadeajmn") );
});
unit.test("group: /*a.a/", function () {
var pattern = "*a.a";
unit.assert('"abcbccacaca"', match(pattern, "abcbccacaca") );
});
unit.test("group: /*a.a.*ca.ab*c.*/", function () {
var pattern = "*a.a.*ca.ab*c.*";
var test = "abcbccacacaacaaaaaacaadklfgjfdlkgjlkfdjgldfkgcjzxazaczcababslkgjssacacacaccaaccccacacacccnjfdiehrdgjrig"
unit.assert('"'+test+'"', match(pattern, test) );
});
unit.test("group: /*a*b*c*d*e*f*/", function () {
var pattern = "*a*b*c*d*e*f*";
var test = "abcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcde"
test += "abcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcde"
unit.forbid("slow w/o memoise...", match(pattern, test) );
});
};