suite.js
2.86 KB
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
/* jshint globalstrict: true */
/* global require */
/* global module */
"use strict";
var calmcard = require("../calmcard");
module.exports = {
testNoWildcard: function(test) {
test.expect(2);
test.strictEqual(calmcard("foobar", "foobar"), true);
test.strictEqual(calmcard("foobar", "something"), false);
test.done();
},
testSingleWildcard: function(test) {
test.expect(2);
var pattern = "foo*bar";
var correct = "foo123bar";
var incorrect = "foobar";
test.strictEqual(calmcard(pattern, correct), true);
test.strictEqual(calmcard(pattern, incorrect), false);
test.done();
},
testEscapedWildcard: function(test) {
test.expect(2);
var pattern = "foo*bar\\*bla";
var correct = "foo123bar*bla";
var incorrect = "foo123bar123bla";
test.strictEqual(calmcard(pattern, correct), true);
test.strictEqual(calmcard(pattern, incorrect), false);
test.done();
},
testCollapseWildcards: function(test) {
test.expect(2);
var pattern = "foo****bar";
var correct = "foo123bar";
var incorrect = "foobar";
test.strictEqual(calmcard(pattern, correct), true);
test.strictEqual(calmcard(pattern, incorrect), false);
test.done();
},
testWildCardAtBeginnig: function(test) {
test.expect(2);
test.strictEqual(calmcard("*bar", "foobar"), true);
test.strictEqual(calmcard("*bar", "fooba"), false);
test.done();
},
testWildCardAtEnd: function(test) {
test.expect(2);
var pattern = "foo*";
var correct = "foobar";
var incorrect = "fobar";
test.strictEqual(calmcard("foo*", "foobar"), true);
test.strictEqual(calmcard("foo*", "fobar"), false);
test.done();
},
testEmptyPattern: function(test) {
test.expect(2);
test.strictEqual(calmcard("", ""), true);
test.strictEqual(calmcard("", "foobar"), false);
test.done();
},
testBackSlashes: function(test) {
test.expect(4);
test.strictEqual(calmcard("foo\\\\bar", "foo\\bar"), true);
test.strictEqual(calmcard("foo\\\\\\*bar", "foo\\*bar"), true);
test.strictEqual(calmcard("foo\\\\ \\*bar", "foo\\ *bar"), true);
test.strictEqual(calmcard("foo\\\\bar", "foobar"), false);
test.done();
},
testEmptyString: function(test) {
test.expect(2);
test.strictEqual(calmcard("", ""), true);
test.strictEqual(calmcard("*", ""), false);
test.done();
},
testComplexPattern: function(test) {
test.expect(2);
var pattern = "**foo**\\***bar***";
test.strictEqual(calmcard(pattern, "123foo456*789bar0"), true);
test.strictEqual(calmcard(pattern, "123foo45\\*789bar"), false);
test.done();
}
}