Advertisement
VladNitu

test fp upstream

Mar 16th, 2024
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.05 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. {a,b,(.d):.a,e:.b}
  482. {"a":1, "b":2, "c":3, "d":"c"}
  483. {"a":1, "b":2, "c":1, "e":2}
  484.  
  485. {"a",b,"a$2"}
  486. {"a":1, "b":2, "c":3, "a$2":4}
  487. {"a":1, "b":2, "a$2":4}
  488.  
  489. #
  490. # Unicode input
  491. #
  492. # unicode tests are particularly finicky depending on the encoding/OS/terminal
  493. # if the grading tests say you're deadling with unicode just fine
  494. # then you can safely ignore the tests below
  495. # but if you are missing points during grading these might help to debug your project
  496.  
  497. .
  498. "\b\r\f\t\n\r\u02ac\u058E\u05d2\u0606"
  499. "\b\r\f\t\n\rʬ֎ג؆"
  500.  
  501. .
  502. "\u0000"
  503. "\u0000"
  504.  
  505. #
  506. # Null input
  507. #
  508.  
  509. .[0:10]
  510. null
  511. null
  512.  
  513. .[0:10]?
  514. null
  515. null
  516.  
  517. .[0]
  518. null
  519. null
  520.  
  521. .[0]?
  522. null
  523. null
  524.  
  525. .["foo"]
  526. null
  527. null
  528.  
  529. .["foo"]?
  530. null
  531. null
  532.  
  533. .foo
  534. null
  535. null
  536.  
  537. .foo?
  538. null
  539. null
  540.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement