Ejemplo n.º 1
0
        public void TestMeaninglessParens()
        {
            Hash assigns = Hash.FromAnonymousObject(new { b = "bar", c = "baz" });

            Helper.AssertTemplateResult(" YES ", "{% if a == 'foo' or (b == 'bar' and c == 'baz') or false %} YES {% endif %}", assigns);
        }
Ejemplo n.º 2
0
 public void TestUnexpectedCharactersSilentlyEatLogic()
 {
     Helper.AssertTemplateResult(" YES ", "{% if true && false %} YES {% endif %}");
     Helper.AssertTemplateResult("", "{% if false || true %} YES {% endif %}");
 }
Ejemplo n.º 3
0
 public void TestCSharp_SnakeCaseNotAccepted()
 {
     Helper.AssertTemplateResult("Liquid error: Unknown operator starts_with", "{% if 'bob' starts_with 'B' %} YES {% endif %}", null, new CSharpNamingConvention());
 }
Ejemplo n.º 4
0
 public void TestCSharp_LowerPascalCaseAccepted()
 {
     Helper.AssertTemplateResult("", "{% if 'bob' startsWith 'B' %} YES {% endif %}", null, new CSharpNamingConvention());
     Helper.AssertTemplateResult(" YES ", "{% if 'Bob' startsWith 'B' %} YES {% endif %}", null, new CSharpNamingConvention());
 }
Ejemplo n.º 5
0
 public void TestRuby_PascalCaseNotAccepted()
 {
     Helper.AssertTemplateResult("Liquid error: Unknown operator StartsWith", "{% if 'bob' StartsWith 'B' %} YES {% endif %}");
 }
Ejemplo n.º 6
0
 public void TestRuby_SnakeCaseAccepted()
 {
     Helper.AssertTemplateResult("", "{% if 'bob' starts_with 'B' %} YES {% endif %}");
     Helper.AssertTemplateResult(" YES ", "{% if 'Bob' starts_with 'B' %} YES {% endif %}");
 }
Ejemplo n.º 7
0
        public void TestSimpleVariablesRendering()
        {
            Helper.AssertTemplateResult(
                expected: "string",
                template: "{{context}}",
                localVariables: Hash.FromAnonymousObject(new { context = "string" }));

            Helper.AssertTemplateResult(
                expected: "EscapedCharacter\"",
                template: "{{context}}",
                localVariables: Hash.FromAnonymousObject(new { context = "EscapedCharacter\"" }));

            Helper.AssertTemplateResult(
                expected: "5",
                template: "{{context}}",
                localVariables: Hash.FromAnonymousObject(new { context = 5 }));

            Helper.AssertTemplateResult(
                expected: "5",
                template: "{{context}}",
                localVariables: Hash.FromAnonymousObject(new { context = 5m }));

            Helper.AssertTemplateResult(
                expected: "5",
                template: "{{context}}",
                localVariables: Hash.FromAnonymousObject(new { context = 5.0f }));

            Helper.AssertTemplateResult(
                expected: "5",
                template: "{{context}}",
                localVariables: Hash.FromAnonymousObject(new { context = 5.0 }));

            Helper.AssertTemplateResult(
                expected: "1.00:00:00",
                template: "{{context}}",
                localVariables: Hash.FromAnonymousObject(new { context = TimeSpan.FromDays(1) }));

            Helper.AssertTemplateResult(
                expected: "1/01/0001 12:00:00 AM",
                template: "{{context}}",
                localVariables: Hash.FromAnonymousObject(new { context = DateTime.MinValue }));

            Helper.AssertTemplateResult(
                expected: "10/09/2013 12:10:32 AM +01:00",
                template: "{{context}}",
                localVariables: Hash.FromAnonymousObject(new { context = new DateTimeOffset(2013, 9, 10, 0, 10, 32, new TimeSpan(1, 0, 0)) }));

            Helper.AssertTemplateResult(
                expected: "d0f28a51-9393-4658-af0b-8c4b4c5c31ff",
                template: "{{context}}",
                localVariables: Hash.FromAnonymousObject(new { context = new Guid("{D0F28A51-9393-4658-AF0B-8C4B4C5C31FF}") }));

            Helper.AssertTemplateResult(
                expected: "true",
                template: "{{context}}",
                localVariables: Hash.FromAnonymousObject(new { context = true }));

            Helper.AssertTemplateResult(
                expected: "false",
                template: "{{context}}",
                localVariables: Hash.FromAnonymousObject(new { context = false }));

            Helper.AssertTemplateResult(
                expected: "",
                template: "{{context}}",
                localVariables: Hash.FromAnonymousObject(new { context = null as string }));
        }