File tree Expand file tree Collapse file tree 2 files changed +39
-0
lines changed
tests/HydraScript.UnitTests/Domain/FrontEnd Expand file tree Collapse file tree 2 files changed +39
-0
lines changed Original file line number Diff line number Diff line change 1+ using HydraScript . Domain . FrontEnd . Parser ;
2+ using HydraScript . Domain . FrontEnd . Parser . Impl . Ast . Nodes . Expressions ;
3+ using HydraScript . Domain . FrontEnd . Parser . Impl . Ast . Nodes . Expressions . PrimaryExpressions ;
4+
15namespace HydraScript . UnitTests . Domain . FrontEnd ;
26
37public sealed class ParserSuccessTestData : TheoryData < string >
@@ -18,4 +22,30 @@ public ParserSuccessTestData()
1822 Add ( "while (~arr != 0) { arr::0 continue }" ) ;
1923 Add ( "if (!(true || (false && false))) { break } else { break }" ) ;
2024 }
25+ }
26+
27+ public sealed class ParserExpectedAstTestData : TheoryData < string , Action < IAbstractSyntaxTree > >
28+ {
29+ public ParserExpectedAstTestData ( )
30+ {
31+ Add (
32+ "$ENV_VAR = \" VALUE\" " ,
33+ ast =>
34+ {
35+ var assignment = ast . Root . GetAllNodes ( ) . OfType < AssignmentExpression > ( ) . Single ( ) ;
36+ assignment . Destination . Id . Should ( ) . BeOfType < EnvVarReference > ( )
37+ . Which . Name . Should ( ) . Be ( "ENV_VAR" ) ;
38+ assignment . Source . Should ( ) . BeOfType < Literal > ( ) ;
39+ } ) ;
40+
41+ Add (
42+ "let envVarValue = $ENV_VAR" ,
43+ ast =>
44+ {
45+ var assignment = ast . Root . GetAllNodes ( ) . OfType < AssignmentExpression > ( ) . Single ( ) ;
46+ assignment . Destination . Id . Name . Should ( ) . Be ( "envVarValue" ) ;
47+ assignment . Source . Should ( ) . BeOfType < EnvVarReference > ( )
48+ . Which . Name . Should ( ) . Be ( "ENV_VAR" ) ;
49+ } ) ;
50+ }
2151}
Original file line number Diff line number Diff line change 11using HydraScript . Domain . FrontEnd . Lexer . Impl ;
2+ using HydraScript . Domain . FrontEnd . Parser ;
23using HydraScript . Domain . FrontEnd . Parser . Impl ;
34
45namespace HydraScript . UnitTests . Domain . FrontEnd ;
@@ -16,4 +17,12 @@ public void Parse_Always_DoesNotThrow(string text)
1617 var ex = Record . Exception ( ( ) => _parser . Parse ( text ) ) ;
1718 Assert . Null ( ex ) ;
1819 }
20+
21+ [ Theory ]
22+ [ ClassData ( typeof ( ParserExpectedAstTestData ) ) ]
23+ public void Parse_Always_Expected ( string text , Action < IAbstractSyntaxTree > assert )
24+ {
25+ var actual = _parser . Parse ( text ) ;
26+ assert ( actual ) ;
27+ }
1928}
You can’t perform that action at this time.
0 commit comments