slice.json 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. [{
  2. "given": {
  3. "foo": [0, 1, 2, 3, 4, 5, 6, 7, 8, 9],
  4. "bar": {
  5. "baz": 1
  6. }
  7. },
  8. "cases": [
  9. {
  10. "expression": "bar[0:10]",
  11. "result": null
  12. },
  13. {
  14. "expression": "foo[0:10:1]",
  15. "result": [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
  16. },
  17. {
  18. "expression": "foo[0:10]",
  19. "result": [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
  20. },
  21. {
  22. "expression": "foo[0:10:]",
  23. "result": [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
  24. },
  25. {
  26. "expression": "foo[0::1]",
  27. "result": [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
  28. },
  29. {
  30. "expression": "foo[0::]",
  31. "result": [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
  32. },
  33. {
  34. "expression": "foo[0:]",
  35. "result": [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
  36. },
  37. {
  38. "expression": "foo[:10:1]",
  39. "result": [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
  40. },
  41. {
  42. "expression": "foo[::1]",
  43. "result": [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
  44. },
  45. {
  46. "expression": "foo[:10:]",
  47. "result": [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
  48. },
  49. {
  50. "expression": "foo[::]",
  51. "result": [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
  52. },
  53. {
  54. "expression": "foo[:]",
  55. "result": [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
  56. },
  57. {
  58. "expression": "foo[1:9]",
  59. "result": [1, 2, 3, 4, 5, 6, 7, 8]
  60. },
  61. {
  62. "expression": "foo[0:10:2]",
  63. "result": [0, 2, 4, 6, 8]
  64. },
  65. {
  66. "expression": "foo[5:]",
  67. "result": [5, 6, 7, 8, 9]
  68. },
  69. {
  70. "expression": "foo[5::2]",
  71. "result": [5, 7, 9]
  72. },
  73. {
  74. "expression": "foo[::2]",
  75. "result": [0, 2, 4, 6, 8]
  76. },
  77. {
  78. "expression": "foo[::-1]",
  79. "result": [9, 8, 7, 6, 5, 4, 3, 2, 1, 0]
  80. },
  81. {
  82. "expression": "foo[1::2]",
  83. "result": [1, 3, 5, 7, 9]
  84. },
  85. {
  86. "expression": "foo[10:0:-1]",
  87. "result": [9, 8, 7, 6, 5, 4, 3, 2, 1]
  88. },
  89. {
  90. "expression": "foo[10:5:-1]",
  91. "result": [9, 8, 7, 6]
  92. },
  93. {
  94. "expression": "foo[8:2:-2]",
  95. "result": [8, 6, 4]
  96. },
  97. {
  98. "expression": "foo[0:20]",
  99. "result": [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
  100. },
  101. {
  102. "expression": "foo[10:-20:-1]",
  103. "result": [9, 8, 7, 6, 5, 4, 3, 2, 1, 0]
  104. },
  105. {
  106. "expression": "foo[10:-20]",
  107. "result": []
  108. },
  109. {
  110. "expression": "foo[-4:-1]",
  111. "result": [6, 7, 8]
  112. },
  113. {
  114. "expression": "foo[:-5:-1]",
  115. "result": [9, 8, 7, 6]
  116. },
  117. {
  118. "expression": "foo[8:2:0]",
  119. "error": "invalid-value"
  120. },
  121. {
  122. "expression": "foo[8:2:0:1]",
  123. "error": "syntax"
  124. },
  125. {
  126. "expression": "foo[8:2&]",
  127. "error": "syntax"
  128. },
  129. {
  130. "expression": "foo[2:a:3]",
  131. "error": "syntax"
  132. }
  133. ]
  134. }, {
  135. "given": {
  136. "foo": [{"a": 1}, {"a": 2}, {"a": 3}],
  137. "bar": [{"a": {"b": 1}}, {"a": {"b": 2}},
  138. {"a": {"b": 3}}],
  139. "baz": 50
  140. },
  141. "cases": [
  142. {
  143. "expression": "foo[:2].a",
  144. "result": [1, 2]
  145. },
  146. {
  147. "expression": "foo[:2].b",
  148. "result": []
  149. },
  150. {
  151. "expression": "foo[:2].a.b",
  152. "result": []
  153. },
  154. {
  155. "expression": "bar[::-1].a.b",
  156. "result": [3, 2, 1]
  157. },
  158. {
  159. "expression": "bar[:2].a.b",
  160. "result": [1, 2]
  161. },
  162. {
  163. "expression": "baz[:2].a",
  164. "result": null
  165. }
  166. ]
  167. }, {
  168. "given": [{"a": 1}, {"a": 2}, {"a": 3}],
  169. "cases": [
  170. {
  171. "expression": "[:]",
  172. "result": [{"a": 1}, {"a": 2}, {"a": 3}]
  173. },
  174. {
  175. "expression": "[:2].a",
  176. "result": [1, 2]
  177. },
  178. {
  179. "expression": "[::-1].a",
  180. "result": [3, 2, 1]
  181. },
  182. {
  183. "expression": "[:2].b",
  184. "result": []
  185. }
  186. ]
  187. }]