Repositorio del curso CCOM4030 el semestre B91 del proyecto Paz para la Mujer

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. var inspect = require('../');
  2. var test = require('tape');
  3. test('values', function (t) {
  4. t.plan(1);
  5. var obj = [ {}, [], { 'a-b': 5 } ];
  6. t.equal(inspect(obj), '[ {}, [], { \'a-b\': 5 } ]');
  7. });
  8. test('arrays with properties', function (t) {
  9. t.plan(1);
  10. var arr = [3];
  11. arr.foo = 'bar';
  12. var obj = [1, 2, arr];
  13. obj.baz = 'quux';
  14. obj.index = -1;
  15. t.equal(inspect(obj), '[ 1, 2, [ 3, foo: \'bar\' ], baz: \'quux\', index: -1 ]');
  16. });
  17. test('has', function (t) {
  18. t.plan(1);
  19. var has = Object.prototype.hasOwnProperty;
  20. delete Object.prototype.hasOwnProperty;
  21. t.equal(inspect({ a: 1, b: 2 }), '{ a: 1, b: 2 }');
  22. Object.prototype.hasOwnProperty = has;
  23. });
  24. test('indexOf seen', function (t) {
  25. t.plan(1);
  26. var xs = [ 1, 2, 3, {} ];
  27. xs.push(xs);
  28. var seen = [];
  29. seen.indexOf = undefined;
  30. t.equal(
  31. inspect(xs, {}, 0, seen),
  32. '[ 1, 2, 3, {}, [Circular] ]'
  33. );
  34. });
  35. test('seen seen', function (t) {
  36. t.plan(1);
  37. var xs = [ 1, 2, 3 ];
  38. var seen = [ xs ];
  39. seen.indexOf = undefined;
  40. t.equal(
  41. inspect(xs, {}, 0, seen),
  42. '[Circular]'
  43. );
  44. });
  45. test('seen seen seen', function (t) {
  46. t.plan(1);
  47. var xs = [ 1, 2, 3 ];
  48. var seen = [ 5, xs ];
  49. seen.indexOf = undefined;
  50. t.equal(
  51. inspect(xs, {}, 0, seen),
  52. '[Circular]'
  53. );
  54. });
  55. test('symbols', { skip: typeof Symbol !== 'function' }, function (t) {
  56. var sym = Symbol('foo');
  57. t.equal(inspect(sym), 'Symbol(foo)', 'Symbol("foo") should be "Symbol(foo)"');
  58. t.equal(inspect(Object(sym)), 'Object(Symbol(foo))', 'Object(Symbol("foo")) should be "Object(Symbol(foo))"');
  59. t.end();
  60. });
  61. test('Map', { skip: typeof Map !== 'function' }, function (t) {
  62. var map = new Map();
  63. map.set({ a: 1 }, ['b']);
  64. map.set(3, NaN);
  65. var expectedString = 'Map (2) {' + inspect({ a: 1 }) + ' => ' + inspect(['b']) + ', 3 => NaN}';
  66. t.equal(inspect(map), expectedString, 'new Map([[{ a: 1 }, ["b"]], [3, NaN]]) should show size and contents');
  67. t.equal(inspect(new Map()), 'Map (0) {}', 'empty Map should show as empty');
  68. var nestedMap = new Map();
  69. nestedMap.set(nestedMap, map);
  70. t.equal(inspect(nestedMap), 'Map (1) {[Circular] => ' + expectedString + '}', 'Map containing a Map should work');
  71. t.end();
  72. });
  73. test('Set', { skip: typeof Set !== 'function' }, function (t) {
  74. var set = new Set();
  75. set.add({ a: 1 });
  76. set.add(['b']);
  77. var expectedString = 'Set (2) {' + inspect({ a: 1 }) + ', ' + inspect(['b']) + '}';
  78. t.equal(inspect(set), expectedString, 'new Set([{ a: 1 }, ["b"]]) should show size and contents');
  79. t.equal(inspect(new Set()), 'Set (0) {}', 'empty Set should show as empty');
  80. var nestedSet = new Set();
  81. nestedSet.add(set);
  82. nestedSet.add(nestedSet);
  83. t.equal(inspect(nestedSet), 'Set (2) {' + expectedString + ', [Circular]}', 'Set containing a Set should work');
  84. t.end();
  85. });
  86. test('Strings', function (t) {
  87. var str = 'abc';
  88. t.equal(inspect(str), "'" + str + "'", 'primitive string shows as such');
  89. t.equal(inspect(str, { quoteStyle: 'single' }), "'" + str + "'", 'primitive string shows as such, single quoted');
  90. t.equal(inspect(str, { quoteStyle: 'double' }), '"' + str + '"', 'primitive string shows as such, double quoted');
  91. t.equal(inspect(Object(str)), 'Object(' + inspect(str) + ')', 'String object shows as such');
  92. t.equal(inspect(Object(str), { quoteStyle: 'single' }), 'Object(' + inspect(str, { quoteStyle: 'single' }) + ')', 'String object shows as such, single quoted');
  93. t.equal(inspect(Object(str), { quoteStyle: 'double' }), 'Object(' + inspect(str, { quoteStyle: 'double' }) + ')', 'String object shows as such, double quoted');
  94. t.end();
  95. });
  96. test('Numbers', function (t) {
  97. var num = 42;
  98. t.equal(inspect(num), String(num), 'primitive number shows as such');
  99. t.equal(inspect(Object(num)), 'Object(' + inspect(num) + ')', 'Number object shows as such');
  100. t.end();
  101. });
  102. test('Booleans', function (t) {
  103. t.equal(inspect(true), String(true), 'primitive true shows as such');
  104. t.equal(inspect(Object(true)), 'Object(' + inspect(true) + ')', 'Boolean object true shows as such');
  105. t.equal(inspect(false), String(false), 'primitive false shows as such');
  106. t.equal(inspect(Object(false)), 'Object(' + inspect(false) + ')', 'Boolean false object shows as such');
  107. t.end();
  108. });