castleproject / NVelocity

Castle's NVelocity
Other
57 stars 33 forks source link

Surrounding #else directive with curly brackets gives wrong result #15

Open petrhorny opened 5 years ago

petrhorny commented 5 years ago

According to http://velocity.apache.org/engine/devel/user-guide.html#if-elseif-else

When you wish to include text immediately following a #else directive you will need to use curly brackets immediately surrounding the directive to differentiate it from the following text. (Any directive can be delimited by curly brackets, although this is most useful for #else).

But it doesn't work.

var context = new VelocityContext();
var engine = new VelocityEngine();
var sw = new StringWriter();
var template = "#if(1 == 1)it's true!#{else}it's not!#end";
engine.Init();
engine.Evaluate(context, sw, "", template);
var expected = "it's true!";
Assert.AreEqual(expected, sw.ToString()); // <-- fails, actual (wrong) result is "it's true!#{else}it's not!"
jonorossi commented 5 years ago

I'm don't think Velocity had this feature when it was originally ported to become NVelocity over a decade ago.