-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
Copy pathdotAll.js
110 lines (96 loc) · 4.38 KB
/
dotAll.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
//-------------------------------------------------------------------------------------------------------
// Copyright (C) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
//-------------------------------------------------------------------------------------------------------
WScript.LoadScriptFile("..\\UnitTestFramework\\UnitTestFramework.js");
const dotAllMatch = [
"hel\nlo",
"hel\rlo",
"hel\u2028lo",
"hel\u2029lo"
];
const alwaysMatch = [
"hel\vlo",
"hel\flo",
"hel\u0085lo"
];
const neverMatch = [
"hel\n\nlo",
"hel\rllo",
"hel\u2028llo",
"hell\u2029lo",
"hel \vlo",
"hel \flo",
"hel \u0085lo"
];
const tests = [
{
name : "Match without dotAll",
body : function ()
{
const reg = /hel.lo/;
neverMatch.forEach(function (string) {
assert.isFalse(reg.test(string), "Shouldn't match");
});
dotAllMatch.forEach(function (string) {
assert.isFalse(reg.test(string), "Shouldn't match - strings that match with dotAll flag without the flag");
});
alwaysMatch.forEach(function (string) {
assert.isTrue(reg.test(string), "Should match - strings that match without dotAll flag");
});
}
},
{
name : "Match with dotAll",
body : function ()
{
const reg = /hel.lo/s;
neverMatch.forEach(function (string) {
assert.isFalse(reg.test(string), "Shouldn't match");
});
dotAllMatch.forEach(function (string) {
assert.isTrue(reg.test(string), "Should match - strings that match with dotAll flag");
});
alwaysMatch.forEach(function (string) {
assert.isTrue(reg.test(string), "Should match - strings that match without dotAll flag");
});
}
},
{
name : "Properties of dotAll property",
body : function ()
{
const withFlag = /stuff/s;
const withoutFlag = /stuff/;
assert.isTrue(withFlag.dotAll, "dotAll flag has correct value");
assert.isFalse(withoutFlag.dotAll, "dotAll flag has correct value");
assert.isTrue(delete withFlag.dotAll, "deleting dotAll property returns true");
assert.doesNotThrow(()=>{"use strict"; delete withFlag.dotAll;}, "deleting dotAll property does not throw in strict mode");
assert.isTrue(delete withoutFlag.dotAll, "deleting dotAll property returns true");
assert.doesNotThrow(()=>{"use strict"; delete withoutFlag.dotAll;}, "deleting dotAll property does not throw in strict mode");
assert.isFalse(withFlag.hasOwnProperty("dotAll"), "dotAll property is not a property of individual RegExp");
assert.isFalse(withoutFlag.hasOwnProperty("dotAll"), "dotAll property is not a property of individual RegExp");
}
},
{
name : "Properties of prototype dotAll property",
body : function ()
{
const dotAll = RegExp.prototype.dotAll;
assert.isTrue(RegExp.prototype.hasOwnProperty("dotAll"), "RegExp prototype has dotAll property");
const desc = Object.getOwnPropertyDescriptor(RegExp.prototype, "dotAll");
assert.isTrue(desc.configurable, "dotAll property of prototype is configurable");
assert.isFalse(desc.enumerable, "dotAll property of prototype is not enumerable");
assert.areEqual(dotAll, undefined, "dotAll property of prototype is undefined");
RegExp.prototype.dotAll = 5;
assert.areEqual(dotAll, undefined, "writing to dotAll property of prototype is a no-op");
assert.isTrue(delete RegExp.prototype.dotAll, "deleting dotAll property returns true");
assert.isFalse(RegExp.prototype.hasOwnProperty("dotAll"), "RegExp prototype has no dotAll property after deletion");
const withFlag = /stuff/s;
const withoutFlag = /stuff/;
assert.areEqual(withFlag.dotAll, undefined, "After deleting dotAll from prototype its undefined");
assert.areEqual(withoutFlag.dotAll, undefined, "After deleting dotAll from prototype its undefined");
}
}
];
testRunner.runTests(tests, { verbose: WScript.Arguments[0] != "summary" });