From afe13e92cf46e0bd4bf493bd0896f9fc0152ff37 Mon Sep 17 00:00:00 2001 From: Chimrod <> Date: Sun, 24 Sep 2023 12:51:35 +0200 Subject: Variable without index are now evaluated as well --- test/qsp_parser_test.ml | 72 +++++++++++++++++-------------------------------- 1 file changed, 25 insertions(+), 47 deletions(-) (limited to 'test') diff --git a/test/qsp_parser_test.ml b/test/qsp_parser_test.ml index 6ac8bfa..505f905 100644 --- a/test/qsp_parser_test.ml +++ b/test/qsp_parser_test.ml @@ -61,7 +61,7 @@ let test_negative_numeric_expression () = [ Expression (Op (_position, Neg, Integer (_position, "123"))) ] let test_negative_numeric_expression2 () = - let index = Some Ast.(Integer (_position, "0")) in + let index = None in let var = { Ast.pos = _position; name = "CURTIMESUN"; index } in _test_instruction "-(780-CurTimeSun)" Ast. @@ -75,12 +75,12 @@ let test_negative_numeric_expression2 () = ] let test_str_variable () = - let index = Some T.(Integer (_position, "0")) in + let index = None in let var = { Ast.pos = _position; name = "$VALUE"; index } in _test_instruction "$value" [ Expression (Ident var) ] let test_variable () = - let index = Some Ast.(Integer (_position, "0")) in + let index = None in let var = { Ast.pos = _position; name = "VALUE"; index } in _test_instruction "value" [ Expression (Ident var) ] @@ -90,7 +90,7 @@ let test_indexed_variable () = _test_instruction "value[1]" [ Expression (Ident var) ] let test_let_literal () = - let index = Some Ast.(Integer (_position, "0")) in + let index = None in let var = { Ast.pos = _position; name = "VALUE"; index } in _test_instruction "let value = '123'" Ast.[ Declaration (_position, var, Eq', Literal (_position, "123")) ] @@ -101,13 +101,13 @@ let test_set_array_append () = Ast.[ Declaration (_position, var, Eq', Literal (_position, "")) ] let test_direct_assignation () = - let index = Some Ast.(Integer (_position, "0")) in + let index = None in let var = { T.pos = _position; name = "VALUE"; index } in _test_instruction "value = '123'" Ast.[ Declaration (_position, var, Eq', Literal (_position, "123")) ] let test_command_assignation () = - let index = Some Ast.(Integer (_position, "0")) in + let index = None in let st_1 = { Ast.pos = _position; name = "ST_1"; index } in _test_instruction "st_1 = input 'Enter the amount'" Ast. @@ -121,13 +121,13 @@ let test_command_assignation () = ] let test_assignation2 () = - let index = Some Ast.(Integer (_position, "0")) in + let index = None in let var = { Ast.pos = _position; name = "VALUE"; index } in _test_instruction "set value += 123" Ast.[ Declaration (_position, var, Inc, Integer (_position, "123")) ] let test_multilie_literal () = - let index = Some Ast.(Integer (_position, "0")) in + let index = None in let var = { Ast.pos = _position; name = "VALUE"; index } in _test_instruction {| value = { @@ -150,11 +150,7 @@ let test_nested_literal () = [ Ast.Declaration ( _position, - { - Ast.pos = _position; - name = "VALUE"; - index = Some (Ast.Integer (_position, "0")); - }, + { Ast.pos = _position; name = "VALUE"; index = None }, Qsp_syntax.T.Eq', Ast.Literal (_position, "\n\n {\n\n }\n") ); ] @@ -182,7 +178,7 @@ apples = 5 pears = 10 |} in - let index = Some Ast.(Integer (_position, "0")) in + let index = None in let apples = { Ast.pos = _position; name = "APPLES"; index } and pears = { Ast.pos = _position; name = "PEARS"; index } and value_5 = Ast.Integer (_position, "5") @@ -197,7 +193,7 @@ pears = 10 let test_multiline2 () = let content = "apples = 5 & pears = 10" in - let index = Some Ast.(Integer (_position, "0")) in + let index = None in let apples = { Ast.pos = _position; name = "APPLES"; index } and pears = { Ast.pos = _position; name = "PEARS"; index } and value_5 = Ast.Integer (_position, "5") @@ -210,7 +206,7 @@ let test_multiline2 () = let test_equality () = let content = "apples = 5 = pears" in - let index = Some Ast.(Integer (_position, "0")) in + let index = None in let apples = { Ast.pos = _position; name = "APPLES"; index } and pears = { Ast.pos = _position; name = "PEARS"; index } and value_5 = Ast.Integer (_position, "5") in @@ -224,7 +220,7 @@ let test_plus () = let content = {| apples = 5 + pears |} in - let index = Some Ast.(Integer (_position, "0")) in + let index = None in let apples = { Ast.pos = _position; name = "APPLES"; index } and pears = { Ast.pos = _position; name = "PEARS"; index } and value_5 = Ast.Integer (_position, "5") in @@ -241,7 +237,7 @@ let test_plus_litt () = let content = {| 'five'+ pears |} in - let index = Some Ast.(Integer (_position, "0")) in + let index = None in let pears = { Ast.pos = _position; name = "PEARS"; index } in _test_instruction content [ @@ -254,7 +250,7 @@ let test_concat () = let content = {| $firstName + ' ' + $lastName |} in - let index = Some Ast.(Integer (_position, "0")) in + let index = None in let firstname = { Ast.pos = _position; name = "$FIRSTNAME"; index } and lastName = { Ast.pos = _position; name = "$LASTNAME"; index } and space = Ast.Literal (_position, " ") in @@ -271,7 +267,7 @@ $firstName + ' ' + $lastName let test_comment () = _test_instruction "! Comment" [ Comment _position ] let test_comment2 () = - let index = Some Ast.(Integer (_position, "0")) in + let index = None in let a = { Ast.pos = _position; name = "A"; index } and value_0 = Ast.Integer (_position, "0") in _test_instruction "a = 0 &! Comment" @@ -282,7 +278,7 @@ let test_comment3 () = _test_instruction {|!!1234 (** The exclamation mark here is an operation and not a comment *) let test_comment4 () = - let index = Some Ast.(Integer (_position, "0")) in + let index = None in let a = { Ast.pos = _position; name = "A"; index } and value_0 = Ast.Integer (_position, "0") in _test_instruction "a = rand(0, 1) ! 0" @@ -307,11 +303,7 @@ let test_comment5 () = [ Ast.Declaration ( _position, - { - Ast.pos = _position; - name = "A"; - index = Some (Ast.Integer (_position, "0")); - }, + { Ast.pos = _position; name = "A"; index = None }, Qsp_syntax.T.Eq', Ast.Function (_position, Rand, []) ); Ast.Comment _position; @@ -338,7 +330,7 @@ also count}. This is still the same comment. |} (** This test ensure that the unary operator is applied to the whole expression *) let test_precedence () = - let index = Some Ast.(Integer (_position, "0")) in + let index = None in let x = Ast.Ident { Ast.pos = _position; name = "X"; index } and y = Ast.Ident { Ast.pos = _position; name = "Y"; index } in _test_instruction "no x = y" @@ -347,7 +339,7 @@ let test_precedence () = (** This test ensure that a ! is not considered as a comment in an expression *) let test_precedence2 () = - let index = Some Ast.(Integer (_position, "0")) in + let index = None in let x = { Ast.pos = _position; name = "X"; index } and y = Ast.Ident { Ast.pos = _position; name = "Y"; index } in _test_instruction "x = y ! 0" @@ -501,20 +493,12 @@ let test_if_inline_act () = ( _position, Qsp_syntax.T.Gte, Ast.Ident - { - Ast.pos = _position; - name = "HOUR"; - index = Some (Ast.Integer (_position, "0")); - }, + { Ast.pos = _position; name = "HOUR"; index = None }, Ast.Integer (_position, "8") ) ), [ Ast.Declaration ( _position, - { - Ast.pos = _position; - name = "MINUT"; - index = Some (Ast.Integer (_position, "0")); - }, + { Ast.pos = _position; name = "MINUT"; index = None }, Qsp_syntax.T.Inc, Ast.Integer (_position, "1") ); Ast.Act @@ -591,14 +575,8 @@ let test_gt () = Ast.Call ( _position, "GOTO", - [ - Ast.Ident - { - Ast.pos = _position; - name = "$CURLOC"; - index = Some (Ast.Integer (_position, "0")); - }; - ] ); + [ Ast.Ident { Ast.pos = _position; name = "$CURLOC"; index = None } ] + ); ] let test_nl () = @@ -661,7 +639,7 @@ let test_precedence6 () = (** An identifier cannot start by a number *0 is a product and not an identifier *) let test_operator () = - let index = Some Ast.(Integer (_position, "0")) in + let index = None in let a = { Ast.pos = _position; name = "A"; index } and value_0 = Ast.Integer (_position, "0") in _test_instruction "a *0" -- cgit v1.2.3