Ohm-Management - Projektarbeit B-ME
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

space.js 1.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. var test = require('tape');
  2. var stringify = require('../');
  3. test('space parameter', function (t) {
  4. t.plan(1);
  5. var obj = { one: 1, two: 2 };
  6. t.equal(stringify(obj, {space: ' '}), ''
  7. + '{\n'
  8. + ' "one": 1,\n'
  9. + ' "two": 2\n'
  10. + '}'
  11. );
  12. });
  13. test('space parameter (with tabs)', function (t) {
  14. t.plan(1);
  15. var obj = { one: 1, two: 2 };
  16. t.equal(stringify(obj, {space: '\t'}), ''
  17. + '{\n'
  18. + '\t"one": 1,\n'
  19. + '\t"two": 2\n'
  20. + '}'
  21. );
  22. });
  23. test('space parameter (with a number)', function (t) {
  24. t.plan(1);
  25. var obj = { one: 1, two: 2 };
  26. t.equal(stringify(obj, {space: 3}), ''
  27. + '{\n'
  28. + ' "one": 1,\n'
  29. + ' "two": 2\n'
  30. + '}'
  31. );
  32. });
  33. test('space parameter (nested objects)', function (t) {
  34. t.plan(1);
  35. var obj = { one: 1, two: { b: 4, a: [2,3] } };
  36. t.equal(stringify(obj, {space: ' '}), ''
  37. + '{\n'
  38. + ' "one": 1,\n'
  39. + ' "two": {\n'
  40. + ' "a": [\n'
  41. + ' 2,\n'
  42. + ' 3\n'
  43. + ' ],\n'
  44. + ' "b": 4\n'
  45. + ' }\n'
  46. + '}'
  47. );
  48. });
  49. test('space parameter (same as native)', function (t) {
  50. t.plan(1);
  51. // for this test, properties need to be in alphabetical order
  52. var obj = { one: 1, two: { a: [2,3], b: 4 } };
  53. t.equal(stringify(obj, {space: ' '}), JSON.stringify(obj, null, ' '));
  54. });