Advertisement
VladNitu

test fp vlad

Mar 19th, 2024
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.98 KB | None | 0 0
  1. # Tests are groups of three lines: program, input, expected output
  2. # Blank lines and lines starting with # are ignored
  3.  
  4. #
  5. # Simple value tests to check parser. Input is irrelevant
  6. #
  7. .
  8. null
  9. null
  10.  
  11. #
  12. # Double number test
  13. #
  14. .
  15. 12.014
  16. 12.014
  17.  
  18. #
  19. # Integer number test
  20. #
  21. .
  22. 123
  23. 123
  24.  
  25. #
  26. # String test basic
  27. #
  28. .
  29. "test string"
  30. "test string"
  31.  
  32. #
  33. # String test escape chars
  34. #
  35. .
  36. "\"Hello World\""
  37. "\"Hello World\""
  38.  
  39. #
  40. # String test number
  41. #
  42. .
  43. "123"
  44. "123"
  45.  
  46. #
  47. # Test floats
  48. #
  49. .
  50. 0.5
  51. 0.5
  52.  
  53. #
  54. # Tests w/ negative floats
  55. #
  56. .
  57. -1.5
  58. -1.5
  59.  
  60. # Test w/ arrays (basic)
  61. #
  62. .
  63. [1,2,3]
  64. [1,2,3]
  65.  
  66.  
  67. # Test w/ empty array
  68. #
  69. .
  70. []
  71. []
  72.  
  73. # Test w/ arrays + spaces
  74. #
  75. .
  76. [1, 2 ,3]
  77. [1,2,3]
  78.  
  79. # Test w/ arrays w/ multiple types of elements
  80. #
  81. .
  82. [1, -1.5 ,"abc"]
  83. [1,-1.5,"abc"]
  84.  
  85. # Test w/ spaces before arrays
  86. #
  87. .
  88. [1, -1.5 ,"abc"]
  89. [1,-1.5,"abc"]
  90.  
  91. # Test JObject basic (1 el)
  92. #
  93. #
  94. .
  95. {"a":1}
  96. {"a":1}
  97.  
  98. # Test JObject basic (>1 diff elements) + spaces
  99. #
  100. #
  101. .
  102. {"a":1, "b": 2, "c": "abc"}
  103. {"a":1,"b":2,"c":"abc"}
  104.  
  105. # Test JObject basic empty arr
  106. #
  107. #
  108. .
  109. {}
  110. {}
  111.  
  112. # Test JObject with Object with JArray
  113. #
  114. #
  115. .
  116. {"a":1, "b": 2, "c": [1, 2, 3]}
  117. {"a":1,"b":2,"c":[1,2,3]}
  118.  
  119.  
  120. #
  121. # String test control char
  122. #
  123. .
  124. "\u2600"
  125. "\u2600"
  126.  
  127. #
  128. # Test weird string
  129. #
  130. .
  131. "Aa\r\n\t\b\f"
  132. "Aa\r\n\t\b\f"
  133.  
  134. #
  135. # True test
  136. #
  137. .
  138. true
  139. true
  140.  
  141. #
  142. # False test
  143. #
  144. .
  145. false
  146. false
  147.  
  148.  
  149. ### FILTERS
  150.  
  151. #
  152. # Filter paranthesis basic case (identity) + spaces (to check token)
  153. #
  154. ( . )
  155. "abc"
  156. "abc"
  157.  
  158. #
  159. # Field access (ObjIndex) which exists
  160. #
  161. .foo
  162. {"foo": 42, "bar": 43}
  163. 42
  164.  
  165.  
  166. #
  167. # Field access (ObjIndex) which exists AND is a string ."foo", but not generic
  168. #
  169. ."foo"
  170. {"foo": 42, "bar": 43}
  171. 42
  172.  
  173. #
  174. # Field access (ObjIndex) which DOES NOT exist
  175. #
  176. .mama
  177. {"foo": 42, "bar": 43}
  178. null
  179.  
  180. #
  181. # ObjIndex generic (ObjValueIt w/ 1 element) -> .["foo"]
  182. #
  183. .["foo"]
  184. {"bar": 43, "foo": 42}
  185. 42
  186.  
  187.  
  188. #
  189. # ObjIndex generic with spaces (ObjValueIt w/ 1 element) -> .["foo bar"]
  190. #
  191. .["foo bar"]
  192. {"foo bar": 43, "foo": 42}
  193. 43
  194.  
  195.  
  196. #
  197. # Field access generic (ObjValueIt) which DOES NOT exist
  198. #
  199. .["mama"]
  200. {"foo": 42, "bar": 43}
  201. null
  202.  
  203. #
  204. # Object Value Iterator w/ multiple elements, some exist, some don't
  205. #
  206. .["abc", "f1", "no"]
  207. {"f1" : "hi", "yes" : null, "abc" : [1,2, 3]}
  208. [1,2,3]
  209. "hi"
  210. null
  211.  
  212. #
  213. # ArrIt through all elements in Array
  214. #
  215. .[]
  216. [0, 1,2,3,4]
  217. 0
  218. 1
  219. 2
  220. 3
  221. 4
  222.  
  223. #
  224. # ObjValueIt through all elements in JObject
  225. #
  226. .[-2, -3]
  227. [0, 1,2,3,4]
  228. 3
  229. 2
  230.  
  231.  
  232. #
  233. # ArrIt negative values
  234. #
  235. .[-3, -2]
  236. [1, 2, 3]
  237. 1
  238. 2
  239.  
  240. #
  241. # ArrIt negative len < 0; -len > length xs should not wrap around -> null
  242. #
  243. .[-100]
  244. [1, 2, 3]
  245. null
  246.  
  247. #
  248. # ArrIt negative len > 0; len > length xs should not wrap around -> null
  249. #
  250. .[100]
  251. [1, 2, 3]
  252. null
  253.  
  254.  
  255. #Tests taken from week4 impl by me and retested here
  256.  
  257. #
  258. # ObjIndex on JNull input
  259. #
  260. .["a"]
  261. null
  262. null
  263.  
  264. #
  265. # ObjIndex all missing
  266. #
  267. .["a", "b"]
  268. {"c":1, "d":2}
  269. null
  270. null
  271.  
  272. #
  273. # ObjIndex one exists
  274. #
  275. .["a", "c"]
  276. {"a": 1, "b": "f"}
  277. 1
  278. null
  279.  
  280. #
  281. # ObjIndex one exists other order
  282. #
  283. .["c", "a"]
  284. {"a": 1, "b": "f"}
  285. null
  286. 1
  287.  
  288.  
  289. #
  290. # ArrIndex test (in bounds)
  291. #
  292. .[2]
  293. [0, 1, "abc",3]
  294. "abc"
  295.  
  296.  
  297. #
  298. # ArrIt w/ multiple indexes, some in bounds, some out of boundsj
  299. #
  300. .[1, 2, 4 ]
  301. [0, 1, 2,3]
  302. 1
  303. 2
  304. null
  305.  
  306.  
  307. #
  308. # ArrIndexSlice both there in bounds
  309. #
  310. .[0:2]
  311. [1,2,3,4]
  312. [1,2]
  313.  
  314. #
  315. # ArrIndexSlice emtpy range
  316. #
  317. .[2:2]
  318. [1,2,3,4]
  319. []
  320.  
  321. #
  322. # ArrIndexSlice only left given
  323. #
  324. .[2:]
  325. [1,2,3,4]
  326. [3,4]
  327.  
  328. #
  329. # ArrIndexSlice only right given
  330. #
  331. .[:3]
  332. [1,2,3,4]
  333. [1,2,3]
  334.  
  335. #
  336. # ArrIndexSlice left >= right
  337. #
  338. .[4:2]
  339. [1,2,3,4,5,6]
  340. []
  341.  
  342. #
  343. # ArrIndex negative (last but not least el : -2)
  344. #
  345. .[-2]
  346. [1,2,3,4,5,6]
  347. 5
  348.  
  349. .foo | .bar
  350. {"foo": {"bar": 42}, "bar": "badvalue"}
  351. 42
  352.  
  353. .foo.bar
  354. {"foo": {"bar": 42}, "bar": "badvalue"}
  355. 42
  356.  
  357. .foo_bar
  358. {"foo_bar": 2}
  359. 2
  360.  
  361. .["foo"].bar
  362. {"foo": {"bar": 42}, "bar": "badvalue"}
  363. 42
  364.  
  365. ."foo"."bar"
  366. {"foo": {"bar": 20}}
  367. 20
  368.  
  369.  
  370. #
  371. # ObjIndex & ArrIndex combined -> Value Constructor, TODO
  372. #
  373. .foo[2]
  374. {"foo" : [1, 2, 3]}
  375. 3
  376.  
  377. #
  378. # Comma and Pipe ambiguous, Comma should have priority
  379. #
  380. .a, .b, .c | .foo
  381. {"a" : {"foo" : 1}, "b" : {"foo" : 2}, "c" : {"foo" : 3}}
  382. 1
  383. 2
  384. 3
  385.  
  386. #
  387. # Comma and Pipe + parnthesis, Comma should have priority
  388. #
  389. .a,.b,(.c|.bar)|.foo
  390. {"a" : {"foo" : 1}, "b" : {"foo" : 2}, "c" : {"foo" : 3, "bar" : {"foo" : 100}}}
  391. 1
  392. 2
  393. 100
  394.  
  395. #
  396. # Paranthesis nested test
  397. #
  398. ((.))
  399. false
  400. false
  401.  
  402. #
  403. # Paranthesis nested - Pipe and Comma inversion of priority
  404. #
  405. .a , (.b | .foo )
  406. {"a" : true, "b" : {"foo" : "lol" } }
  407. true
  408. "lol"
  409.  
  410. #
  411. # Test parenthesis a -> b pipe
  412. #
  413. (.a| .b )
  414. {"a" : {"b" : {"foo" : "lol" }} }
  415. {"foo":"lol"}
  416.  
  417.  
  418. # VALUE CONSTRUCTORS
  419. # Arrays
  420.  
  421. [.[]|.foo?]
  422. [1,[2],{"foo":3,"bar":4},{},{"foo":5}]
  423. [3,null,5]
  424.  
  425. [.[]|.foo?.bar?]
  426. [1,[2],[],{"foo":3},{"foo":{"bar":4}},{}]
  427. [4,null]
  428.  
  429. [.[]|.[]?]
  430. [1,null,[],[1,[2,[[3]]]],[{}],[{"a":[1,[2]]}]]
  431. [1,[2,[[3]]],{},{"a":[1,[2]]}]
  432.  
  433. [.[]|.[1:3]?]
  434. [1,null,true,false,"abcdef",{},{"a":1,"b":2},[],[1,2,3,4,5],[1,2]]
  435. [null,"bc",[],[2,3],[2]]
  436.  
  437. # Value construction
  438.  
  439. true
  440. null
  441. true
  442.  
  443. false
  444. null
  445. false
  446.  
  447. null
  448. 42
  449. null
  450.  
  451. 1
  452. null
  453. 1
  454.  
  455.  
  456. -1
  457. null
  458. -1
  459.  
  460. {}
  461. null
  462. {}
  463.  
  464. []
  465. null
  466. []
  467.  
  468. {x: -1}
  469. null
  470. {"x": -1}
  471.  
  472.  
  473. #
  474. # Dictionary construction syntax
  475. #
  476.  
  477. {a: 1}
  478. null
  479. {"a":1}
  480.  
  481. #
  482. # Dictionary construction when it exists
  483. #
  484.  
  485. {a : 1}
  486. {"a":2}
  487. {"a":1}
  488.  
  489.  
  490. #
  491. # Dictionary construction when it exists
  492. #
  493.  
  494. {a}
  495. {"a":1}
  496. {"a":1}
  497.  
  498.  
  499. {a,b,(.d):.a,e:.b}
  500. {"a":1, "b":2, "c":3, "d":"c"}
  501. {"a":1, "b":2, "c":1, "e":2}
  502.  
  503. # {"a",b,"a$2"}
  504. # {"a":1, "b":2, "c":3, "a$2":4}
  505. # {"a":1, "b":2, "a$2":4}
  506.  
  507. {a}
  508. {"a":1}
  509. {"a":1}
  510.  
  511. {e:.b}
  512. {"a":1, "b":2, "c":3, "d":"c"}
  513. {"e:2}
  514.  
  515. {e:100}
  516. {"a":1, "b":2, "c":3, "d":"c"}
  517. {"e":100}
  518.  
  519. {(.d):2}
  520. {"a":1, "b":2, "c":3, "d":"c"}
  521. {"c":2}
  522.  
  523. {(.d):.a}
  524. {"a":1, "b":2, "c":3, "d":"c"}
  525. {"c":1}
  526.  
  527. {a,b,(.d):.a}
  528. {"a":1, "b":2, "c":3, "d":"c"}
  529. {"a":1, "b":2, "c":1}
  530.  
  531. {e:.b}
  532. {"a":1, "b":2, "c":3, "d":"c"}
  533. {"e": 2}
  534.  
  535. #
  536. # Test assignment 1 - Value ctor
  537. #
  538. {"this" : [.]}
  539. 1
  540. {"this": [1]}
  541.  
  542. #
  543. # Test assignment 2 - Value ctor
  544. #
  545. {"this" : [42]}
  546. null
  547. {"this": [42]}
  548.  
  549. #
  550. # Unicode input
  551. #
  552. # unicode tests are particularly finicky depending on the encoding/OS/terminal
  553. # if the grading tests say you're deadling with unicode just fine
  554. # then you can safely ignore the tests below
  555. # but if you are missing points during grading these might help to debug your project
  556.  
  557. .
  558. "\b\r\f\t\n\r\u02ac\u058E\u05d2\u0606"
  559. "\b\r\f\t\n\rʬ֎ג؆"
  560.  
  561. .
  562. "\u0000"
  563. "\u0000"
  564.  
  565. #
  566. # Null input
  567. #
  568.  
  569. .[0:10]
  570. null
  571. null
  572.  
  573. .[0:10]?
  574. null
  575. null
  576.  
  577. .[0]
  578. null
  579. null
  580.  
  581. .[0]?
  582. null
  583. null
  584.  
  585. .["foo"]
  586. null
  587. null
  588.  
  589. .["foo"]?
  590. null
  591. null
  592.  
  593. .foo
  594. null
  595. null
  596.  
  597. .foo?
  598. null
  599. null
  600.  
  601. #
  602. # Test string slice
  603. #
  604.  
  605. .[1:3]
  606. "abcdef"
  607. "bc"
  608.  
  609. #
  610. # Test string slice
  611. #
  612.  
  613. .[1:3]
  614. "abcdef"
  615. "bc"
  616.  
  617. #
  618. # Recursive descent operator test
  619. #
  620. ..
  621. [{"a": 1}]
  622. [{"a": 1}]
  623. {"a": 1}
  624. 1
  625.  
  626. #
  627. # Recursive descent operator test 2
  628. #
  629. ..
  630. {"a": 1}
  631. {"a": 1}
  632. 1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement