syntax.json 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616
  1. [{
  2. "comment": "Dot syntax",
  3. "given": {"type": "object"},
  4. "cases": [
  5. {
  6. "expression": "foo.bar",
  7. "result": null
  8. },
  9. {
  10. "expression": "foo.1",
  11. "error": "syntax"
  12. },
  13. {
  14. "expression": "foo.-11",
  15. "error": "syntax"
  16. },
  17. {
  18. "expression": "foo",
  19. "result": null
  20. },
  21. {
  22. "expression": "foo.",
  23. "error": "syntax"
  24. },
  25. {
  26. "expression": "foo.",
  27. "error": "syntax"
  28. },
  29. {
  30. "expression": ".foo",
  31. "error": "syntax"
  32. },
  33. {
  34. "expression": "foo..bar",
  35. "error": "syntax"
  36. },
  37. {
  38. "expression": "foo.bar.",
  39. "error": "syntax"
  40. },
  41. {
  42. "expression": "foo[.]",
  43. "error": "syntax"
  44. }
  45. ]
  46. },
  47. {
  48. "comment": "Simple token errors",
  49. "given": {"type": "object"},
  50. "cases": [
  51. {
  52. "expression": ".",
  53. "error": "syntax"
  54. },
  55. {
  56. "expression": ":",
  57. "error": "syntax"
  58. },
  59. {
  60. "expression": ",",
  61. "error": "syntax"
  62. },
  63. {
  64. "expression": "]",
  65. "error": "syntax"
  66. },
  67. {
  68. "expression": "[",
  69. "error": "syntax"
  70. },
  71. {
  72. "expression": "}",
  73. "error": "syntax"
  74. },
  75. {
  76. "expression": "{",
  77. "error": "syntax"
  78. },
  79. {
  80. "expression": ")",
  81. "error": "syntax"
  82. },
  83. {
  84. "expression": "(",
  85. "error": "syntax"
  86. },
  87. {
  88. "expression": "((&",
  89. "error": "syntax"
  90. },
  91. {
  92. "expression": "a[",
  93. "error": "syntax"
  94. },
  95. {
  96. "expression": "a]",
  97. "error": "syntax"
  98. },
  99. {
  100. "expression": "a][",
  101. "error": "syntax"
  102. },
  103. {
  104. "expression": "!",
  105. "error": "syntax"
  106. }
  107. ]
  108. },
  109. {
  110. "comment": "Boolean syntax errors",
  111. "given": {"type": "object"},
  112. "cases": [
  113. {
  114. "expression": "![!(!",
  115. "error": "syntax"
  116. }
  117. ]
  118. },
  119. {
  120. "comment": "Wildcard syntax",
  121. "given": {"type": "object"},
  122. "cases": [
  123. {
  124. "expression": "*",
  125. "result": ["object"]
  126. },
  127. {
  128. "expression": "*.*",
  129. "result": []
  130. },
  131. {
  132. "expression": "*.foo",
  133. "result": []
  134. },
  135. {
  136. "expression": "*[0]",
  137. "result": []
  138. },
  139. {
  140. "expression": ".*",
  141. "error": "syntax"
  142. },
  143. {
  144. "expression": "*foo",
  145. "error": "syntax"
  146. },
  147. {
  148. "expression": "*0",
  149. "error": "syntax"
  150. },
  151. {
  152. "expression": "foo[*]bar",
  153. "error": "syntax"
  154. },
  155. {
  156. "expression": "foo[*]*",
  157. "error": "syntax"
  158. }
  159. ]
  160. },
  161. {
  162. "comment": "Flatten syntax",
  163. "given": {"type": "object"},
  164. "cases": [
  165. {
  166. "expression": "[]",
  167. "result": null
  168. }
  169. ]
  170. },
  171. {
  172. "comment": "Simple bracket syntax",
  173. "given": {"type": "object"},
  174. "cases": [
  175. {
  176. "expression": "[0]",
  177. "result": null
  178. },
  179. {
  180. "expression": "[*]",
  181. "result": null
  182. },
  183. {
  184. "expression": "*.[0]",
  185. "error": "syntax"
  186. },
  187. {
  188. "expression": "*.[\"0\"]",
  189. "result": [[null]]
  190. },
  191. {
  192. "expression": "[*].bar",
  193. "result": null
  194. },
  195. {
  196. "expression": "[*][0]",
  197. "result": null
  198. },
  199. {
  200. "expression": "foo[#]",
  201. "error": "syntax"
  202. }
  203. ]
  204. },
  205. {
  206. "comment": "Multi-select list syntax",
  207. "given": {"type": "object"},
  208. "cases": [
  209. {
  210. "expression": "foo[0]",
  211. "result": null
  212. },
  213. {
  214. "comment": "Valid multi-select of a list",
  215. "expression": "foo[0, 1]",
  216. "error": "syntax"
  217. },
  218. {
  219. "expression": "foo.[0]",
  220. "error": "syntax"
  221. },
  222. {
  223. "expression": "foo.[*]",
  224. "result": null
  225. },
  226. {
  227. "comment": "Multi-select of a list with trailing comma",
  228. "expression": "foo[0, ]",
  229. "error": "syntax"
  230. },
  231. {
  232. "comment": "Multi-select of a list with trailing comma and no close",
  233. "expression": "foo[0,",
  234. "error": "syntax"
  235. },
  236. {
  237. "comment": "Multi-select of a list with trailing comma and no close",
  238. "expression": "foo.[a",
  239. "error": "syntax"
  240. },
  241. {
  242. "comment": "Multi-select of a list with extra comma",
  243. "expression": "foo[0,, 1]",
  244. "error": "syntax"
  245. },
  246. {
  247. "comment": "Multi-select of a list using an identifier index",
  248. "expression": "foo[abc]",
  249. "error": "syntax"
  250. },
  251. {
  252. "comment": "Multi-select of a list using identifier indices",
  253. "expression": "foo[abc, def]",
  254. "error": "syntax"
  255. },
  256. {
  257. "comment": "Multi-select of a list using an identifier index",
  258. "expression": "foo[abc, 1]",
  259. "error": "syntax"
  260. },
  261. {
  262. "comment": "Multi-select of a list using an identifier index with trailing comma",
  263. "expression": "foo[abc, ]",
  264. "error": "syntax"
  265. },
  266. {
  267. "comment": "Valid multi-select of a hash using an identifier index",
  268. "expression": "foo.[abc]",
  269. "result": null
  270. },
  271. {
  272. "comment": "Valid multi-select of a hash",
  273. "expression": "foo.[abc, def]",
  274. "result": null
  275. },
  276. {
  277. "comment": "Multi-select of a hash using a numeric index",
  278. "expression": "foo.[abc, 1]",
  279. "error": "syntax"
  280. },
  281. {
  282. "comment": "Multi-select of a hash with a trailing comma",
  283. "expression": "foo.[abc, ]",
  284. "error": "syntax"
  285. },
  286. {
  287. "comment": "Multi-select of a hash with extra commas",
  288. "expression": "foo.[abc,, def]",
  289. "error": "syntax"
  290. },
  291. {
  292. "comment": "Multi-select of a hash using number indices",
  293. "expression": "foo.[0, 1]",
  294. "error": "syntax"
  295. }
  296. ]
  297. },
  298. {
  299. "comment": "Multi-select hash syntax",
  300. "given": {"type": "object"},
  301. "cases": [
  302. {
  303. "comment": "No key or value",
  304. "expression": "a{}",
  305. "error": "syntax"
  306. },
  307. {
  308. "comment": "No closing token",
  309. "expression": "a{",
  310. "error": "syntax"
  311. },
  312. {
  313. "comment": "Not a key value pair",
  314. "expression": "a{foo}",
  315. "error": "syntax"
  316. },
  317. {
  318. "comment": "Missing value and closing character",
  319. "expression": "a{foo:",
  320. "error": "syntax"
  321. },
  322. {
  323. "comment": "Missing closing character",
  324. "expression": "a{foo: 0",
  325. "error": "syntax"
  326. },
  327. {
  328. "comment": "Missing value",
  329. "expression": "a{foo:}",
  330. "error": "syntax"
  331. },
  332. {
  333. "comment": "Trailing comma and no closing character",
  334. "expression": "a{foo: 0, ",
  335. "error": "syntax"
  336. },
  337. {
  338. "comment": "Missing value with trailing comma",
  339. "expression": "a{foo: ,}",
  340. "error": "syntax"
  341. },
  342. {
  343. "comment": "Accessing Array using an identifier",
  344. "expression": "a{foo: bar}",
  345. "error": "syntax"
  346. },
  347. {
  348. "expression": "a{foo: 0}",
  349. "error": "syntax"
  350. },
  351. {
  352. "comment": "Missing key-value pair",
  353. "expression": "a.{}",
  354. "error": "syntax"
  355. },
  356. {
  357. "comment": "Not a key-value pair",
  358. "expression": "a.{foo}",
  359. "error": "syntax"
  360. },
  361. {
  362. "comment": "Missing value",
  363. "expression": "a.{foo:}",
  364. "error": "syntax"
  365. },
  366. {
  367. "comment": "Missing value with trailing comma",
  368. "expression": "a.{foo: ,}",
  369. "error": "syntax"
  370. },
  371. {
  372. "comment": "Valid multi-select hash extraction",
  373. "expression": "a.{foo: bar}",
  374. "result": null
  375. },
  376. {
  377. "comment": "Valid multi-select hash extraction",
  378. "expression": "a.{foo: bar, baz: bam}",
  379. "result": null
  380. },
  381. {
  382. "comment": "Trailing comma",
  383. "expression": "a.{foo: bar, }",
  384. "error": "syntax"
  385. },
  386. {
  387. "comment": "Missing key in second key-value pair",
  388. "expression": "a.{foo: bar, baz}",
  389. "error": "syntax"
  390. },
  391. {
  392. "comment": "Missing value in second key-value pair",
  393. "expression": "a.{foo: bar, baz:}",
  394. "error": "syntax"
  395. },
  396. {
  397. "comment": "Trailing comma",
  398. "expression": "a.{foo: bar, baz: bam, }",
  399. "error": "syntax"
  400. },
  401. {
  402. "comment": "Nested multi select",
  403. "expression": "{\"\\\\\":{\" \":*}}",
  404. "result": {"\\": {" ": ["object"]}}
  405. }
  406. ]
  407. },
  408. {
  409. "comment": "Or expressions",
  410. "given": {"type": "object"},
  411. "cases": [
  412. {
  413. "expression": "foo || bar",
  414. "result": null
  415. },
  416. {
  417. "expression": "foo ||",
  418. "error": "syntax"
  419. },
  420. {
  421. "expression": "foo.|| bar",
  422. "error": "syntax"
  423. },
  424. {
  425. "expression": " || foo",
  426. "error": "syntax"
  427. },
  428. {
  429. "expression": "foo || || foo",
  430. "error": "syntax"
  431. },
  432. {
  433. "expression": "foo.[a || b]",
  434. "result": null
  435. },
  436. {
  437. "expression": "foo.[a ||]",
  438. "error": "syntax"
  439. },
  440. {
  441. "expression": "\"foo",
  442. "error": "syntax"
  443. }
  444. ]
  445. },
  446. {
  447. "comment": "Filter expressions",
  448. "given": {"type": "object"},
  449. "cases": [
  450. {
  451. "expression": "foo[?bar==`\"baz\"`]",
  452. "result": null
  453. },
  454. {
  455. "expression": "foo[? bar == `\"baz\"` ]",
  456. "result": null
  457. },
  458. {
  459. "expression": "foo[ ?bar==`\"baz\"`]",
  460. "error": "syntax"
  461. },
  462. {
  463. "expression": "foo[?bar==]",
  464. "error": "syntax"
  465. },
  466. {
  467. "expression": "foo[?==]",
  468. "error": "syntax"
  469. },
  470. {
  471. "expression": "foo[?==bar]",
  472. "error": "syntax"
  473. },
  474. {
  475. "expression": "foo[?bar==baz?]",
  476. "error": "syntax"
  477. },
  478. {
  479. "expression": "foo[?a.b.c==d.e.f]",
  480. "result": null
  481. },
  482. {
  483. "expression": "foo[?bar==`[0, 1, 2]`]",
  484. "result": null
  485. },
  486. {
  487. "expression": "foo[?bar==`[\"a\", \"b\", \"c\"]`]",
  488. "result": null
  489. },
  490. {
  491. "comment": "Literal char not escaped",
  492. "expression": "foo[?bar==`[\"foo`bar\"]`]",
  493. "error": "syntax"
  494. },
  495. {
  496. "comment": "Literal char escaped",
  497. "expression": "foo[?bar==`[\"foo\\`bar\"]`]",
  498. "result": null
  499. },
  500. {
  501. "comment": "Unknown comparator",
  502. "expression": "foo[?bar<>baz]",
  503. "error": "syntax"
  504. },
  505. {
  506. "comment": "Unknown comparator",
  507. "expression": "foo[?bar^baz]",
  508. "error": "syntax"
  509. },
  510. {
  511. "expression": "foo[bar==baz]",
  512. "error": "syntax"
  513. },
  514. {
  515. "comment": "Quoted identifier in filter expression no spaces",
  516. "expression": "[?\"\\\\\">`\"foo\"`]",
  517. "result": null
  518. },
  519. {
  520. "comment": "Quoted identifier in filter expression with spaces",
  521. "expression": "[?\"\\\\\" > `\"foo\"`]",
  522. "result": null
  523. }
  524. ]
  525. },
  526. {
  527. "comment": "Filter expression errors",
  528. "given": {"type": "object"},
  529. "cases": [
  530. {
  531. "expression": "bar.`\"anything\"`",
  532. "error": "syntax"
  533. },
  534. {
  535. "expression": "bar.baz.noexists.`\"literal\"`",
  536. "error": "syntax"
  537. },
  538. {
  539. "comment": "Literal wildcard projection",
  540. "expression": "foo[*].`\"literal\"`",
  541. "error": "syntax"
  542. },
  543. {
  544. "expression": "foo[*].name.`\"literal\"`",
  545. "error": "syntax"
  546. },
  547. {
  548. "expression": "foo[].name.`\"literal\"`",
  549. "error": "syntax"
  550. },
  551. {
  552. "expression": "foo[].name.`\"literal\"`.`\"subliteral\"`",
  553. "error": "syntax"
  554. },
  555. {
  556. "comment": "Projecting a literal onto an empty list",
  557. "expression": "foo[*].name.noexist.`\"literal\"`",
  558. "error": "syntax"
  559. },
  560. {
  561. "expression": "foo[].name.noexist.`\"literal\"`",
  562. "error": "syntax"
  563. },
  564. {
  565. "expression": "twolen[*].`\"foo\"`",
  566. "error": "syntax"
  567. },
  568. {
  569. "comment": "Two level projection of a literal",
  570. "expression": "twolen[*].threelen[*].`\"bar\"`",
  571. "error": "syntax"
  572. },
  573. {
  574. "comment": "Two level flattened projection of a literal",
  575. "expression": "twolen[].threelen[].`\"bar\"`",
  576. "error": "syntax"
  577. }
  578. ]
  579. },
  580. {
  581. "comment": "Identifiers",
  582. "given": {"type": "object"},
  583. "cases": [
  584. {
  585. "expression": "foo",
  586. "result": null
  587. },
  588. {
  589. "expression": "\"foo\"",
  590. "result": null
  591. },
  592. {
  593. "expression": "\"\\\\\"",
  594. "result": null
  595. }
  596. ]
  597. },
  598. {
  599. "comment": "Combined syntax",
  600. "given": [],
  601. "cases": [
  602. {
  603. "expression": "*||*|*|*",
  604. "result": []
  605. },
  606. {
  607. "expression": "*[]||[*]",
  608. "result": []
  609. },
  610. {
  611. "expression": "[*.*]",
  612. "result": [[]]
  613. }
  614. ]
  615. }
  616. ]