empty-keys-cases.js 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  1. 'use strict';
  2. module.exports = {
  3. emptyTestCases: [
  4. {
  5. input: '&',
  6. withEmptyKeys: {},
  7. stringifyOutput: {
  8. brackets: '',
  9. indices: '',
  10. repeat: ''
  11. },
  12. noEmptyKeys: {}
  13. },
  14. {
  15. input: '&&',
  16. withEmptyKeys: {},
  17. stringifyOutput: {
  18. brackets: '',
  19. indices: '',
  20. repeat: ''
  21. },
  22. noEmptyKeys: {}
  23. },
  24. {
  25. input: '&=',
  26. withEmptyKeys: { '': '' },
  27. stringifyOutput: {
  28. brackets: '=',
  29. indices: '=',
  30. repeat: '='
  31. },
  32. noEmptyKeys: {}
  33. },
  34. {
  35. input: '&=&',
  36. withEmptyKeys: { '': '' },
  37. stringifyOutput: {
  38. brackets: '=',
  39. indices: '=',
  40. repeat: '='
  41. },
  42. noEmptyKeys: {}
  43. },
  44. {
  45. input: '&=&=',
  46. withEmptyKeys: { '': ['', ''] },
  47. stringifyOutput: {
  48. brackets: '[]=&[]=',
  49. indices: '[0]=&[1]=',
  50. repeat: '=&='
  51. },
  52. noEmptyKeys: {}
  53. },
  54. {
  55. input: '&=&=&',
  56. withEmptyKeys: { '': ['', ''] },
  57. stringifyOutput: {
  58. brackets: '[]=&[]=',
  59. indices: '[0]=&[1]=',
  60. repeat: '=&='
  61. },
  62. noEmptyKeys: {}
  63. },
  64. {
  65. input: '=',
  66. withEmptyKeys: { '': '' },
  67. noEmptyKeys: {},
  68. stringifyOutput: {
  69. brackets: '=',
  70. indices: '=',
  71. repeat: '='
  72. }
  73. },
  74. {
  75. input: '=&',
  76. withEmptyKeys: { '': '' },
  77. stringifyOutput: {
  78. brackets: '=',
  79. indices: '=',
  80. repeat: '='
  81. },
  82. noEmptyKeys: {}
  83. },
  84. {
  85. input: '=&&&',
  86. withEmptyKeys: { '': '' },
  87. stringifyOutput: {
  88. brackets: '=',
  89. indices: '=',
  90. repeat: '='
  91. },
  92. noEmptyKeys: {}
  93. },
  94. {
  95. input: '=&=&=&',
  96. withEmptyKeys: { '': ['', '', ''] },
  97. stringifyOutput: {
  98. brackets: '[]=&[]=&[]=',
  99. indices: '[0]=&[1]=&[2]=',
  100. repeat: '=&=&='
  101. },
  102. noEmptyKeys: {}
  103. },
  104. {
  105. input: '=&a[]=b&a[1]=c',
  106. withEmptyKeys: { '': '', a: ['b', 'c'] },
  107. stringifyOutput: {
  108. brackets: '=&a[]=b&a[]=c',
  109. indices: '=&a[0]=b&a[1]=c',
  110. repeat: '=&a=b&a=c'
  111. },
  112. noEmptyKeys: { a: ['b', 'c'] }
  113. },
  114. {
  115. input: '=a',
  116. withEmptyKeys: { '': 'a' },
  117. noEmptyKeys: {},
  118. stringifyOutput: {
  119. brackets: '=a',
  120. indices: '=a',
  121. repeat: '=a'
  122. }
  123. },
  124. {
  125. input: 'a==a',
  126. withEmptyKeys: { a: '=a' },
  127. noEmptyKeys: { a: '=a' },
  128. stringifyOutput: {
  129. brackets: 'a==a',
  130. indices: 'a==a',
  131. repeat: 'a==a'
  132. }
  133. },
  134. {
  135. input: '=&a[]=b',
  136. withEmptyKeys: { '': '', a: ['b'] },
  137. stringifyOutput: {
  138. brackets: '=&a[]=b',
  139. indices: '=&a[0]=b',
  140. repeat: '=&a=b'
  141. },
  142. noEmptyKeys: { a: ['b'] }
  143. },
  144. {
  145. input: '=&a[]=b&a[]=c&a[2]=d',
  146. withEmptyKeys: { '': '', a: ['b', 'c', 'd'] },
  147. stringifyOutput: {
  148. brackets: '=&a[]=b&a[]=c&a[]=d',
  149. indices: '=&a[0]=b&a[1]=c&a[2]=d',
  150. repeat: '=&a=b&a=c&a=d'
  151. },
  152. noEmptyKeys: { a: ['b', 'c', 'd'] }
  153. },
  154. {
  155. input: '=a&=b',
  156. withEmptyKeys: { '': ['a', 'b'] },
  157. stringifyOutput: {
  158. brackets: '[]=a&[]=b',
  159. indices: '[0]=a&[1]=b',
  160. repeat: '=a&=b'
  161. },
  162. noEmptyKeys: {}
  163. },
  164. {
  165. input: '=a&foo=b',
  166. withEmptyKeys: { '': 'a', foo: 'b' },
  167. noEmptyKeys: { foo: 'b' },
  168. stringifyOutput: {
  169. brackets: '=a&foo=b',
  170. indices: '=a&foo=b',
  171. repeat: '=a&foo=b'
  172. }
  173. },
  174. {
  175. input: 'a[]=b&a=c&=',
  176. withEmptyKeys: { '': '', a: ['b', 'c'] },
  177. stringifyOutput: {
  178. brackets: '=&a[]=b&a[]=c',
  179. indices: '=&a[0]=b&a[1]=c',
  180. repeat: '=&a=b&a=c'
  181. },
  182. noEmptyKeys: { a: ['b', 'c'] }
  183. },
  184. {
  185. input: 'a[]=b&a=c&=',
  186. withEmptyKeys: { '': '', a: ['b', 'c'] },
  187. stringifyOutput: {
  188. brackets: '=&a[]=b&a[]=c',
  189. indices: '=&a[0]=b&a[1]=c',
  190. repeat: '=&a=b&a=c'
  191. },
  192. noEmptyKeys: { a: ['b', 'c'] }
  193. },
  194. {
  195. input: 'a[0]=b&a=c&=',
  196. withEmptyKeys: { '': '', a: ['b', 'c'] },
  197. stringifyOutput: {
  198. brackets: '=&a[]=b&a[]=c',
  199. indices: '=&a[0]=b&a[1]=c',
  200. repeat: '=&a=b&a=c'
  201. },
  202. noEmptyKeys: { a: ['b', 'c'] }
  203. },
  204. {
  205. input: 'a=b&a[]=c&=',
  206. withEmptyKeys: { '': '', a: ['b', 'c'] },
  207. stringifyOutput: {
  208. brackets: '=&a[]=b&a[]=c',
  209. indices: '=&a[0]=b&a[1]=c',
  210. repeat: '=&a=b&a=c'
  211. },
  212. noEmptyKeys: { a: ['b', 'c'] }
  213. },
  214. {
  215. input: 'a=b&a[0]=c&=',
  216. withEmptyKeys: { '': '', a: ['b', 'c'] },
  217. stringifyOutput: {
  218. brackets: '=&a[]=b&a[]=c',
  219. indices: '=&a[0]=b&a[1]=c',
  220. repeat: '=&a=b&a=c'
  221. },
  222. noEmptyKeys: { a: ['b', 'c'] }
  223. },
  224. {
  225. input: '[]=a&[]=b& []=1',
  226. withEmptyKeys: { '': ['a', 'b'], ' ': ['1'] },
  227. stringifyOutput: {
  228. brackets: '[]=a&[]=b& []=1',
  229. indices: '[0]=a&[1]=b& [0]=1',
  230. repeat: '=a&=b& =1'
  231. },
  232. noEmptyKeys: { 0: 'a', 1: 'b', ' ': ['1'] }
  233. },
  234. {
  235. input: '[0]=a&[1]=b&a[0]=1&a[1]=2',
  236. withEmptyKeys: { '': ['a', 'b'], a: ['1', '2'] },
  237. noEmptyKeys: { 0: 'a', 1: 'b', a: ['1', '2'] },
  238. stringifyOutput: {
  239. brackets: '[]=a&[]=b&a[]=1&a[]=2',
  240. indices: '[0]=a&[1]=b&a[0]=1&a[1]=2',
  241. repeat: '=a&=b&a=1&a=2'
  242. }
  243. },
  244. {
  245. input: '[deep]=a&[deep]=2',
  246. withEmptyKeys: { '': { deep: ['a', '2'] }
  247. },
  248. stringifyOutput: {
  249. brackets: '[deep][]=a&[deep][]=2',
  250. indices: '[deep][0]=a&[deep][1]=2',
  251. repeat: '[deep]=a&[deep]=2'
  252. },
  253. noEmptyKeys: { deep: ['a', '2'] }
  254. },
  255. {
  256. input: '%5B0%5D=a&%5B1%5D=b',
  257. withEmptyKeys: { '': ['a', 'b'] },
  258. stringifyOutput: {
  259. brackets: '[]=a&[]=b',
  260. indices: '[0]=a&[1]=b',
  261. repeat: '=a&=b'
  262. },
  263. noEmptyKeys: { 0: 'a', 1: 'b' }
  264. }
  265. ]
  266. };