public string Evaluate(TagModel model) { var id = GetAutoValueAsString(nameof(Name), model); if (id == null) { throw ExpressionParseException.UnexpectedNullValue(nameof(Name)).Decorate(Name.Context); } id = LanguageHelper.CamelCaseAttribute(id); var raw = model.TryGet(id); if (raw == null) { throw MacroException.NotFound(id).Decorate(Name.Context); } var macro = raw as DefineMacroTag.MarcoDefinition; var function = raw as DefineFunctionTag.FunctionDefinition; if (macro == null && function == null) { throw MacroException.NoMacroOrFunction(id).Decorate(Name.Context); } if (macro != null) { return(ExecuteMacro(model, id, macro)); } return(ExecuteFunction(model, function)); }
public void TestTooManyArguments() { try { new ExpressionLib().ParseAndEvaluate("fn:concat('abcd','ef', 'oops one extra')", new Reflection(this)); Assert.Fail("Expected exception"); } catch (ExpressionParseException EPe) { Assert.That(EPe.MessageWithOutContext, Is.EqualTo( ExpressionParseException.UnExpectedParameter(new Constant("oops one extra")).Message)); } }
public void TestNotEnoughArguments() { try { new ExpressionLib().ParseAndEvaluate("fn:concat('abcd')", new Reflection(this)); Assert.Fail("Expected exception"); } catch (ExpressionParseException EPe) { Assert.That(EPe.MessageWithOutContext, Is.EqualTo( ExpressionParseException.ExpectedMoreParameter(new BaseFunctionLib().Obtain("concat"), 1, 2).Message)); } }