@schukai/monster 3.35.4 → 3.37.0
Sign up to get free protection for your applications and to get access to all the features.
- package/package.json +1 -1
- package/source/dom/util.mjs +46 -1
- package/source/text/bracketed-key-value-hash.mjs +245 -0
- package/source/text/generate-range-comparison-expression.mjs +93 -0
- package/source/text/util.mjs +1 -85
- package/source/types/version.mjs +1 -1
- package/test/cases/dom/util.mjs +60 -0
- package/test/cases/monster.mjs +1 -1
- package/test/cases/text/bracketed-key-value-hash.mjs +214 -0
- package/test/util/jsdom.mjs +1 -1
- package/test/web/test.html +2 -2
- package/test/web/tests.js +214 -50
@@ -0,0 +1,214 @@
|
|
1
|
+
// test.js
|
2
|
+
import {expect} from "chai";
|
3
|
+
import {
|
4
|
+
parseBracketedKeyValueHash,
|
5
|
+
createBracketedKeyValueHash
|
6
|
+
} from "../../../../application/source/text/bracketed-key-value-hash.mjs";
|
7
|
+
|
8
|
+
describe("parseBracketedKeyValueHash", () => {
|
9
|
+
it("should return an empty object for an empty string", () => {
|
10
|
+
const input = "";
|
11
|
+
const expectedResult = {};
|
12
|
+
expect(parseBracketedKeyValueHash(input)).to.deep.equal(expectedResult);
|
13
|
+
});
|
14
|
+
|
15
|
+
it("should parse a single selector with one key-value pair", () => {
|
16
|
+
const input = "#selector1(key1=value1)";
|
17
|
+
const expectedResult = {
|
18
|
+
selector1: {
|
19
|
+
key1: "value1",
|
20
|
+
},
|
21
|
+
};
|
22
|
+
expect(parseBracketedKeyValueHash(input)).to.deep.equal(expectedResult);
|
23
|
+
});
|
24
|
+
|
25
|
+
it("should parse multiple selectors with multiple key-value pairs", () => {
|
26
|
+
const input = "#selector1(key1=value1,key2=value2);selector2(key3=value3,key4=value4)";
|
27
|
+
const expectedResult = {
|
28
|
+
selector1: {
|
29
|
+
key1: "value1",
|
30
|
+
key2: "value2",
|
31
|
+
},
|
32
|
+
selector2: {
|
33
|
+
key3: "value3",
|
34
|
+
key4: "value4",
|
35
|
+
},
|
36
|
+
};
|
37
|
+
expect(parseBracketedKeyValueHash(input)).to.deep.equal(expectedResult);
|
38
|
+
});
|
39
|
+
|
40
|
+
it("should decode URL-encoded values", () => {
|
41
|
+
const input = "#selector1(key1=value1%2Cwith%20comma)";
|
42
|
+
const expectedResult = {
|
43
|
+
selector1: {
|
44
|
+
key1: "value1,with comma",
|
45
|
+
},
|
46
|
+
};
|
47
|
+
const result = parseBracketedKeyValueHash(input);
|
48
|
+
expect(result.selector1.key1).to.equal(expectedResult.selector1.key1);
|
49
|
+
});
|
50
|
+
|
51
|
+
it("should handle input without a leading hash", () => {
|
52
|
+
const input = "selector1(key1=value1)";
|
53
|
+
const expectedResult = {
|
54
|
+
selector1: {
|
55
|
+
key1: "value1",
|
56
|
+
},
|
57
|
+
};
|
58
|
+
expect(parseBracketedKeyValueHash(input)).to.deep.equal(expectedResult);
|
59
|
+
});
|
60
|
+
|
61
|
+
it("should return an empty object for invalid input", () => {
|
62
|
+
const input = "#selector1(key1=value1,key2";
|
63
|
+
const expectedResult = {};
|
64
|
+
expect(parseBracketedKeyValueHash(input)).to.deep.equal(expectedResult);
|
65
|
+
});
|
66
|
+
|
67
|
+
it('should return an empty object for an empty input string', () => {
|
68
|
+
const hashString = '';
|
69
|
+
const result = parseBracketedKeyValueHash(hashString);
|
70
|
+
expect(result).to.deep.equal({});
|
71
|
+
});
|
72
|
+
|
73
|
+
it('should return an empty object for an invalid input string', () => {
|
74
|
+
const hashString = '#invalid';
|
75
|
+
const result = parseBracketedKeyValueHash(hashString);
|
76
|
+
expect(result).to.deep.equal({});
|
77
|
+
});
|
78
|
+
|
79
|
+
it('should parse a simple input string with one selector and one key-value pair', () => {
|
80
|
+
const hashString = '#selector(key=value)';
|
81
|
+
const result = parseBracketedKeyValueHash(hashString);
|
82
|
+
expect(result).to.deep.equal({selector: {key: 'value'}});
|
83
|
+
});
|
84
|
+
|
85
|
+
it('should parse an input string with multiple selectors and key-value pairs', () => {
|
86
|
+
const hashString = '#selector1(key1=value1);selector2(key2=value2)';
|
87
|
+
const result = parseBracketedKeyValueHash(hashString);
|
88
|
+
expect(result).to.deep.equal({selector1: {key1: 'value1'}, selector2: {key2: 'value2'}});
|
89
|
+
});
|
90
|
+
|
91
|
+
it('should handle empty values', () => {
|
92
|
+
const hashString = '#selector(key1=,key2=)';
|
93
|
+
const result = parseBracketedKeyValueHash(hashString);
|
94
|
+
expect(result).to.deep.equal({selector: {key1: '', key2: ''}});
|
95
|
+
});
|
96
|
+
|
97
|
+
it('should handle percent-encoded values', () => {
|
98
|
+
const hashString = '#selector(key1=value%201,key2=value%2C2)';
|
99
|
+
const result = parseBracketedKeyValueHash(hashString);
|
100
|
+
expect(result).to.deep.equal({selector: {key1: 'value 1', key2: 'value,2'}});
|
101
|
+
});
|
102
|
+
|
103
|
+
it('should handle double-quoted values with commas', () => {
|
104
|
+
const hashString = '#selector(key1="value,1",key2="value,2")';
|
105
|
+
const result = parseBracketedKeyValueHash(hashString);
|
106
|
+
expect(result).to.deep.equal({selector: {key1: 'value,1', key2: 'value,2'}});
|
107
|
+
});
|
108
|
+
|
109
|
+
it('should ignore leading hash symbol (#)', () => {
|
110
|
+
const hashString = 'selector(key=value)';
|
111
|
+
const result = parseBracketedKeyValueHash(hashString);
|
112
|
+
expect(result).to.deep.equal({selector: {key: 'value'}});
|
113
|
+
});
|
114
|
+
|
115
|
+
it('should ignore leading and trailing white space', () => {
|
116
|
+
const hashString = ' #selector(key=value) ';
|
117
|
+
const result = parseBracketedKeyValueHash(hashString);
|
118
|
+
expect(result).to.deep.equal({selector: {key: 'value'}});
|
119
|
+
});
|
120
|
+
|
121
|
+
it('should return an empty object if the input string ends prematurely', () => {
|
122
|
+
const hashString = '#selector(key=value';
|
123
|
+
const result = parseBracketedKeyValueHash(hashString);
|
124
|
+
expect(result).to.deep.equal({});
|
125
|
+
});
|
126
|
+
|
127
|
+
it('should return an empty object if a selector is missing', () => {
|
128
|
+
const hashString = '#(key=value)';
|
129
|
+
const result = parseBracketedKeyValueHash(hashString);
|
130
|
+
expect(result).to.deep.equal({});
|
131
|
+
});
|
132
|
+
|
133
|
+
it('should return an empty object if a key is missing', () => {
|
134
|
+
const hashString = '#selector(=value)';
|
135
|
+
const result = parseBracketedKeyValueHash(hashString);
|
136
|
+
expect(result).to.deep.equal({});
|
137
|
+
});
|
138
|
+
|
139
|
+
it('should return an empty object ifa value is missing', () => {
|
140
|
+
const hashString = '#selector(key=)';
|
141
|
+
const result = parseBracketedKeyValueHash(hashString);
|
142
|
+
expect(result).to.deep.equal({
|
143
|
+
selector: {
|
144
|
+
key: '',
|
145
|
+
},
|
146
|
+
});
|
147
|
+
});
|
148
|
+
|
149
|
+
it('should return an empty object if there is no closing parenthesis for a selector', () => {
|
150
|
+
const hashString = '#selector(key=value;';
|
151
|
+
const result = parseBracketedKeyValueHash(hashString);
|
152
|
+
expect(result).to.deep.equal({});
|
153
|
+
});
|
154
|
+
|
155
|
+
it('should return an empty object if there is no semicolon after a selector', () => {
|
156
|
+
const hashString = '#selector(key=value)selector2(key2=value2)';
|
157
|
+
const result = parseBracketedKeyValueHash(hashString);
|
158
|
+
expect(result).to.deep.equal({
|
159
|
+
selector: {
|
160
|
+
key: 'value',
|
161
|
+
},
|
162
|
+
selector2: {
|
163
|
+
key2: 'value2',
|
164
|
+
},
|
165
|
+
});
|
166
|
+
});
|
167
|
+
|
168
|
+
describe('createBracketedKeyValueHash', () => {
|
169
|
+
it('should return an hash string for a simple object', () => {
|
170
|
+
const input = {
|
171
|
+
'.example': {
|
172
|
+
'color': 'red',
|
173
|
+
'font-size': '14px'
|
174
|
+
},
|
175
|
+
'.other': {
|
176
|
+
'background': 'blue'
|
177
|
+
}
|
178
|
+
};
|
179
|
+
|
180
|
+
const result = createBracketedKeyValueHash(input);
|
181
|
+
expect(result).to.deep.equal("#.example(color=red,font-size=14px);.other(background=blue)");
|
182
|
+
});
|
183
|
+
|
184
|
+
it('should return a url-encoded hash string for a simple object', () => {
|
185
|
+
const input = {
|
186
|
+
'.example': {
|
187
|
+
'color': 'r"ed',
|
188
|
+
'font-size': '14px'
|
189
|
+
},
|
190
|
+
'.other': {
|
191
|
+
'background': 'blue'
|
192
|
+
}
|
193
|
+
};
|
194
|
+
|
195
|
+
const result = createBracketedKeyValueHash(input, true);
|
196
|
+
expect(result).to.deep.equal("#.example(color=r%22ed,font-size=14px);.other(background=blue)");
|
197
|
+
});
|
198
|
+
|
199
|
+
it('should return an empty string for an empty object', () => {
|
200
|
+
const input = {};
|
201
|
+
const result = createBracketedKeyValueHash(input,false);
|
202
|
+
expect(result).to.deep.equal("");
|
203
|
+
});
|
204
|
+
|
205
|
+
it('should return an empty string for an empty object', () => {
|
206
|
+
const input = {};
|
207
|
+
const result = createBracketedKeyValueHash(input,false);
|
208
|
+
expect(result).to.deep.equal("");
|
209
|
+
});
|
210
|
+
|
211
|
+
});
|
212
|
+
|
213
|
+
|
214
|
+
});
|
package/test/util/jsdom.mjs
CHANGED
package/test/web/test.html
CHANGED
@@ -14,8 +14,8 @@
|
|
14
14
|
</head>
|
15
15
|
<body>
|
16
16
|
<div id="headline" style="display: flex;align-items: center;justify-content: center;flex-direction: column;">
|
17
|
-
<h1 style='margin-bottom: 0.1em;'>Monster 3.
|
18
|
-
<div id="lastupdate" style='font-size:0.7em'>last update
|
17
|
+
<h1 style='margin-bottom: 0.1em;'>Monster 3.35.4</h1>
|
18
|
+
<div id="lastupdate" style='font-size:0.7em'>last update Sa 1. Apr 17:29:43 CEST 2023</div>
|
19
19
|
</div>
|
20
20
|
<div id="mocks"></div>
|
21
21
|
<div id="mocha"></div>
|