syntax.json 15 KB

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