r3c / cottle

Fast, light & extensible template engine for C#

Home Page:https://r3c.github.io/cottle/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Change in nested functions in Cottle version 2.0.1?

Tkael opened this issue · comments

I'm trying to update our Cottle configuration from version 1.6.2 to version 2.0.1 and I'm running into a bit of an issue... there seems to be a change in the way that nested functions are being handled.

        [TestMethod]
        public void TestTemplateConditional()
        {
            var setting = new DocumentConfiguration
            {
                Trimmer = DocumentConfiguration.TrimRepeatedWhitespaces
            };
            var document = Document.CreateDefault("{if value = 1:foo|else:{if value = 2:bar|else:baz}}", setting).DocumentOrThrow;
            var vars = new Dictionary<Value, Value>();

            vars["value"] = 1;
            var result = document.Render(Context.CreateBuiltin(vars));
            Assert.AreEqual("foo", result);

            vars["value"] = 2;
            result = document.Render(Context.CreateBuiltin(vars));
            Assert.AreEqual("bar", result);

            vars["value"] = 3;
            result = document.Render(Context.CreateBuiltin(vars));
            Assert.AreEqual("baz", result);
        }

This test succeeds under Cottle version 1.6.2 but fails under version 2.0.1.

Under version 2.0.1, the test fails on the very first Assert. The value of result is "foobaz" when we except "foo". Please advise?

Hey @Tkael, wow that's a big one! Not only it's a significant regression from 2.0.0, but the unit tests that were supposed to catch this kind of bug were not working properly. I'm both fixing the bug and improving faulty tests in 2.0.2, I hope you won't have issue migrating to this one.

Thank you so much for taking the time reporting this bug and providing a sample!

Let me know if there is anything else I can do to help.

Glad to help and thank you! :-)