1010using System . Diagnostics ;
1111using ExtendedSystemObjects ;
1212using Interpreter ;
13+ using Interpreter . ScriptEngine ;
1314using Microsoft . VisualStudio . TestTools . UnitTesting ;
1415
1516namespace InterpreteTests
@@ -45,10 +46,12 @@ public void ParseIfElseClausesSingleIfClauseReturnsOneIfElseObj()
4546 // Act
4647 var result = ConditionalExpressions . ParseIfElseClauses ( input ) ;
4748
48- // Assert
49+ // Assert: only one IfElseObj should exist
50+ Assert . IsNotNull ( result ) ;
4951 Assert . AreEqual ( 1 , result . Count ) ;
5052
51- var ifElseObj = result [ 0 ] ;
53+ // Grab the only object
54+ Assert . IsTrue ( result . TryGetValue ( 0 , out var ifElseObj ) ) ;
5255 Assert . AreEqual ( 0 , ifElseObj . Id ) ;
5356 Assert . AreEqual ( - 1 , ifElseObj . ParentId ) ;
5457 Assert . AreEqual ( 0 , ifElseObj . Position ) ;
@@ -57,34 +60,34 @@ public void ParseIfElseClausesSingleIfClauseReturnsOneIfElseObj()
5760 Assert . IsFalse ( ifElseObj . Nested ) ;
5861 Assert . AreEqual ( "if (condition1) {com1; }" , ifElseObj . Input ) ;
5962
60- foreach ( var value in result )
61- {
62- Trace . WriteLine ( value . ToString ( ) ) ;
63- }
64-
65-
66- var commands = IrtParserCommand . BuildCommand ( input ) ;
67-
68- Trace . WriteLine ( commands . ToString ( ) ) ;
63+ // Output debug info
64+ Trace . WriteLine ( ifElseObj . ToString ( ) ) ;
6965
66+ // Validate commands inside the IfElseObj
7067 var expectedResults = new List < ( int Key , string Category , string Value ) >
7168 {
72- ( 0 , "IF" , "condition1" ) , ( 1 , "COMMAND" , "com1" )
69+ ( 0 , "If_Condition" , "condition1" ) ,
70+ ( 1 , "If" , "com1;" )
7371 } ;
7472
75- //// Assert
76- foreach ( var expected in expectedResults )
73+ foreach ( var ( key , cat , val ) in ifElseObj . Commands )
7774 {
78- var ( key , category , value ) = expected ;
79- //Assert.IsTrue(result.TryGetCategory(key, out var actualCategory));
75+ Trace . WriteLine ( $ "Parsed Command -> Key: { key } , Category: { cat } , Value: { val } " ) ;
76+ }
8077
81- //Assert.AreEqual(category, actualCategory, $"Category mismatch for key {key}");
82- //Assert.IsTrue(result.TryGetValue(key, out var actualValue));
83- //TODO error here
84- //Assert.AreEqual(value, actualValue, $"Value mismatch for key {key}");
78+ foreach ( var ( key , category , value ) in expectedResults )
79+ {
80+ Assert . IsTrue ( ifElseObj . Commands . TryGetCategory ( key , out var actualCategory ) ,
81+ $ "Missing category for key { key } ") ;
82+ Assert . AreEqual ( category , actualCategory , $ "Category mismatch for key { key } ") ;
83+
84+ Assert . IsTrue ( ifElseObj . Commands . TryGetValue ( key , out var actualValue ) ,
85+ $ "Missing value for key { key } ") ;
86+ Assert . AreEqual ( value , actualValue , $ "Value mismatch for key { key } ") ;
8587 }
8688 }
8789
90+
8891 /// <summary>
8992 /// Parses if else clauses single if clause returns correct object.
9093 /// </summary>
@@ -94,13 +97,13 @@ public void ParseIfElseClausesSingleIfClauseReturnsCorrectObject()
9497 const string input = "if (condition) { doSomething(); }" ;
9598 var result = ConditionalExpressions . ParseIfElseClauses ( input ) ;
9699
97- // Assert.AreEqual(3 , result.Count, "There should be one IfElseObj in the result.");
98- // var obj = result[0];
99- // Assert.IsFalse(obj.Else, "The 'Else' flag should be false for an 'if' clause.");
100- // Assert.AreEqual(-1, obj.ParentId, "The ParentId should be -1 for a top-level 'if' clause.");
101- // Assert.AreEqual(0, obj.Layer, "The Layer should be 0 for a top-level 'if' clause.");
102- // Assert.AreEqual(0, obj.Position, "The Position should be 0 for a top-level 'if' clause.");
103- // Assert.AreEqual("if (condition) { doSomething(); }", obj.Input, "The Input string should match.");
100+ Assert . AreEqual ( 1 , result . Count , "There should be one IfElseObj in the result." ) ;
101+ var obj = result [ 0 ] ;
102+ Assert . IsFalse ( obj . Else , "The 'Else' flag should be false for an 'if' clause." ) ;
103+ Assert . AreEqual ( - 1 , obj . ParentId , "The ParentId should be -1 for a top-level 'if' clause." ) ;
104+ Assert . AreEqual ( 0 , obj . Layer , "The Layer should be 0 for a top-level 'if' clause." ) ;
105+ Assert . AreEqual ( 0 , obj . Position , "The Position should be 0 for a top-level 'if' clause." ) ;
106+ Assert . AreEqual ( "if (condition) { doSomething(); }" , obj . Input , "The Input string should match." ) ;
104107 }
105108
106109 /// <summary>
0 commit comments