@@ -19,4 +19,66 @@ describe('Substitutions', () => {
19
19
} ) ,
20
20
) . toEqual ( 'Hello not_var{{ user.name }}!' ) ;
21
21
} ) ;
22
+
23
+ test ( 'Should return unchanged string if no variables present' , ( ) => {
24
+ const input = 'This is just a string' ;
25
+ expect ( liquid ( input , { } ) ) . toEqual ( input ) ;
26
+ } ) ;
27
+
28
+ test ( 'Should return unchanged string if variable not found in context' , ( ) => {
29
+ const input = 'Variable {{ notFound }} not found' ;
30
+ expect ( liquid ( input , { } ) ) . toEqual ( input ) ;
31
+ } ) ;
32
+
33
+ test ( 'Should substitute multiple occurrences of the same variable' , ( ) => {
34
+ const input = 'Repeated {{ variable }} here and also here: {{ variable }}' ;
35
+ const context = { variable : 'value' } ;
36
+ expect ( liquid ( input , context ) ) . toEqual ( 'Repeated value here and also here: value' ) ;
37
+ } ) ;
38
+
39
+ describe ( 'Should save type of variable, if possible' , ( ) => {
40
+ const string = 'Example' ;
41
+ const number = 10 ;
42
+ const boolean = true ;
43
+ const nullVar = null ;
44
+ const array = [ 'item1' , 'item2' , 'item3' ] ;
45
+ const object = { key1 : 'value1' , key2 : 'value2' } ;
46
+ const undefinedVar = undefined ;
47
+
48
+ test ( 'Should substitute to string' , ( ) => {
49
+ expect ( liquid ( '{{ string }}' , { string} ) ) . toEqual ( string ) ;
50
+ } ) ;
51
+
52
+ test ( 'Should substitute to number' , ( ) => {
53
+ expect ( liquid ( '{{ number }}' , { number} ) ) . toEqual ( number ) ;
54
+ } ) ;
55
+
56
+ test ( 'Should substitute to boolean' , ( ) => {
57
+ expect ( liquid ( '{{ boolean }}' , { boolean} ) ) . toEqual ( boolean ) ;
58
+ } ) ;
59
+
60
+ test ( 'Should substitute to null' , ( ) => {
61
+ expect ( liquid ( '{{ nullVar }}' , { nullVar} ) ) . toEqual ( nullVar ) ;
62
+ } ) ;
63
+
64
+ test ( 'Should substitute to array' , ( ) => {
65
+ expect ( liquid ( '{{ array }}' , { array} ) ) . toEqual ( array ) ;
66
+ } ) ;
67
+
68
+ test ( 'Should substitute to object' , ( ) => {
69
+ expect ( liquid ( '{{ object }}' , { object} ) ) . toEqual ( object ) ;
70
+ } ) ;
71
+
72
+ test ( 'Should not substitute undefined vars' , ( ) => {
73
+ expect ( liquid ( '{{ undefinedVar }}' , { undefinedVar} ) ) . toEqual ( '{{ undefinedVar }}' ) ;
74
+ } ) ;
75
+
76
+ test ( 'Should substitute to string if input contains more than one variable' , ( ) => {
77
+ expect ( liquid ( '{{ number }} {{ boolean }}' , { number, boolean} ) ) . toEqual (
78
+ `${ number } ${ boolean } ` ,
79
+ ) ;
80
+
81
+ expect ( liquid ( '{{ number }} postfix' , { number} ) ) . toEqual ( `${ number } postfix` ) ;
82
+ } ) ;
83
+ } ) ;
22
84
} ) ;
0 commit comments