Skip to content

Commit 9b57ead

Browse files
committed
added uncommon keyname test
1 parent 46b2818 commit 9b57ead

File tree

1 file changed

+138
-40
lines changed

1 file changed

+138
-40
lines changed

test/test.js

Lines changed: 138 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,26 @@ sampleData = {
127127
],
128128
numbers : [ 0, 1, -100, -7.5, 500, 1.823 ],
129129
primitives : [false,true]
130+
},
131+
uncommonKeys : {
132+
true : true,
133+
false : false,
134+
undefined : 'undefined',
135+
null : 'null',
136+
'' : 0,
137+
'compound word' : ['*'],
138+
'~!@#$%' : 'non-alphanumeric',
139+
$ : 'dollar',
140+
_ : 'underscore',
141+
'{}' : 'curly brackets',
142+
'[]' : 'square brackets',
143+
0 : 'number',
144+
'0' : 'number-like text',
145+
A423423 : 'letter-number',
146+
'0A' : 'number-letter',
147+
'A 4' : 'letter-space-number',
148+
'0 A' : 'number-space-letter',
149+
'0 A,&' : 'number-space-letter-nonAlphanumeric'
130150
}
131151
};
132152

@@ -154,51 +174,129 @@ testSyntaxLogic('JS','Common Sample',sampleData.common,{
154174
lines : 20,
155175
noSpaces : "{strings:['xyz','This is a test','+_)(*&^%$#@!~/|}{:?/.,;][=-`'],numbers:[0,1,-100,-7.5,500,1.823],primitives:[false,true]}",
156176
tokens : [
157-
{ depth : 1, string: "{", type: "symbol", value: "{" },
158-
{ depth : 1, string: "strings", type: "key", value: "strings" },
159-
{ depth : 1, string: ":", type: "symbol", value: ":" },
160-
{ depth : 2, string: "[", type: "symbol", value: "[" },
161-
{ depth : 2, string: "'xyz'", type: "string", value: "'xyz'" },
162-
{ depth : 2, string: ",", type: "symbol", value: "," },
163-
{ depth : 2, string: "'This is a test'", type: "string", value: "'This is a test'" },
164-
{ depth : 2, string: ",", type: "symbol", value: "," },
165-
{ depth : 2, string: "'+_)(*&^%$#@!~/|}{:?/.,;][=-`'", type: "string", value: "'+_)(*&^%$#@!~/|}{:?/.,;][=-`'" },
166-
{ depth : 1, string: "]", type: "symbol", value: "]" },
167-
{ depth : 1, string: ",", type: "symbol", value: "," },
168-
{ depth : 1, string: "numbers", type: "key", value: "numbers" },
169-
{ depth : 1, string: ":", type: "symbol", value: ":" },
170-
{ depth : 2, string: "[", type: "symbol", value: "[" },
171-
{ depth : 2, string: "0", type: "number", value: 0 },
172-
{ depth : 2, string: ",", type: "symbol", value: "," },
173-
{ depth : 2, string: "1", type: "number", value: 1 },
174-
{ depth : 2, string: ",", type: "symbol", value: "," },
175-
{ depth : 2, string: "-100", type: "number", value: -100 },
176-
{ depth : 2, string: ",", type: "symbol", value: "," },
177-
{ depth : 2, string: "-7.5", type: "number", value: -7.5 },
178-
{ depth : 2, string: ",", type: "symbol", value: "," },
179-
{ depth : 2, string: "500", type: "number", value: 500 },
180-
{ depth : 2, string: ",", type: "symbol", value: "," },
181-
{ depth : 2, string: "1.823", type: "number", value: 1.823 },
182-
{ depth : 1, string: "]", type: "symbol", value: "]" },
183-
{ depth : 1, string: ",", type: "symbol", value: "," },
184-
{ depth : 1, string: "primitives", type: "key", value: "primitives" },
185-
{ depth : 1, string: ":", type: "symbol", value: ":" },
186-
{ depth : 2, string: "[", type: "symbol", value: "[" },
187-
{ depth : 2, string: "false", type: "primitive", value: false },
188-
{ depth : 2, string: ",", type: "symbol", value: "," },
189-
{ depth : 2, string: "true", type: "primitive", value: true },
190-
{ depth : 1, string: "]", type: "symbol", value: "]" },
191-
{ depth : 0, string: "}", type: "symbol", value: "}" }
177+
{ depth: 1, string: '{', type: 'symbol', value: '{' },
178+
{ depth: 1, string: 'strings', type: 'key', value: 'strings' },
179+
{ depth: 1, string: ':', type: 'symbol', value: ':' },
180+
{ depth: 2, string: '[', type: 'symbol', value: '[' },
181+
{ depth: 2, string: "'xyz'", type: 'string', value: "'xyz'" },
182+
{ depth: 2, string: ',', type: 'symbol', value: ',' },
183+
{ depth: 2, string: "'This is a test'", type: 'string', value: "'This is a test'" },
184+
{ depth: 2, string: ',', type: 'symbol', value: ',' },
185+
{ depth: 2, string: "'+_)(*&^%$#@!~/|}{:?/.,;][=-`'", type: 'string', value: "'+_)(*&^%$#@!~/|}{:?/.,;][=-`'" },
186+
{ depth: 1, string: ']', type: 'symbol', value: ']' },
187+
{ depth: 1, string: ',', type: 'symbol', value: ',' },
188+
{ depth: 1, string: 'numbers', type: 'key', value: 'numbers' },
189+
{ depth: 1, string: ':', type: 'symbol', value: ':' },
190+
{ depth: 2, string: '[', type: 'symbol', value: '[' },
191+
{ depth: 2, string: '0', type: 'number', value: 0 },
192+
{ depth: 2, string: ',', type: 'symbol', value: ',' },
193+
{ depth: 2, string: '1', type: 'number', value: 1 },
194+
{ depth: 2, string: ',', type: 'symbol', value: ',' },
195+
{ depth: 2, string: '-100', type: 'number', value: -100 },
196+
{ depth: 2, string: ',', type: 'symbol', value: ',' },
197+
{ depth: 2, string: '-7.5', type: 'number', value: -7.5 },
198+
{ depth: 2, string: ',', type: 'symbol', value: ',' },
199+
{ depth: 2, string: '500', type: 'number', value: 500 },
200+
{ depth: 2, string: ',', type: 'symbol', value: ',' },
201+
{ depth: 2, string: '1.823', type: 'number', value: 1.823 },
202+
{ depth: 1, string: ']', type: 'symbol', value: ']' },
203+
{ depth: 1, string: ',', type: 'symbol', value: ',' },
204+
{ depth: 1, string: 'primitives', type: 'key', value: 'primitives' },
205+
{ depth: 1, string: ':', type: 'symbol', value: ':' },
206+
{ depth: 2, string: '[', type: 'symbol', value: '[' },
207+
{ depth: 2, string: 'false', type: 'primitive', value: false },
208+
{ depth: 2, string: ',', type: 'symbol', value: ',' },
209+
{ depth: 2, string: 'true', type: 'primitive', value: true },
210+
{ depth: 1, string: ']', type: 'symbol', value: ']' },
211+
{ depth: 0, string: '}', type: 'symbol', value: '}' }
212+
]
213+
});
214+
215+
testSyntaxLogic('JS','Uncommon Key Names',sampleData.uncommonKeys,{
216+
jsObject : { ...sampleData.uncommonKeys },
217+
json : "{\"0\":\"number-like text\",\"true\":true,\"false\":false,\"undefined\":\"undefined\",\"null\":\"null\",\"\":0,\"compound word\":[\"*\"],\"~!@#$%\":\"non-alphanumeric\",\"$\":\"dollar\",\"_\":\"underscore\",\"{}\":\"curly brackets\",\"[]\":\"square brackets\",\"A423423\":\"letter-number\",\"0A\":\"number-letter\",\"A 4\":\"letter-space-number\",\"0 A\":\"number-space-letter\",\"0 A,&\":\"number-space-letter-nonAlphanumeric\"}",
218+
lines : 22,
219+
noSpaces : "{0:'number-like text',true:true,false:false,undefined:'undefined',null:'null','':0,'compound word':['*'],'~!@#$%':'non-alphanumeric','$':'dollar',_:'underscore','{}':'curly brackets','[]':'square brackets',A423423:'letter-number','0A':'number-letter','A 4':'letter-space-number','0 A':'number-space-letter','0 A,&':'number-space-letter-nonAlphanumeric'}",
220+
tokens : [
221+
{ depth: 1, string: '{', type: 'symbol', value: '{' },
222+
{ depth: 1, string: '0', type: 'key', value: '0' },
223+
{ depth: 1, string: ':', type: 'symbol', value: ':' },
224+
{ depth: 1, string: "'number-like text'", type: 'string', value: "'number-like text'" },
225+
{ depth: 1, string: ',', type: 'symbol', value: ',' },
226+
{ depth: 1, string: 'true', type: 'key', value: 'true' },
227+
{ depth: 1, string: ':', type: 'symbol', value: ':' },
228+
{ depth: 1, string: 'true', type: 'primitive', value: true },
229+
{ depth: 1, string: ',', type: 'symbol', value: ',' },
230+
{ depth: 1, string: 'false', type: 'key', value: 'false' },
231+
{ depth: 1, string: ':', type: 'symbol', value: ':' },
232+
{ depth: 1, string: 'false', type: 'primitive', value: false },
233+
{ depth: 1, string: ',', type: 'symbol', value: ',' },
234+
{ depth: 1, string: 'undefined', type: 'key', value: 'undefined' },
235+
{ depth: 1, string: ':', type: 'symbol', value: ':' },
236+
{ depth: 1, string: "'undefined'", type: 'string', value: "'undefined'" },
237+
{ depth: 1, string: ',', type: 'symbol', value: ',' },
238+
{ depth: 1, string: 'null', type: 'key', value: 'null' },
239+
{ depth: 1, string: ':', type: 'symbol', value: ':' },
240+
{ depth: 1, string: "'null'", type: 'string', value: "'null'" },
241+
{ depth: 1, string: ',', type: 'symbol', value: ',' },
242+
{ depth: 1, string: "''", type: 'key', value: "''" },
243+
{ depth: 1, string: ':', type: 'symbol', value: ':' },
244+
{ depth: 1, string: '0', type: 'number', value: 0 },
245+
{ depth: 1, string: ',', type: 'symbol', value: ',' },
246+
{ depth: 1, string: "'compound word'", type: 'key', value: "'compound word'" },
247+
{ depth: 1, string: ':', type: 'symbol', value: ':' },
248+
{ depth: 2, string: '[', type: 'symbol', value: '[' },
249+
{ depth: 2, string: "'*'", type: 'string', value: "'*'" },
250+
{ depth: 1, string: ']', type: 'symbol', value: ']' },
251+
{ depth: 1, string: ',', type: 'symbol', value: ',' },
252+
{ depth: 1, string: "'~!@#$%'", type: 'key', value: "'~!@#$%'" },
253+
{ depth: 1, string: ':', type: 'symbol', value: ':' },
254+
{ depth: 1, string: "'non-alphanumeric'", type: 'string', value: "'non-alphanumeric'" },
255+
{ depth: 1, string: ',', type: 'symbol', value: ',' },
256+
{ depth: 1, string: "'$'", type: 'key', value: "'$'" },
257+
{ depth: 1, string: ':', type: 'symbol', value: ':' },
258+
{ depth: 1, string: "'dollar'", type: 'string', value: "'dollar'" },
259+
{ depth: 1, string: ',', type: 'symbol', value: ',' },
260+
{ depth: 1, string: '_', type: 'key', value: '_' },
261+
{ depth: 1, string: ':', type: 'symbol', value: ':' },
262+
{ depth: 1, string: "'underscore'", type: 'string', value: "'underscore'" },
263+
{ depth: 1, string: ',', type: 'symbol', value: ',' },
264+
{ depth: 1, string: "'{}'", type: 'key', value: "'{}'" },
265+
{ depth: 1, string: ':', type: 'symbol', value: ':' },
266+
{ depth: 1, string: "'curly brackets'", type: 'string', value: "'curly brackets'" },
267+
{ depth: 1, string: ',', type: 'symbol', value: ',' },
268+
{ depth: 1, string: "'[]'", type: 'key', value: "'[]'" },
269+
{ depth: 1, string: ':', type: 'symbol', value: ':' },
270+
{ depth: 1, string: "'square brackets'", type: 'string', value: "'square brackets'" },
271+
{ depth: 1, string: ',', type: 'symbol', value: ',' },
272+
{ depth: 1, string: 'A423423', type: 'key', value: 'A423423' },
273+
{ depth: 1, string: ':', type: 'symbol', value: ':' },
274+
{ depth: 1, string: "'letter-number'", type: 'string', value: "'letter-number'" },
275+
{ depth: 1, string: ',', type: 'symbol', value: ',' },
276+
{ depth: 1, string: "'0A'", type: 'key', value: "'0A'" },
277+
{ depth: 1, string: ':', type: 'symbol', value: ':' },
278+
{ depth: 1, string: "'number-letter'", type: 'string', value: "'number-letter'" },
279+
{ depth: 1, string: ',', type: 'symbol', value: ',' },
280+
{ depth: 1, string: "'A 4'", type: 'key', value: "'A 4'" },
281+
{ depth: 1, string: ':', type: 'symbol', value: ':' },
282+
{ depth: 1, string: "'letter-space-number'", type: 'string', value: "'letter-space-number'" },
283+
{ depth: 1, string: ',', type: 'symbol', value: ',' },
284+
{ depth: 1, string: "'0 A'", type: 'key', value: "'0 A'" },
285+
{ depth: 1, string: ':', type: 'symbol', value: ':' },
286+
{ depth: 1, string: "'number-space-letter'", type: 'string', value: "'number-space-letter'" },
287+
{ depth: 1, string: ',', type: 'symbol', value: ',' },
288+
{ depth: 1, string: "'0 A,&'", type: 'key', value: "'0 A,&'" },
289+
{ depth: 1, string: ':', type: 'symbol', value: ':' },
290+
{ depth: 1, string: "'number-space-letter-nonAlphanumeric'", type: 'string', value: "'number-space-letter-nonAlphanumeric'"},
291+
{ depth: 0, string: '}', type: 'symbol', value: '}' }
192292
]
193293
});
194294

195295
/**
196296
* TODO - Add missing Syntax Logic validations:
197-
* 1. Primitive words as key names
198-
* 2. Special characters in keys. I.e. @#$% L32423 ""
199-
* 3. Quotes characters and nested. I.e. "" '' ``
200-
* 4. Escape character. I.e \
201-
* 5. Html Tags and stand alone reserved words I.e. <pre> <div> <> >< <br/>
297+
* 1. Quotes in key and string notations and nested. I.e. "" '' ``
298+
* 2. Escape character. I.e \
299+
* 3. Html Tags and stand alone reserved words I.e. <pre> <div> <> >< <br/>
202300
*
203301
* 6. Provide invalid information, validate warnings
204302
**/

0 commit comments

Comments
 (0)