Example #1
0
        public void TestSimple()
        {
            TemplateCompareResult compareResult = TemplateHelper.TestTemplate("Test with a include yoyo", "Test with a include {{ include 'yoyo' }}");

            WriteTemplateResult(compareResult);
            Assert.True(compareResult.IsEqual);
        }
Example #2
0
        public void TestArguments()
        {
            TemplateCompareResult compareResult = TemplateHelper.TestTemplate("1 + 2", "{{ include 'arguments' 1 2 }}");

            WriteTemplateResult(compareResult);
            Assert.True(compareResult.IsEqual);
        }
Example #3
0
        public void TestLiquidFor()
        {
            TemplateCompareResult compareResult = TemplateHelper.TestTemplate("for_product: Orange for_product: Banana for_product: Apple for_product: Computer for_product: Mobile Phone for_product: Table for_product: Sofa ", "{% include 'for_product' for products %}", true);

            WriteTemplateResult(compareResult);
            Assert.True(compareResult.IsEqual);
        }
Example #4
0
        public void TestLiquidWithAndArguments()
        {
            TemplateCompareResult compareResult = TemplateHelper.TestTemplate("tada : 1 + yoyo", "{% include 'with_arguments' with 'tada' var1: 1, var2: 'yoyo' %}", true);

            WriteTemplateResult(compareResult);
            Assert.True(compareResult.IsEqual);
        }
Example #5
0
        public void TestLiquidNull()
        {
            TemplateCompareResult compareResult = TemplateHelper.TestTemplate("", "{% include a %}", true);

            WriteTemplateResult(compareResult);
            Assert.True(compareResult.IsEqual);
        }
Example #6
0
        public void TestLiquidWith()
        {
            TemplateCompareResult compareResult = TemplateHelper.TestTemplate("with_product: Orange", "{% include 'with_product' with product %}", true);

            WriteTemplateResult(compareResult);
            Assert.True(compareResult.IsEqual);
        }
Example #7
0
        public void TestRecursiveNested()
        {
            TemplateCompareResult compareResult = TemplateHelper.TestTemplate("56789", "{{ include 'recursive_nested_templates' 5 }}");

            WriteTemplateResult(compareResult);
            Assert.True(compareResult.IsEqual);
        }
Example #8
0
        public void TestNested()
        {
            TemplateCompareResult compareResult = TemplateHelper.TestTemplate("This is a header body This is a body_detail This is a footer", "{{ include 'nested_templates' }}");

            WriteTemplateResult(compareResult);
            Assert.True(compareResult.IsEqual);
        }
Example #9
0
        public void TestProduct()
        {
            TemplateCompareResult compareResult = TemplateHelper.TestTemplate("product: Orange", "{{ include 'product' }}");

            WriteTemplateResult(compareResult);
            Assert.True(compareResult.IsEqual);
        }
Example #10
0
        public void TestSliceAtError()
        {
            TemplateCompareResult compareResult = TemplateHelper.TestTemplate("text(1,11) : error : " + string.Format(SRS.BadFunctionInvokeArgCountMin, "string.slice1", 0, 2),
                                                                              "{{ string.slice1 }}");

            WriteTemplateResult(compareResult);
            Assert.True(compareResult.IsEqual);
        }
Example #11
0
        public void TestSortError()
        {
            TemplateCompareResult compareResult = TemplateHelper.TestTemplate("text(1,19) : error : " + string.Format(SRS.BadFunctionInvokeArgCountMin, "array.sort", 0, 1),
                                                                              "{{ [1,2] || array.sort }}");

            WriteTemplateResult(compareResult);
            Assert.True(compareResult.IsEqual);
        }
Example #12
0
        private bool TestRoundtrip(string inputText, bool isLiquid = false)
        {
            inputText = inputText.Replace("\r\n", "\n");
            TemplateCompareResult compareResult = TemplateHelper.TestTemplate(inputText, inputText, isLiquid, true);

            WriteTemplateResult(compareResult);
            return(compareResult.IsEqual);
        }
Example #13
0
        private void WriteTemplateResult(TemplateCompareResult compareResult)
        {
            if (compareResult.DebugCode != "")
            {
                _output.WriteLine("Debug code: " + compareResult.DebugCode);
            }

            if (compareResult.Tokens != null)
            {
                foreach (string line in compareResult.Tokens)
                {
                    _output.WriteLine(line);
                }
            }

            if (compareResult.VerboseMessage != null)
            {
                foreach (string line in compareResult.VerboseMessage)
                {
                    _output.WriteLine(line);
                }
            }
        }
Example #14
0
        private bool TestFile(string inputName)
        {
            string expectedOutputFile = null;
            string expectedInputFile  = null;

            _output.WriteLine(inputName);
            if (!inputName.EndsWith(".txt"))
            {
                throw new ArgumentException("Template name should end with .txt");
            }
            else
            {
                expectedInputFile  = inputName;
                expectedOutputFile = inputName.Substring(0, inputName.Length - 4) + ".out.txt";
            }

            bool isSupportingExactRoundtrip = true;

            foreach (string item in NotSupportingExactRoundtrip)
            {
                if (inputName.EndsWith(inputName))
                {
                    isSupportingExactRoundtrip = false;
                    break;
                }
            }

            bool isLiquid = inputName.Contains("-liquid-");

            string inputText  = GetEmbedFileContent(GetExecutingAssembly(), expectedInputFile);
            string outputText = GetEmbedFileContent(GetExecutingAssembly(), expectedOutputFile);

            TemplateCompareResult compareResult = TemplateHelper.TestTemplate(outputText, inputText, isLiquid, false, isSupportingExactRoundtrip);

            if (compareResult.DebugCode != "")
            {
                _output.WriteLine("Debug code: " + compareResult.DebugCode);
            }

            if (compareResult.Tokens != null)
            {
                foreach (string line in compareResult.Tokens)
                {
                    _output.WriteLine(line);
                }
            }

            if (compareResult.VerboseMessage != null)
            {
                foreach (string line in compareResult.VerboseMessage)
                {
                    _output.WriteLine(line);
                }
            }

            if (!compareResult.IsEqual)
            {
                _output.WriteLine("[FAILED SCENARIO] " + inputName);

                if (WriteFailureToFile && compareResult.Result != null)
                {
                    string outputFileName = expectedOutputFile.StartsWith(TestAssemblyPrefix)
                        ? expectedOutputFile.StartsWith(TestAssemblyPrefix + "._")
                            ? expectedOutputFile.Substring(TestAssemblyPrefix.Length + 2)
                            : expectedOutputFile.Substring(TestAssemblyPrefix.Length)
                        : expectedOutputFile;

                    string outputPath = Path.Combine(ScenarioResultOutputDirectory, outputFileName);
                    _output.WriteLine($"  --> Write result to {outputPath}");

                    File.WriteAllText(outputPath, compareResult.Result);
                }
            }

            return(compareResult.IsEqual);
        }