% $Id: MyOzParserTest.oz,v 1.8 2012/01/10 15:59:42 leavens Exp $ \insert 'MyOzParser.oz' \insert 'Desugar.oz' \insert 'Unparse.oz' \insert 'TestingNoStop.oz' {StartTesting 'MyOzParserTest $Revision: 1.8 $'} proc {Reporter error(coord:Coord kind:_ msg:Message)} % ENSURES: Output shows the message {System.showInfo {PositionMsg Coord}#': '#Message} end proc {TestParseVS FileName VS Connective Expected} {ReportAbout '\nRunning test '#FileName} PT = {ParseVS VS FileName Reporter} in {ReportAbout {Value.toVirtualString PT 20 20}} {TestString {UnparseToString PT} Connective Expected} end proc {TestParseFile FN Connective Expected} {ReportAbout '\nRunning test '#FN} PT = {ParseFile FN Reporter} in {ReportAbout {Value.toVirtualString PT 20 20}} {TestString {UnparseToString PT} Connective Expected} end % {TestString {UnparseToString % {List.take {ParseExpression {OzLexer "1" 'one'}} 1}} % '==' "1"} {TestParseVS 'assign1' "X = Y" '==' "X = Y"} {TestParseVS 'add1' "X = 3 + 4 + 5" '==' "X = {Number.'+' {Number.'+' 3 4} 5}"} {TestParseVS 'add2' "X = 6 - 7 - 8 + 9" '==' "X = {Number.'+' {Number.'-' {Number.'-' 6 7} 8} 9}"} {TestParseVS 'mult1' "X = 4*5" '==' "X = {Number.'*' 4 5}"} {TestParseVS 'precd1' "X = 3 - 4*5" '==' "X = {Number.'-' 3 {Number.'*' 4 5}}"} {TestParseVS 'precd2' "X = ~~3" '==' "X = {Number.'~' ~3}"} {TestParseVS 'precd3' "X = !!!!Y" '==' "X = {Value.'!!' {Value.'!!' Y}}"} {TestParseVS 'precd4' "X = 3+5|(5+7*8)#~!!Y|nil" '==' "X = '|'(1:{Number.'+' 3 5} 2:'|'(1:'#'(1:{Number.'+' 5 {Number.'*' 7 8}} 2:{Number.'~' {Value.'!!' Y}}) 2:nil))"} {TestParseVS 'precd5' "X = 3#4#5#6#7" '==' "X = '#'(1:3 2:4 3:5 4:6 5:7)"} {TestParseVS 'local1' "local Res in Res=2 end" '==' "local Res in Res = 2 end"} {TestParseVS 'fun0' "fun {Zero} 0 end" '==' "fun {Zero} 0 end"} {TestParseVS 'fun1' "local R in R={Two} end" '==' "local R in R = {Two} end"} {TestParseVS 'fun2' "fun {Two} 2 end local R in R={Two} end" '==' "fun {Two} 2 end local R in R = {Two} end"} {TestParseVS 'fun3' "fun {Pair X Y} X+Y end" '==' "fun {Pair X Y} {Number.'+' X Y} end"} {TestParseVS 'fun4' "fun {Cons E Es} E|Es end" '==' "fun {Cons E Es} '|'(1:E 2:Es) end"} {TestParseVS 'fun5' "fun {First E|Es} E end" '==' "fun {First '|'(1:E 2:Es)} E end"} {TestParseVS 'fun6' "fun {First A#B|As#Bs} (A|As)#(B|Bs) end" '==' "fun {First '|'(1:'#'(1:A 2:B) 2:'#'(1:As 2:Bs))} '#'(1:'|'(1:A 2:As) 2:'|'(1:B 2:Bs)) end"} {TestParseVS 'bool1' "X = true" '==' "X = true"} {TestParseVS 'bool2' "X = false" '==' "X = false"} {TestParseVS 'pair1' "P = a#b" '==' "P = '#'(1:a 2:b)"} {TestParseVS 'pair2' "P = '#'(1:a 2:b)" '==' "P = '#'(1:a 2:b)"} {TestParseVS 'list1' "X = E|Es" '==' "X = '|'(1:E 2:Es)"} {TestParseVS 'list1' "X = '|'(1:E 2:Es)" '==' "X = '|'(1:E 2:Es)"} {TestParseVS 'float1' "X = 3.1416" '==' "X = 3.1416"} {TestParseVS 'skip1' "skip" '==' "skip"} {TestParseVS 'if1' "if B then skip else skip end" '==' "if B then skip else skip end"} {TestParseVS 'if1.5' "if B then R = Y else R = Z end" '==' "if B then R = Y else R = Z end"} {TestParseVS 'if2' "if B then Y = 3 in R = Y else R = Z end" '==' "if B then Y = 3 in R = Y else R = Z end"} {TestParseVS 'if2.8' "if B then Y = 3 in R = Y else foo(Z Zs) = foo(1 nil) in R = Z end" '==' "if B then Y = 3 in R = Y else foo(1:Z 2:Zs) = foo(1:1 2:nil) in R = Z end"} {TestParseVS 'if2.9' "if B then Y = 3 in R = Y else '|'(Z Zs) = '|'(1 nil) in R = Z end" '==' "if B then Y = 3 in R = Y else '|'(1:Z 2:Zs) = '|'(1:1 2:nil) in R = Z end"} {TestParseVS 'if3' "if B then Y = 3 in R = Y else Z|Zs = 1|nil in R = Z end" '==' "if B then Y = 3 in R = Y else '|'(1:Z 2:Zs) = '|'(1:1 2:nil) in R = Z end"} {TestParseVS 'case0' "case L of X then skip else skip end" '==' "case L of X then skip else skip end"} {TestParseVS 'case0.5' "case B of true then skip else skip end" '==' "case B of true then skip else skip end"} {TestParseVS 'case0.7' "case B of true then R = B else skip end" '==' "case B of true then R = B else skip end"} {TestParseVS 'case1' "case L of E|Es then skip else skip end" '==' "case L of '|'(1:E 2:Es) then skip else skip end"} {TestParseVS 'nil1' "Z = nil" '==' "Z = nil"} {TestParseVS 'appE1' "Z = {Append E Es}" '==' "Z = {Append E Es}"} {TestParseVS 'case1.8' "Z = case L of X then {Append E Es} else nil end" '==' "Z = case L of X then {Append E Es} else nil end"} {TestParseVS 'case1.9' "Z = case L of E|Es then {Append E Es} else nil end" '==' "Z = case L of '|'(1:E 2:Es) then {Append E Es} else nil end"} {TestParseVS 'case2' "Z = case L of '|'(1:E 2:Es) then {Append E Es} else nil end" '==' "Z = case L of '|'(1:E 2:Es) then {Append E Es} else nil end"} {TestParseVS 'applyStmt1' "{Append {F E} {AppendMap Es F}}" '==' "{Append {F E} {AppendMap Es F}}"} {TestParseVS 'applyExp1' "Z = {Append {F E} {AppendMap Es F}}" '==' "Z = {Append {F E} {AppendMap Es F}}"} {TestParseVS 'case3' "Z = case L of '|'(1:E 2:Es) then {Append {F E} {AppendMap Es F}} else nil end" '==' "Z = case L of '|'(1:E 2:Es) then {Append {F E} {AppendMap Es F}} else nil end"} {TestParseVS 'progSeq1' "X = 1 Y = 2" '==' "X = 1 Y = 2"} {TestParseVS 'declare0' "declare X = 0 Y = X" '==' "declare X = 0 Y = X"} {TestParseVS 'declare0.5' "declare A = nil B = Four|A" '==' "declare A = nil B = '|'(1:Four 2:A)"} {TestParseVS 'declare1' "declare X = 1" '==' "declare X = 1"} {TestParseVS 'declare1.2' "declare X = 1 Y = 2" '==' "declare X = 1 Y = 2"} {TestParseVS 'declare2' "declare X = 1 in Y = X" '==' "declare X = 1 in Y = X"} {TestParseVS 'AppendMapString' "declare fun {AppendMap L F} case L of E|Es then {Append {F E} {AppendMap Es F}} else nil end end" '==' "declare fun {AppendMap L F} case L of '|'(1:E 2:Es) then {Append {F E} {AppendMap Es F}} else nil end end"} {TestParseFile 'AppendMap.oz' '==' {Append "declare fun {AppendMap L F} case L of '|'(1:E 2:Es) then " "{Append {F E} {AppendMap Es F}} else nil end end"}} % {TestParseFile 'AppendMap.oz' % '==' % {Append "fun {AppendMap L F} case L of '|'(1:E 2:Es) then " % "{Append {F E} {AppendMap Es F}} else nil end end"}} {TestParseFile 'tests/AddToEach.oz' '==' {FoldR ["declare" " fun {AddToEach '#'(1:A 2:B) Ls}" " case Ls of" " '|'(1:'#'(1:X 2:Y) 2:T) then '|'(1:'#'(1:{Plus A X} 2:{Plus B Y})" " 2:{AddToEach '#'(1:A 2:B) T})" " else nil" " end" " end" ] Append nil}} {TestParseFile 'tests/ParseError1.oz' '==' "Parse-Error at File \"tests/ParseError1.oz\", line 1, column 1"} {DoneTesting}