public void IsEmptyArray(string code, bool emptyArray, bool expected) { var ctx = SdmapCompilerContext.CreateEmpty(); var func = CompileExpression(code, ctx); var actual = func(ctx, new { A = emptyArray ? new int[] { } : new[] { 1 } }); Assert.Equal(expected, actual); }
public void IsNullTest(string propValue, string op, bool expected) { var ctx = SdmapCompilerContext.CreateEmpty(); var func = CompileExpression($"A {op}", ctx); var result = func(new OneCallContext(ctx, new { A = propValue })); Assert.Equal(expected, result); }
public void InputNullWillBeEmpty() { string val = null; var actual = CommonMacros.Val(SdmapCompilerContext.CreateEmpty(), "", val, null); Assert.True(actual.IsSuccess); Assert.Equal(string.Empty, actual.Value); }
public void ScalarTest(bool expected) { var ctx = SdmapCompilerContext.CreateEmpty(); var func = CompileExpression("A", ctx); var actual = func(new OneCallContext(ctx, new { A = expected })); Assert.Equal(expected, actual); }
public void BraceTest() { var ctx = SdmapCompilerContext.CreateEmpty(); var func = CompileExpression("(A)", ctx); var actual = func(new OneCallContext(ctx, new { A = true })); Assert.Equal(true, actual); }
public void HelloWorld() { var val = "Hello World"; var actual = CommonMacros.Val(SdmapCompilerContext.CreateEmpty(), "", val, null); Assert.True(actual.IsSuccess); Assert.Equal(val, actual.Value); }
public void LiteralTest(string input, bool expected) { var ctx = SdmapCompilerContext.CreateEmpty(); var func = CompileExpression(input, ctx); var actual = func(ctx, null); Assert.Equal(expected, actual); }
public void NsSyntax2Test() { var ctx = SdmapCompilerContext.CreateEmpty(); var func = CompileExpression("A.B", ctx); var actual = func(new OneCallContext(ctx, new { A = new { B = true } })); Assert.Equal(true, actual); }
public void NsSyntax4Test() { var ctx = SdmapCompilerContext.CreateEmpty(); var func = CompileExpression("A.B.C.D", ctx); var actual = func(ctx, new { A = new { B = new { C = new { D = false } } } }); Assert.Equal(false, actual); }
public void IsNotEmptyTest() { var ctx = SdmapCompilerContext.CreateEmpty(); var func = CompileExpression("isNotEmpty(A)", ctx); var actual = func(ctx, new { A = new[] { 1 } }); Assert.Equal(true, actual); }
public void IsEmptyString(string code, string value, bool expected) { var ctx = SdmapCompilerContext.CreateEmpty(); var func = CompileExpression(code, ctx); var actual = func(new OneCallContext(ctx, new { A = value })); Assert.Equal(expected, actual); }
public void AndTest(string code, bool expected) { var ctx = SdmapCompilerContext.CreateEmpty(); var func = CompileExpression(code, ctx); var actual = func(new OneCallContext(ctx, null)); Assert.Equal(expected, actual); }
public void NotExistPropShouldFail() { var val = CommonMacros.Iif(SdmapCompilerContext.CreateEmpty(), "", new { A = new bool?() }, new object[] { "B", "true", "false" }); Assert.False(val.IsSuccess); }
public void EmptyNullShouldTreatFalsy() { var val = CommonMacros.Iif(SdmapCompilerContext.CreateEmpty(), "", new { A = new bool?() }, new object[] { "A", "true", "false" }); Assert.True(val.IsSuccess); Assert.Equal("false", val.Value); }
public void Smoke() { var val = CommonMacros.Iif(SdmapCompilerContext.CreateEmpty(), "", new { A = true }, new object[] { "A", "true", "false" }); Assert.True(val.IsSuccess); Assert.Equal("true", val.Value); }
public void ValueIsNotEmpty() { var val = CommonMacros.IsNotEmpty(SdmapCompilerContext.CreateEmpty(), "", new { A = DateTime.Now }, new object[] { "A", "Ok" }); Assert.True(val.IsSuccess); Assert.Equal("Ok", val.Value); }
public void ReallyCompiled() { var ctx = SdmapCompilerContext.CreateEmpty(); var compiler = new SdmapCompiler(ctx); compiler.AddSourceCode("sql v1{Hello World}"); Assert.True(ctx.Emiters["v1"].Emiter == null); var ok = compiler.EnsureCompiled(); Assert.True(ctx.Emiters["v1"].Emiter != null); }
public void SubsqlCanCompile() { var ctx = SdmapCompilerContext.CreateEmpty(); var compiler = new SdmapCompiler(ctx); compiler.AddSourceCode("sql v1{#isNull<A, sql{test}}"); var ok = compiler.EnsureCompiled(); Assert.True(ok.IsSuccess); Assert.Equal(2, ctx.Emiters.Count); }
public void HelloWorld() { var code = "sql v1{Hello World}"; var parseTree = GetParseTree(code); var result = SqlEmiterUtil.CompileNamed( SdmapCompilerContext.CreateEmpty(), parseTree.namedSql()[0]); Assert.True(result.IsSuccess); var function = result.Value; var output = function(SdmapCompilerContext.CreateEmpty(), null); Assert.Equal("Hello World", output.Value); }
public void OrShortCircuit() { var ctx = SdmapCompilerContext.CreateEmpty(); var func = CompileExpression("A.Value || B.Value", ctx); var obj = new { A = new BoolWithAccessCount(true), B = new BoolWithAccessCount(false) }; var actual = func(new OneCallContext(ctx, obj)); Assert.True(actual); Assert.Equal(0, obj.B.AccessCount); Assert.Equal(1, obj.A.AccessCount); }
public void SqlInNamespaceTest() { var sql = "SELECT * FROM `client_WOReactive`;"; var code = "sql v1{" + sql + "}"; var parseTree = GetParseTree(code); var result = SqlEmiterUtil.CompileNamed( SdmapCompilerContext.CreateEmpty(), parseTree.namedSql()[0]); Assert.True(result.IsSuccess); var function = result.Value; var output = function(SdmapCompilerContext.CreateEmpty(), null); Assert.Equal(sql, output.Value); }
public void MultiLineTest() { var sql = "SELECT \r\n" + " * \r\n" + "FROM \r\n" + " `client_WOReactive`; \r\n"; var code = $"sql v1{{{sql}}}"; var parseTree = GetParseTree(code); var result = SqlEmiterUtil.CompileNamed( SdmapCompilerContext.CreateEmpty(), parseTree.namedSql()[0]); Assert.True(result.IsSuccess); var function = result.Value; var output = function(SdmapCompilerContext.CreateEmpty(), null); Assert.Equal(sql, output.Value); }
private Result <string> CallIterate(object self, string joiner, string text) { return(CommonMacros.Iterate(SdmapCompilerContext.CreateEmpty(), "", self, new object[] { joiner, text })); }
private Result <string> CallEach(object self, string prop, string joiner, string text) { return(CommonMacros.Each(SdmapCompilerContext.CreateEmpty(), "", self, new object[] { prop, joiner, text })); }
public static SqlItemVisitor CreateEmpty() { return(new SqlItemVisitor(SdmapCompilerContext.CreateEmpty())); }
private Result <string> CallHasProp(object self, string prop, string result) { return(CommonMacros.HasProp(SdmapCompilerContext.CreateEmpty(), "", self, new[] { prop, result })); }
private Result <string> CallIsNotLike(object self, string prop, string regex, string result) { return(CommonMacros.IsNotLike(SdmapCompilerContext.CreateEmpty(), "", self, new object[] { prop, regex, result })); }