aboutsummaryrefslogtreecommitdiff
path: root/__tests__/index.js
blob: 2df77173150c28e9ed06d9aaff33d77e3e341ded (plain)
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
'use strict';

import test from 'ava';
import parse from '../src';

const errorHappened = {prop: {}, eaten: ''};

test('line-input', t => {
  const toParse = '{key=value}';
  const r = parse(toParse);
  t.is(r.prop.key, 'value');
  t.is(r.eaten, toParse);
});

test('curvy-brace optional', t => {
  const toParse = 'key=value';
  const r = parse(toParse);
  t.is(r.prop.key, 'value');
  t.is(r.eaten, toParse);
});

test('simple', t => {
  const toParse = 'key';
  const r = parse(toParse);
  t.is(r.eaten, toParse);
  t.is('key' in r.prop, true);
  t.is(r.prop.key, undefined);
});

test('simple-class', t => {
  const toParse = '.class';
  const r = parse(toParse);
  t.is(r.eaten, '.class');
  t.deepEqual(r.prop.class, ['class']);
  t.is(r.prop.key, undefined);
});

test('simple-id', t => {
  const toParse = '{#id}';
  const r = parse(toParse);
  t.is(r.eaten, toParse);
  t.is(r.prop.id, 'id');
  t.is(r.prop.key, undefined);
});

test('id and class', t => {
  const toParse = '{#id .class}';
  const r = parse(toParse);
  t.is(r.eaten, toParse);
  t.is(r.prop.id, 'id');
  t.deepEqual(r.prop.class, ['class']);
});

test('classes', t => {
  const toParse = '{.class2 .class .class3}';
  const r = parse(toParse);
  const expected = ['class', 'class2', 'class3'];
  t.is(r.eaten, toParse);
  r.prop.class.forEach(elem => t.is(expected.indexOf(elem) > -1, true));
  expected.forEach(elem => t.is(r.prop.class.indexOf(elem) > -1, true));
});

test('prop with class', t => {
  const toParse = '{class=another .class}';
  const r = parse(toParse);
  t.is(r.eaten, toParse);
  t.deepEqual(r.prop.class, ['another', 'class']);
});

test('id and id key', t => {
  const toParse = '#id id=falseId';
  const r = parse(toParse);
  t.is(r.eaten, toParse);
});

test('class with key class', t => {
  const toParse = '{class=falseClass .class}';
  const r = parse(toParse);
  const expected = ['falseClass', 'class'];
  t.is(r.eaten, toParse);
  r.prop.class.forEach(elem => t.is(expected.indexOf(elem) > -1, true));
  expected.forEach(elem => t.is(r.prop.class.indexOf(elem) > -1, true));
});

test('classes with key class', t => {
  const toParse = '{class=falseClass .class .class2 class=falseClass2}';
  const r = parse(toParse);
  const expected = ['falseClass', 'class', 'class2'];
  t.is(r.eaten, toParse);
  r.prop.class.forEach(elem => t.is(expected.indexOf(elem) > -1, true));
  expected.forEach(elem => t.is(r.prop.class.indexOf(elem) > -1, true));
});

test('classes with key class2', t => {
  const toParse = 'class=falseClass .class .class2 class=falseClass2 .class3';
  const r = parse(toParse);
  const expected = ['falseClass', 'class', 'class2', 'class3'];
  t.is(r.eaten, toParse);
  r.prop.class.forEach(elem => t.is(expected.indexOf(elem) > -1, true));
  expected.forEach(elem => t.is(r.prop.class.indexOf(elem) > -1, true));
});

test('id and id key with class', t => {
  const toParse = '{id=id #falseId .class}';
  const r = parse(toParse);
  t.is(r.prop.id, 'id');
  t.deepEqual(r.prop.class, ['class']);
  t.is(r.eaten, toParse);
});

test('multiple id', t => {
  const toParse = '#id #badId #again';
  const r = parse(toParse);
  t.is(r.prop.id, 'id');
  t.is(r.eaten, toParse);
});

test('empty', t => {
  const toParse = '';
  const r = parse(toParse);
  t.deepEqual(r.prop, errorHappened.prop);
  t.is(r.eaten, toParse);
});

test('empty brace', t => {
  const toParse = '{}';
  const r = parse(toParse);
  t.deepEqual(r.prop, errorHappened.prop);
  t.is(r.eaten, toParse);
});

test('only spaces', t => {
  const toParse = '    ';
  const r = parse(toParse);
  t.deepEqual(r.prop, errorHappened.prop);
  t.is(r.eaten, toParse);
});

test('only one space', t => {
  const toParse = ' ';
  const r = parse(toParse);
  t.deepEqual(r.prop, errorHappened.prop);
  t.is(r.eaten, toParse);
});

test('only spaces with tab', t => {
  const toParse = ' 		 ';
  const r = parse(toParse);
  t.deepEqual(r.prop, errorHappened.prop);
  t.is(r.eaten, toParse);
});

test('braces with spaces', t => {
  const toParse = '{    }';
  const r = parse(toParse);
  t.deepEqual(r.prop, errorHappened.prop);
  t.is(r.eaten, toParse);
});

test('braces with spaces2', t => {
  const toParse = '{ 		 	 }';
  const r = parse(toParse);
  t.deepEqual(r.prop, errorHappened.prop);
  t.is(r.eaten, toParse);
});

test('braces in braces', t => {
  const toParse = '{{}}';
  const r = parse(toParse);
  t.deepEqual(r.prop, errorHappened.prop);
  t.deepEqual(r, errorHappened);
  t.is(r.eaten, ''); // It's an error
});

test('spaces then braces', t => {
  const toParse = '   {}';
  const r = parse(toParse);
  t.deepEqual(r.prop, errorHappened.prop);
  t.is(r.eaten, toParse);
});

test('braces then spaces', t => {
  const toParse = '{} 	 ';
  const r = parse(toParse);
  t.deepEqual(r.prop, errorHappened.prop);
  t.is(r.eaten, '{}');
});

test('newline in brace', t => {
  const toParse = '{#id \n.class}';
  const r = parse(toParse);
  t.deepEqual(r.prop, errorHappened.prop);
  t.is(r.eaten, ''); // It's an error
});

test('non latin value', t => {
  const toParse = '{#id .class key=🕶 neko="🐱"}';
  const r = parse(toParse);
  t.is(r.prop.id, 'id');
  t.is(r.prop.key, '🕶');
  t.is(r.prop.neko, '🐱');
  t.is(r.eaten, toParse);
});

test('non latin key and value', t => {
  const toParse = '{ねこ=🐈}';
  const r = parse(toParse);
  t.is(r.prop.ねこ, '🐈');
  t.is(r.eaten, toParse);
});

test('value in quote', t => {
  const toParse = 'key="value"';
  const r = parse(toParse);
  t.is(r.prop.key, 'value');
  t.is(r.eaten, toParse);
});

test('value in single quote', t => {
  const toParse = 'key=\'value\'';
  const r = parse(toParse);
  t.is(r.prop.key, 'value');
  t.is(r.eaten, toParse);
});

test('value in  with escaped quotes', t => {
  const toParse = 'key="\\"value\\""';
  const r = parse(toParse);
  t.is(r.prop.key, '"value"');
  t.is(r.eaten, toParse);
});

test('multiple value to same key', t => {
  const toParse = '{key=value key=value2 key=value3}';
  const r = parse(toParse);
  t.is(r.prop.key, 'value');
  t.is(r.eaten, toParse);
});

test('id key', t => {
  const toParse = '{id=id}';
  const r = parse(toParse);
  t.is(r.prop.id, 'id');
  t.is(r.eaten, toParse);
});

test('class key', t => {
  const toParse = 'class=class';
  const r = parse(toParse);
  t.deepEqual(r.prop.class, ['class']);
  t.is(r.eaten, toParse);
});

test('newline stop', t => {
  const toParse = 'hello=yeah  \nnotParsed=stop';
  const r = parse(toParse);
  t.is(r.prop.hello, 'yeah');
  t.not(r.prop.notParsed, 'stop');
  t.is(r.eaten, toParse.split('\n')[0]);
});

test('carriage return stop', t => {
  const toParse = 'hello="yeah"  \rnotParsed=stop';
  const r = parse(toParse);
  t.is(r.prop.hello, 'yeah');
  t.not(r.prop.notParsed, 'stop');
  t.is(r.eaten, toParse.split('\r')[0]);
});

test('class with spaces', t => {
  const toParse = '{.class="hello !"}';
  const r = parse(toParse);
  t.is(r.prop.class, undefined);
  t.is(r.eaten, '');
});

test('class with spaces2', t => {
  const toParse = '{.class=\'Hello ! }';
  const r = parse(toParse);
  t.is(r.prop.class, undefined);
  t.is(r.eaten, '');
});

test('class with spaces3', t => {
  const toParse = '{  .\'Hello !\'}';
  const r = parse(toParse);
  t.deepEqual(r.prop.class, ['\'Hello']);
  t.is('!\'' in r.prop, true);
  t.is(r.eaten, toParse);
});

test('opening brace in value', t => {
  const toParse = 'key=va{ue';
  const r = parse(toParse);
  t.is(r.prop.key, 'va');
  t.is(r.eaten, 'key=va');
});

test('normal case', t => {
  const toParse = 'unicorn="unicorn" type="text" editable .answer #first-answer';
  const r = parse(toParse);
  t.is(r.prop.unicorn, 'unicorn');
  t.is(r.prop.type, 'text');
  t.is(r.prop.editable, undefined);
  t.is('editable' in r.prop, true);
  t.is(r.prop.id, 'first-answer');
  t.deepEqual(r.prop.class, ['answer']);
  t.is(r.eaten, toParse);
});

test('normal case2', t => {
  const toParse = '{kind=textarea display #second-answer .nyan-cat}';
  const r = parse(toParse);
  t.is(r.prop.kind, 'textarea');
  t.is(r.prop.display, undefined);
  t.is(r.prop.id, 'second-answer');
  t.deepEqual(r.prop.class, ['nyan-cat']);
  t.is(r.eaten, toParse);
});

test('normal case not pretty-formated', t => {
  const toParse = '{ kind= textarea display= #second-answer  }';
  const r = parse(toParse);
  t.is(r.prop.kind, '');
  t.is(r.prop.textarea, undefined);
  t.is(r.prop.display, '');
  t.is(r.prop.id, 'second-answer');
  t.is(r.eaten, toParse);
});

test('normal case not pretty-formated2', t => {
  const toParse = '  kind=? textarea display=none #second-answer ';
  const r = parse(toParse);
  t.is(r.prop.kind, '?');
  t.is(r.prop.textarea, undefined);
  t.is(r.prop.display, 'none');
  t.is(r.prop.id, 'second-answer');
  t.is(r.eaten, toParse);
});

test('double class', t => {
  const toParse = '{.class .class}';
  const r = parse(toParse);
  t.deepEqual(r.prop.class, ['class']);
  t.is(r.eaten, toParse);
});

test('class look\'s like a key', t => {
  const toParse = '{.class=key}';
  const r = parse(toParse);
  t.is(r.prop.class, undefined);
  t.is(r.eaten, '');
});

test('id look\'s like a key', t => {
  const toParse = '{#class=key}';
  const r = parse(toParse);
  t.is(r.prop.id, undefined);
  t.is(r.eaten, '');
});

test('key\'s value looks like a key', t => {
  const toParse = '{key=key=value}';
  const r = parse(toParse);
  t.is(r.prop.key, undefined);
  t.is(r.eaten, '');
});

test('key\'s value looks like a key2', t => {
  const toParse = 'key=key=value';
  const r = parse(toParse);
  t.is(r.prop.key, 'key');
  t.is(r.eaten, 'key=key');
});

test('long too parse', t => {
  const toParse = '#Lorem-ipsum dolor sit ame=consectetur adipiscing elit .Sed ac placerat ex .Donec molestie .consequat dux=sodales laoreet justo vulputate .bibendum .Nunc sed ante .loborti qsd=venenatis velit ir=interdum lacus .Proin sed dapibus magna .Suspendisse .id faucibus ligula .Praesent fringilla auctor metus eget egestas .Cras at convallis justo .Duis mollis purus eras=ut maximus felis dignissim vel .Nulla fringille=ex id pellentesque .feugia sid=purus elit egestas odi=sagittis fringilla purus nulla in ligula .Etiam vitae .varius turpis .Sed scelerisque .non augue .vel dignissim .Class aptent taciti sociosqu ad litora torquent per conubia nostro=per inceptos himenaeos';
  const r = parse(toParse);
  t.is(r.eaten, toParse);
  t.snapshot(r);
});

test('very long too parse', t => {
  const toParse = 'In lobortis sapien in libero dapibu=eget aliquam sapien congue ..Fusce .et eros non est placerat dignissim .In et risus sed risus posuere .dignissim sed vel risus .Curabitur sodales dui eu ex ornari=sit amet cursus tellus lobortis .Mauris sit amet aliquam purus=in pulvinar velit .Proin sit amet dignissim libero .Praesent imperdiet eros ut libero ultriciet=eget congue .ante .faucibus .Donec imperdiet mi ut neque .finibus pharetra .Ut vel semper leo .Sed pulvina=lorem vitae .convallis viverro=purus nulla dignissim dul=in placerat lectus enim fermentum odio .Ut et nisi id eros fermentum tristique ..Pellentesque .venenatis faucibus magna hendrerit fermentum .Mauris euismod finibus lorem ac pellentesque ..Suspendisse .facilisis ex a lorem molestir=ac rhoncus massa porta .Fusce .suscipit sapien dus=vitae .imperdiet velit tempus nec .Aenean ut est ac ligula molestie .bibendum  .Quisque .vitae .placerat elit .Phasellus vel bibendum tellu=at ultricies felis .Mauris viverra urna in nibh volutpat congue ..Maecenas rhoncus commodo nisi id tristique ..Praesent id nisl at lacus elementum tempor .Quisque .eleifend nunc dolor .Nulla non sodales lacus=ut mattis nisi .Nullam nibh risut=auctor ut arcu eleifenlid=iaculis vulputate .dolor .Phasellus leo nunblu=malesuada vitae .orci i=pellentesque .rutrum libero .Etiam quam velib=accumsan sit amet gravida velo=finibus et ligula  .Vivamus justo lacunaire=placerat in felis dapibu=vestibulum fermentum ex .Aenean ultricies felis luctus=condimentum lacus interdu97=placerat lacus .In libero nis=aliquet molestie .lectus sit ame=pulvinar mollis purus .Sed fringilla dolor non eros fermentum vulputate ..Donec a porta tellus .Mauris interdum egestas cursus .Quisque .luctus risus eget massa euismod euismod .Mauris in tellus ut neque .vehicula posuere ..Integer vitae .vehicula mauris .Fusce .non libero condimentus=efficitur massa quid=fringilla tellus .Nunc a arcu lacinia sem venenatis finibus .In egestas ex niso=nec tempus metus ornare .vel  .Class aptent taciti sociosqu ad litora torquent per conubia nostre=per inceptos himenaeos .Fusce .sit amet vehicula mi .Sed nec rutrum tortor .Donec pretium mi nibu=ut sodales nibh volutpat sed .Vivamus finibus sollicitudin finibus .Quisque .euismo qsd=dolor porta feugiat ultricie dis=dui nunc pretium elikopter=vel suscipit dui nibh sit amet tortor .In suscipit condimentum nibus=quis condimentum lacus consequat in .Phasellus quis purus et ligula elementum fringilla id ut mi .Nullam ornare .magna ut arcu accumsa=non commodo nisi convallis .Sed eget consectetur orci .Sed vestibulum elit non erat sollicitudi=non maximus ipsum lobortis .Cras sed nisl iaculis massa eleifend accumsan .Suspendisse .nec ipsum elit .Quisque .at turpis erat .In lobortis sapien in libero dapibu=eget aliquam sapien congue ..Fusce .et eros non est placerat dignissim .In et risus sed risus posuere .dignissim sed vel risus .Curabitur sodales dui eu ex ornar=sit amet cursus tellus lobortis .Mauris sit amet aliquam purus=in pulvinar velit .Proin sit amet dignissim libero .Praesent imperdiet eros ut libero ultricien=eget congue .ante .faucibus .Donec imperdiet mi ut neque .finibus pharetra .Ut vel semper leo .Sed pulvina=lorem vitae .convallis viverr=purus nulla dignissim dus=in placerat lectus enim fermentum odio .Ut et nisi id eros fermentum tristique ..Pellentesque .venenatis faucibus magna hendrerit fermentum .Mauris euismod finibus #lorem ac pellentesque ..Suspendisse .facilisis ex a lorem molesti=ac rhoncus massa porta .Fusce .suscipit sapien du=vitae .imperdiet velit tempus nec .Aenean ut est ac ligula molestie .bibendum  .Quisque .vitae .placerat elit .Phasellus vel bibendum tellus=at ultricies felis .Mauris viverra urna in nibh volutpat congue ..Maecenas rhoncus commodo nisi id tristique ..Praesent id nisl at lacus elementum tempor .Quisque .eleifend nunc dolor .Nulla non sodales lacu=ut mattis nisi .Nullam nibh risut=auctor ut arcu eleifenlid=iaculis vulputate .dolor .Phasellus leo nunblum=malesuada vitae .orci i=pellentesque .rutrum libero .Etiam quam veli=accumsan sit amet gravida ve=finibus et ligula  .Vivamus justo lacu=placerat in felis dapibuqsdf=vestibulum fermentum ex .Aenean ultricies felis luctuqsdf=condimentum lacus interduaez=placerat lacus .In libero nisdf=aliquet molestie .lectus sit ameqsdf=pulvinar mollis purus .Sed fringilla dolor non eros fermentum vulputate ..Donec a porta tellus .Mauris interdum egestas cursus .Quisque .luctus risus eget massa euismod euismod .Mauris in tellus ut neque .vehicula posuere ..Integer vitae .vehicula mauris .Fusce .non libero condimentuazer=efficitur massa qui qsfd=fringilla tellus .Nunc a arcu lacinia sem venenatis finibus .In egestas ex niskip=nec tempus metus ornare .vel  .Class aptent taciti sociosqu ad litora torquent per conubia nostro=per inceptos himenaeos .Fusce .sit amet vehicula mi .Sed nec rutrum tortor .Donec pretium mi nibus=ut sodales nibh volutpat sed .Vivamus finibus sollicitudin finibus .Quisque euismop=dolor porta feugiat ultricieser=dui nunc pretium elidi=vel suscipit dui nibh sit amet tortor .In suscipit condimentum nibus=quis condimentum lacus consequat in .Phasellus quis purus et ligula elementum fringilla id ut mi .Nullam ornare .magna ut arcu accumsame=non commodo nisi convallis .Sed eget consectetur orci .Sed vestibulum elit non erat sollicituditis=non maximus ipsum lobortis .Cras sed nisl iaculis massa eleifend accumsan .Suspendisse .nec ipsum elit .Quisque .at turpis erat';
  const r = parse(toParse);
  t.is(r.eaten, toParse);
  t.snapshot(r);
});

test('id with a hash', t => {
  const toParse = '##id';
  const r = parse(toParse);

  t.is(r.prop.id, '#id');
  t.is(r.eaten, toParse);
});

test('class with a dot', t => {
  const toParse = '..class';
  const r = parse(toParse);
  t.deepEqual(r.prop.class, ['.class']);
  t.is(r.eaten, toParse);
});

test('value start with a equal', t => {
  const toParse = '{key==value}';
  const r = parse(toParse);
  /* Maybe this
  t.is(r.prop.key, '');
  t.is(r.eaten, toParse);
  */
  t.is(r.prop.key, undefined);
  t.is(r.eaten, '');
});

test('single quote in key', t => {
  const toParse = '{ke\'y=value}';
  const r = parse(toParse);
  t.is(r.prop['ke\'y'], 'value');
  t.is(r.eaten, toParse);
});

test('quoted key', t => {
  const toParse = '{"key"=value}';
  const r = parse(toParse);
  t.is(r.prop['"key"'], 'value');
  t.is(r.eaten, toParse);
});
test('dashed key', t => {
  const toParse = '{eg-key=value}';
  const r = parse(toParse);
  t.is(r.prop['eg-key'], 'value');
  t.is(r.eaten, toParse);
});
test('quoted class', t => {
  const toParse = '{."key"}';
  const r = parse(toParse);
  t.deepEqual(r.prop.class, ['"key"']);
  t.is(r.eaten, toParse);
});

test('quoted id', t => {
  const toParse = '{#"id"}';
  const r = parse(toParse);
  t.is(r.prop.id, '"id"');
  t.is(r.eaten, toParse);
});

test('key that start by a quote', t => {
  const toParse = '{\'key=value}';
  const r = parse(toParse);
  t.is(r.prop['\'key'], 'value');
  t.is(r.eaten, toParse);
});

test('single-quoted key', t => {
  const toParse = '"key"=value';
  const r = parse(toParse);
  t.is(r.prop['"key"'], 'value');
  t.is(r.eaten, toParse);
});

test('space in quoted value', t => {
  const toParse = 'key="value and value"';
  const r = parse(toParse);
  t.is(r.prop.key, 'value and value');
  t.is(r.eaten, toParse);
});

test('return in quoted value', t => {
  const toParse = 'key="value and\nvalue"';
  const r = parse(toParse);
  t.is(r.prop.key, undefined);
  t.is(r.eaten, '');
});

test('line feed in quoted value (brace version)', t => {
  const toParse = 'key="value and\nvalue"';
  const r = parse(toParse);
  t.is(r.prop.key, undefined);
  t.is(r.eaten, '');
});

test('cariage-return in quoted value (brace version)', t => {
  const toParse = 'key="value and\rvalue"';
  const r = parse(toParse);
  t.is(r.prop.key, undefined);
  t.is(r.eaten, '');
});

test('brace in quoted value', t => {
  const toParse = 'onclic="function() { return \\"Yeah !\\"; }"';
  const r = parse(toParse);
  t.is(r.prop.onclic, 'function() { return "Yeah !"; }');
  t.is(r.eaten, toParse);
});

test('braces as key name', t => {
  const toParse = '{ {}=qsf   }';
  const r = parse(toParse);
  t.is(r.prop['{}'], undefined);
  t.is(r.eaten, '');
});

test('braces as class name', t => {
  const toParse = '{ .{} }';
  const r = parse(toParse);
  t.is(r.prop.class, undefined);
  t.is(r.eaten, '');
});

test('alone dot', t => {
  const toParse = '{ . }';
  const r = parse(toParse);
  t.deepEqual(r.prop, errorHappened.prop);
  t.is(r.eaten, ''); // It's an error
});

test('start by a equal', t => {
  const toParse = '{ =qsdf }';
  const r = parse(toParse);
  t.deepEqual(r.prop, errorHappened.prop);
  t.is(r.eaten, ''); // It's an error
});

test('alone hash', t => {
  const toParse = '#';
  const r = parse(toParse);
  t.deepEqual(r.prop, errorHappened.prop);
  t.is(r.eaten, ''); // It's an error
});

test('alone brace', t => {
  const toParse = '{';
  const r = parse(toParse);
  t.deepEqual(r.prop, errorHappened.prop);
  t.is(r.eaten, ''); // It's an error
});

test('defaultValue true', t => {
  const toParse = 'visible';
  const r = parse(toParse, 0, {defaultValue: 'true'});
  t.is(r.prop.visible, 'true');
  t.is(r.eaten, 'visible');
});

test('defaultValue name', t => {
  const toParse = 'visible';
  const r = parse(toParse, 0, {defaultValue: x => x});
  t.is(r.prop.visible, 'visible');
  t.is(r.eaten, 'visible');
});

test('braces in attr', t => {
  const toParse = '{ data-json=\'{"a": 1, "b": 2}\' }';
  const r = parse(toParse);
  t.is(r.prop['data-json'], '{"a": 1, "b": 2}');
  t.is(r.eaten, toParse);
});

test('nested braces in attr', t => {
  const toParse = '{ data-json=\'{"a": 1, "b": { "c": 4 }}\' }';
  const r = parse(toParse);
  t.is(r.prop['data-json'], '{"a": 1, "b": { "c": 4 }}');
  t.is(r.eaten, toParse);
});