Smarter decoding of terms
This update includes an update to `decodeResult` that makes string decoding far less aggressive. This also replaces the `!decode` REPL command with `!output` to allow users to switch output format on the fly. New tests are included for verifying decoding behavior; this group needs to be fleshed out further.
This commit is contained in:
		
							
								
								
									
										33
									
								
								test/Spec.hs
									
									
									
									
									
								
							
							
						
						
									
										33
									
								
								test/Spec.hs
									
									
									
									
									
								
							| @ -34,6 +34,7 @@ tests = testGroup "Tricu Tests" | ||||
|   , fileEval | ||||
|   , modules | ||||
|   , demos | ||||
|   , decoding | ||||
|   ] | ||||
|  | ||||
| lexer :: TestTree | ||||
| @ -522,3 +523,35 @@ demos = testGroup "Test provided demo functionality" | ||||
|       res     <- liftIO $ evaluateFileResult "./demos/levelOrderTraversal.tri" | ||||
|       decodeResult res @?= "\"\n1 \n2 3 \n4 5 6 7 \n8 11 10 9 12 \"" | ||||
|   ] | ||||
|  | ||||
| decoding :: TestTree | ||||
| decoding = testGroup "Decoding Tests" | ||||
|   [ testCase "Decode Leaf" $ do | ||||
|       decodeResult Leaf @?= "t" | ||||
|  | ||||
|   , testCase "Decode list of non-ASCII numbers" $ do | ||||
|       let input = ofList [ofNumber 1, ofNumber 14, ofNumber 6] | ||||
|       decodeResult input @?= "[1, 14, 6]" | ||||
|  | ||||
|   , testCase "Decode list of ASCII numbers as a string" $ do | ||||
|       let input = ofList [ofNumber 97, ofNumber 98, ofNumber 99] | ||||
|       decodeResult input @?= "\"abc\"" | ||||
|  | ||||
|   , testCase "Decode small number" $ do | ||||
|       decodeResult (ofNumber 42) @?= "42" | ||||
|  | ||||
|   , testCase "Decode large number" $ do | ||||
|       decodeResult (ofNumber 9999) @?= "9999" | ||||
|  | ||||
|   , testCase "Decode string in list" $ do | ||||
|       let input = ofList [ofString "hello", ofString "world"] | ||||
|       decodeResult input @?= "[\"hello\", \"world\"]" | ||||
|  | ||||
|   , testCase "Decode mixed list with strings" $ do | ||||
|       let input = ofList [ofString "hello", ofNumber 42, ofString "world"] | ||||
|       decodeResult input @?= "[\"hello\", 42, \"world\"]" | ||||
|  | ||||
|   , testCase "Decode nested lists with strings" $ do | ||||
|       let input = ofList [ofList [ofString "nested"], ofString "string"] | ||||
|       decodeResult input @?= "[[\"nested\"], \"string\"]" | ||||
|   ] | ||||
		Reference in New Issue
	
	Block a user