public async Task TestHyphenatedAssign() { var assigns = Hash.FromDictionary(new Dictionary <string, object> { { "a-b", "1" } }); await Helper.AssertTemplateResultAsync("a-b:1 a-b:2", "a-b:{{a-b}} {%assign a-b = 2 %}a-b:{{a-b}}", assigns); }
public void TestForWithNestedDictionary() { var dictionary = new Dictionary <string, object> { { "People", new Dictionary <string, object> { { "ID1", new Dictionary <string, object> { { "First", "Jane" }, { "Last", "Green" } } }, { "ID2", new Dictionary <string, object> { { "First", "Mike" }, { "Last", "Doe" } } } } } }; // Validate that: // 1) Nested dictionary properties can be accessed with or without specifying Value. // 2) itemName can still be used as an alias for Key. Helper.AssertTemplateResult( expected: "ID1:Jane Green,ID2:Mike Doe,", template: "{% for item in People %}{{ item.itemName }}:{{ item.First }} {{ item.Value.Last }},{%endfor%}", localVariables: Hash.FromDictionary(dictionary), syntax: SyntaxCompatibility.DotLiquid20); }
public void TestHyphenatedAssign() { Hash assigns = Hash.FromDictionary(new Dictionary <string, object> { { "a-b", "1" } }); Helper.AssertTemplateResult("a-b:1 a-b:2", "a-b:{{a-b}} {%assign a-b = 2 %}a-b:{{a-b}}", assigns); }
public void TestNestedDictionaries_DotLiquid22() { var classes = new Dictionary <string, object> { { "Classes", new Dictionary <string, object> { { "C1", new Dictionary <string, object> { { "Name", "English" }, { "Level", "1" }, { "Students", new Dictionary <string, object> { { "ID1", new Dictionary <string, object> { { "First", "Jane" }, { "Last", "Green" } } }, { "ID2", new Dictionary <string, object> { { "First", "Mike" }, { "Last", "Doe" } } } } } } }, { "C2", new Dictionary <string, object> { { "Name", "Maths" }, { "Level", "2" }, { "Students", new Dictionary <string, object> { { "ID3", new Dictionary <string, object> { { "First", "Eric" }, { "Last", "Schmidt" } } }, { "ID4", new Dictionary <string, object> { { "First", "Bruce" }, { "Last", "Banner" } } } } } } } } } }; // Check for-loops, verify that: // - item.Key OR item[0] --> access the Key // - item.Value.property OR item[1].property --> access values of a nested Hash/IDictionary // - Pre 2.2 syntax (item.property> OR item.itemName) is ignored Helper.AssertTemplateResult( expected: @"English 1: Jane Green (ID1), Mike Doe (ID2), Maths 2: Eric Schmidt (ID3), Bruce Banner (ID4), ", template: @"{% for class in Classes %}{{class.Name}}{{class.Value.Name}} {{class.Value.Level}}: {% for student in class.Value.Students %}{{ student[1].First }} {{ student[1].Last }} ({{ student[0] }}), {%endfor%} {%endfor%}", localVariables: Hash.FromDictionary(classes), syntax: SyntaxCompatibility.DotLiquid22); // Check dot notation Helper.AssertTemplateResult( expected: "Eric Schmidt", template: "{{ Classes.C2.Students.ID3.First }} {{ Classes.C2.Students.ID3.Last }}", localVariables: Hash.FromDictionary(classes), syntax: SyntaxCompatibility.DotLiquid22); }
public void TestForWithSingleLevelNestedDictionary() { var dictionary = new Dictionary <string, object> { { "People", new Dictionary <string, object> { { "ID1", "Jane" }, { "ID2", "Mike" } } } }; Helper.AssertTemplateResult("JaneMike", "{% for item in People %}{{ item.Value }}{%endfor%}", Hash.FromDictionary(dictionary)); }
public void TestForWithNestedDictionary() { var dictionary = new Dictionary <string, object> { { "People", new Dictionary <string, object> { { "ID1", new Dictionary <string, object> { { "First", "Jane" }, { "Last", "Green" } } }, { "ID2", new Dictionary <string, object> { { "First", "Mike" }, { "Last", "Doe" } } } } } }; Helper.AssertTemplateResult("JaneMike", "{% for item in People %}{{ item.First }}{%endfor%}", Hash.FromDictionary(dictionary)); }