better tests and results
This commit is contained in:
parent
4326566ecd
commit
7b9efe9a3e
8 changed files with 24 additions and 15 deletions
2
test.sh
2
test.sh
|
@ -21,7 +21,7 @@ for input in $listfic; do
|
|||
(($?!=0)) && {done=1;continue}
|
||||
read <&3 expected
|
||||
(($?!=0)) && {done=1;continue}
|
||||
result="$( runghc y.hs "$program")"
|
||||
result="$(runghc y.hs "$program")"
|
||||
printf "%18s (line %3d): " ${input:t} $num
|
||||
if [[ $expected == $result ]]; then
|
||||
print -- "OK"
|
||||
|
|
|
@ -1,2 +1,6 @@
|
|||
32
|
||||
32
|
||||
#x012
|
||||
18
|
||||
#b001010
|
||||
Number 10
|
||||
10
|
||||
|
|
|
@ -1,2 +1,2 @@
|
|||
#\a
|
||||
Character 'a'
|
||||
'a'
|
||||
|
|
|
@ -1,2 +1,2 @@
|
|||
3.14
|
||||
Float 3.14
|
||||
3.14
|
||||
|
|
|
@ -1,4 +0,0 @@
|
|||
(a list)
|
||||
List [Atom "a",Atom "list"]
|
||||
(a (nested) list)
|
||||
List [Atom "a",List [Atom "nested"],Atom "list"]
|
|
@ -1,2 +1,2 @@
|
|||
32
|
||||
Number 32
|
||||
32
|
||||
|
|
10
tests/string
10
tests/string
|
@ -1,6 +1,6 @@
|
|||
"This is a simple string"
|
||||
String "This is a simple string"
|
||||
"This is a string with a return ->\n<- Here"
|
||||
String "This is a string with a return ->\n<- Here"
|
||||
"More difficult string \n, \r, \t, \\, \x, \A"
|
||||
String "More difficult string \n, \r, \t, \\, x, A"
|
||||
"This is a simple string"
|
||||
"A tab ->\t<- Here"
|
||||
"A tab -> <- Here"
|
||||
"\S\o\m\e\ \pr\ot\e\ct\e\d\ \w\it\h\ \\"
|
||||
"Some protected with \"
|
||||
|
|
11
y.hs
11
y.hs
|
@ -28,7 +28,16 @@ main = do
|
|||
readExpr :: String -> String
|
||||
readExpr input = case parse parseExpr "lisp" input of
|
||||
Left err -> "No match: " ++ show err
|
||||
Right val -> show val
|
||||
Right val -> showVal val
|
||||
|
||||
showVal :: LispVal -> String
|
||||
showVal (String contents) = "\"" ++ contents ++ "\""
|
||||
showVal (Atom name) = name
|
||||
showVal (Number contents) = show contents
|
||||
showVal (Float contents) = show contents
|
||||
showVal (Character c) = '\'':c:'\'':[]
|
||||
showVal (Bool True) = "#t"
|
||||
showVal (Bool False) = "#f"
|
||||
|
||||
-- parseExpr will parse the Expression
|
||||
parseExpr :: Parser LispVal
|
||||
|
|
Loading…
Reference in a new issue