Simple email application for Android. Original source code: https://framagit.org/dystopia-project/simple-email
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.

207 lines
3.6 KiB

  1. import test from 'tape-catch';
  2. import isSubset from './module';
  3. test('Detects shallow subsets.', (is) => {
  4. is.ok(isSubset(
  5. {},
  6. {}
  7. ), 'with empty objects'
  8. );
  9. is.ok(isSubset(
  10. {a: 1},
  11. {}
  12. ), 'with an empty subset'
  13. );
  14. is.ok(isSubset(
  15. {a: 1, b: 2},
  16. {a: 1, b: 2}
  17. ), 'with deep-equal objects'
  18. );
  19. is.ok(isSubset(
  20. {a: 1, b: true, c: null, d: 'D', e: undefined, 'F-': 'anything'},
  21. {a: 1, b: true, c: null, d: 'D', e: undefined, 'F-': 'anything'}
  22. ), 'with deep-equal objects of different kinds of values'
  23. );
  24. is.ok(isSubset(
  25. {a: 1, b: 2},
  26. {a: 1}
  27. ), 'with simple subsets'
  28. );
  29. is.end();
  30. });
  31. test('Detects shallow non-subsets.', (is) => {
  32. is.notOk(isSubset(
  33. {},
  34. {a: 1}
  35. ), 'with an empty superset'
  36. );
  37. is.notOk(isSubset(
  38. {a: 1},
  39. {a: 2}
  40. ), 'with differences in values'
  41. );
  42. is.notOk(isSubset(
  43. {a: 1},
  44. {b: 1}
  45. ), 'with differences in keys'
  46. );
  47. is.notOk(isSubset(
  48. {a: 1},
  49. {a: 1, b: 2}
  50. ), 'with different sizes'
  51. );
  52. is.notOk(isSubset(
  53. {a: 0},
  54. {a: false}
  55. ), 'seeing the difference between falsey values'
  56. );
  57. is.notOk(isSubset(
  58. {a: null},
  59. {a: undefined}
  60. ), 'seeing the difference between null and undefined'
  61. );
  62. is.notOk(isSubset(
  63. {a: 1},
  64. {a: 1, b: undefined}
  65. ), 'seeing the difference between undefined reference and undefined value'
  66. );
  67. is.end();
  68. });
  69. test('Detects deep subsets.', (is) => {
  70. is.ok(isSubset(
  71. {a: {}},
  72. {a: {}}
  73. ), 'with nested empty objects'
  74. );
  75. is.ok(isSubset(
  76. {a: {}},
  77. {}
  78. ), 'with an empty subset'
  79. );
  80. is.ok(isSubset(
  81. {a: {b: 2}},
  82. {a: {}}
  83. ), 'with a nested empty subset'
  84. );
  85. is.ok(isSubset(
  86. {a: {b: 2}},
  87. {a: {b: 2}}
  88. ), 'with deep-equal objects'
  89. );
  90. is.ok(isSubset(
  91. {a: 1, b: true, c: null, d: 'D', e: undefined, 'F-': 'anything'},
  92. {a: 1, b: true, c: null, d: 'D', e: undefined, 'F-': 'anything'}
  93. ), 'with deep-equal objects of different kinds of values'
  94. );
  95. is.ok(isSubset(
  96. {a: 1, b: {c: 3, d: 4}, e: {f: {g: 7, h: {i: 9}}}},
  97. {a: 1, b: {d: 4}, e: {f: {g: 7}}}
  98. ), 'with multiple levels of nesting'
  99. );
  100. is.end();
  101. });
  102. test('Detects deep non-subsets.', (is) => {
  103. is.notOk(isSubset(
  104. {a: {}},
  105. {a: {b: 1}}
  106. ), 'with an empty object in the superset'
  107. );
  108. is.notOk(isSubset(
  109. {a: {b: 2}},
  110. {a: {b: 3}}
  111. ), 'with differences in values in a nested object'
  112. );
  113. is.notOk(isSubset(
  114. {z: {a: 1}},
  115. {z: {b: 1}}
  116. ), 'with differences in keys in a nested object'
  117. );
  118. is.notOk(isSubset(
  119. {z: {a: 1}},
  120. {z: {a: 1, b: 2}}
  121. ), 'with different sizes of a nested object'
  122. );
  123. is.end();
  124. });
  125. test('Works with array values.', (is) => {
  126. is.ok(isSubset(
  127. {a: []},
  128. {a: []}
  129. ), 'treating empty arrays as equal'
  130. );
  131. is.ok(isSubset(
  132. {a: [1]},
  133. {a: [1]}
  134. ), 'treating equal arrays as equal'
  135. );
  136. is.notOk(isSubset(
  137. {a: [1]},
  138. {a: [1, 2]}
  139. ), 'detecting differences in length'
  140. );
  141. is.notOk(isSubset(
  142. {a: [1]},
  143. {a: [2]}
  144. ), 'detecting differences in values'
  145. );
  146. is.ok(isSubset(
  147. {a: [1, 2, 3]},
  148. {a: [1, 2]}
  149. ), 'treating array subsets as subsets'
  150. );
  151. is.notOk(isSubset(
  152. {a: [1, 2, 3]},
  153. {a: [1, 3]}
  154. ), '– only if the order is identical'
  155. );
  156. is.end();
  157. });
  158. test('Returns false for non-object “objects”.', (is) => {
  159. is.notOk(isSubset(
  160. 'a',
  161. {}
  162. ), 'for the superset'
  163. );
  164. is.notOk(isSubset(
  165. {},
  166. 'a'
  167. ), 'for the subset'
  168. );
  169. is.end();
  170. });