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.

str.js 1.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. 'use strict';
  2. var test = require('tape');
  3. var stringify = require('../');
  4. test('simple object', function (t) {
  5. t.plan(1);
  6. var obj = { c: 6, b: [4,5], a: 3, z: null };
  7. t.equal(stringify(obj), '{"a":3,"b":[4,5],"c":6,"z":null}');
  8. });
  9. test('object with undefined', function (t) {
  10. t.plan(1);
  11. var obj = { a: 3, z: undefined };
  12. t.equal(stringify(obj), '{"a":3}');
  13. });
  14. test('object with null', function (t) {
  15. t.plan(1);
  16. var obj = { a: 3, z: null };
  17. t.equal(stringify(obj), '{"a":3,"z":null}');
  18. });
  19. test('object with NaN and Infinity', function (t) {
  20. t.plan(1);
  21. var obj = { a: 3, b: NaN, c: Infinity };
  22. t.equal(stringify(obj), '{"a":3,"b":null,"c":null}');
  23. });
  24. test('array with undefined', function (t) {
  25. t.plan(1);
  26. var obj = [4, undefined, 6];
  27. t.equal(stringify(obj), '[4,null,6]');
  28. });
  29. test('object with empty string', function (t) {
  30. t.plan(1);
  31. var obj = { a: 3, z: '' };
  32. t.equal(stringify(obj), '{"a":3,"z":""}');
  33. });
  34. test('array with empty string', function (t) {
  35. t.plan(1);
  36. var obj = [4, '', 6];
  37. t.equal(stringify(obj), '[4,"",6]');
  38. });