primitives.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. var test = require('tape');
  2. var Parser = require('../');
  3. var expected = [
  4. [ [], '' ],
  5. [ [], 'Hello' ],
  6. [ [], 'This"is' ],
  7. [ [], '\r\n\f\t\\/"' ],
  8. [ [], 'Λάμβδα' ],
  9. [ [], '\\' ],
  10. [ [], '/' ],
  11. [ [], '"' ],
  12. [ [ 0 ], 0 ],
  13. [ [ 1 ], 1 ],
  14. [ [ 2 ], -1 ],
  15. [ [], [ 0, 1, -1 ] ],
  16. [ [ 0 ], 1 ],
  17. [ [ 1 ], 1.1 ],
  18. [ [ 2 ], -1.1 ],
  19. [ [ 3 ], -1 ],
  20. [ [], [ 1, 1.1, -1.1, -1 ] ],
  21. [ [ 0 ], -1 ],
  22. [ [], [ -1 ] ],
  23. [ [ 0 ], -0.1 ],
  24. [ [], [ -0.1 ] ],
  25. [ [ 0 ], 6.02e+23 ],
  26. [ [], [ 6.02e+23 ] ],
  27. [ [ 0 ], '7161093205057351174' ],
  28. [ [], [ '7161093205057351174'] ]
  29. ];
  30. test('primitives', function (t) {
  31. t.plan(25);
  32. var p = new Parser();
  33. p.onValue = function (value) {
  34. var keys = this.stack
  35. .slice(1)
  36. .map(function (item) { return item.key })
  37. .concat(this.key !== undefined ? this.key : [])
  38. ;
  39. t.deepEqual(
  40. [ keys, value ],
  41. expected.shift()
  42. );
  43. };
  44. p.write('"""Hello""This\\"is""\\r\\n\\f\\t\\\\\\/\\""');
  45. p.write('"\\u039b\\u03ac\\u03bc\\u03b2\\u03b4\\u03b1"');
  46. p.write('"\\\\"');
  47. p.write('"\\/"');
  48. p.write('"\\""');
  49. p.write('[0,1,-1]');
  50. p.write('[1.0,1.1,-1.1,-1.0][-1][-0.1]');
  51. p.write('[6.02e23]');
  52. p.write('[7161093205057351174]');
  53. });