@@ -12,14 +12,19 @@ public class MissingValueTests
1212 [ TestCase ( "x" , "x" ) ]
1313 [ TestCase ( "d.x" , "x" ) ]
1414 [ TestCase ( "d[x]" , "x" ) ]
15- [ TestCase ( "a.b.c" , "a" ) ]
16- public void It_Should_Display_An_Error_When_Dereferencing_Missing_Value ( String varname , String missingVar )
15+ public void It_Should_Display_An_Error_When_Value_Is_Undefined ( String varname , String missingVar )
1716 {
1817 // Arrange
1918
2019 ITemplateContext ctx = new TemplateContext ( )
2120 . ErrorWhenValueMissing ( ) ;
22- ctx . DefineLocalVariable ( "d" , new LiquidHash ( ) ) ;
21+ ctx . DefineLocalVariable ( "x" , LiquidValue . None ) ;
22+ ctx . DefineLocalVariable ( "d" , new LiquidHash ( )
23+ {
24+ {
25+ "x" , LiquidValue . None
26+ }
27+ } ) ;
2328
2429 // Act
2530 var template = LiquidTemplate . Create ( "Result : {{ " + varname + " }}" ) ;
@@ -32,90 +37,50 @@ public void It_Should_Display_An_Error_When_Dereferencing_Missing_Value(String v
3237 }
3338
3439 [ Test ]
35- [ TestCase ( "e[1]" ) ]
36- [ TestCase ( "e.first" ) ]
37- [ TestCase ( "e.last" ) ]
38- public void It_Should_Display_An_Error_When_Dereferencing_Empty_Array ( String varname )
40+ [ TestCase ( "e[1]" , "1" ) ]
41+ [ TestCase ( "e.first" , "first" ) ]
42+ [ TestCase ( "e.last" , "last" ) ]
43+ public void It_Should_Display_An_Error_When_Array_Value_Is_Undefined ( String varname , String missingVar )
3944 {
4045 // Arrange
4146 ITemplateContext ctx = new TemplateContext ( )
4247 . ErrorWhenValueMissing ( ) ;
43- ctx . DefineLocalVariable ( "e" , new LiquidCollection ( ) ) ;
48+ ctx . DefineLocalVariable ( "e" , new LiquidCollection ( new [ ] { LiquidValue . None , LiquidValue . None , LiquidValue . None } ) ) ;
4449
4550 // Act
4651 //var result = RenderingHelper.RenderTemplate("Result : {{ " + varname + " }}", ctx);
4752 var template = LiquidTemplate . Create ( "Result : {{ " + varname + " }}" ) ;
4853 var result = template . LiquidTemplate . Render ( ctx ) ;
4954
5055 // Assert
51- Assert . That ( result . Result , Is . EqualTo ( "Result : ERROR: cannot dereference empty array" ) ) ;
52-
53- }
54-
55-
56-
57- [ Test ]
58- public void It_Should_Display_Error_When_Dereferencing_Array_With_Non_Int ( )
59- {
60- // Arrange
61- ITemplateContext ctx = new TemplateContext ( )
62- . ErrorWhenValueMissing ( ) ;
63- ctx . DefineLocalVariable ( "e" , new LiquidCollection ( ) ) ;
64-
65- // Act
66- var template = LiquidTemplate . Create ( "Result : {{ e.x }}" ) ;
67- var result = template . LiquidTemplate . Render ( ctx ) ;
68- //var result = RenderingHelper.RenderTemplate("Result : {{ e.x }}", ctx);
69-
70- // Assert
71- Assert . That ( result . Result , Is . StringContaining ( "invalid index: 'x'" ) ) ;
72-
73- }
74-
75- [ Test ]
76- public void It_Should_Display_Error_When_Dereferencing_Primitive_With_Index ( )
77- {
78- // Arrange
79- ITemplateContext ctx = new TemplateContext ( )
80- . ErrorWhenValueMissing ( ) ;
81- ctx . DefineLocalVariable ( "e" , LiquidString . Create ( "Hello" ) ) ;
82-
83- // Act
84- var template = LiquidTemplate . Create ( "Result : {{ e.x }}" ) ;
85- var result = template . LiquidTemplate . Render ( ctx ) ;
86-
87- Assert . That ( result . HasRenderingErrors , Is . True ) ;
88- var errorMessage = String . Join ( "," , result . RenderingErrors . Select ( x => x . Message ) ) ;
89- // Assert
90- Assert . That ( errorMessage , Is . StringContaining ( "invalid string index: 'x'" ) ) ;
56+ Assert . That ( result . Result , Is . EqualTo ( "Result : ERROR: " + missingVar + " is undefined" ) ) ;
9157
9258 }
9359
94-
9560 [ Test ]
9661 [ TestCase ( "x" ) ]
62+ [ TestCase ( "e.first" ) ]
9763 [ TestCase ( "e[1]" ) ]
98- [ TestCase ( "e.x" ) ]
9964 [ TestCase ( "d.x" ) ]
10065 [ TestCase ( "d[x]" ) ]
101- [ TestCase ( "a.b.c" ) ]
102- public void It_Should_Not_Display_An_Error_When_Dereferencing_Missing_Value ( String varname )
66+ public void It_Should_Not_Display_An_Error_When_Values_Are_Missing ( String varname )
10367 {
10468 // Arrange
10569 Console . WriteLine ( varname ) ;
106- TemplateContext ctx = new TemplateContext ( ) ;
107- ctx . DefineLocalVariable ( "e" , new LiquidCollection ( ) ) ;
108- ctx . DefineLocalVariable ( "d" , new LiquidHash ( ) ) ;
70+ ITemplateContext ctx = new TemplateContext ( )
71+ . ErrorWhenVariableMissing ( ) ;
72+ ctx . DefineLocalVariable ( "e" , new LiquidCollection ( new [ ] { LiquidValue . None , LiquidValue . None , LiquidValue . None } ) ) ;
73+ ctx . DefineLocalVariable ( "d" , new LiquidHash ( )
74+ {
75+ { "x" , LiquidValue . None }
76+ } ) ;
77+ ctx . DefineLocalVariable ( "x" , LiquidValue . None ) ;
10978
11079 // Act
11180 var result = RenderingHelper . RenderTemplate ( "Result : {{ " + varname + " }}" , ctx ) ;
11281
11382 // Assert
11483 Assert . That ( result , Is . EqualTo ( "Result : " ) ) ;
115-
11684 }
117-
118-
119-
12085 }
12186}
0 commit comments