Beispiel #1
0
        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);
        }
Beispiel #2
0
        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);
        }
Beispiel #3
0
        public void InputNullWillBeEmpty()
        {
            string val    = null;
            var    actual = CommonMacros.Val(SdmapCompilerContext.CreateEmpty(), "", val, null);

            Assert.True(actual.IsSuccess);
            Assert.Equal(string.Empty, actual.Value);
        }
Beispiel #4
0
        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);
        }
Beispiel #5
0
        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);
        }
Beispiel #6
0
        public void HelloWorld()
        {
            var val    = "Hello World";
            var actual = CommonMacros.Val(SdmapCompilerContext.CreateEmpty(), "", val, null);

            Assert.True(actual.IsSuccess);
            Assert.Equal(val, actual.Value);
        }
Beispiel #7
0
        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);
        }
Beispiel #8
0
        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);
        }
Beispiel #9
0
        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);
        }
Beispiel #10
0
        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);
        }
Beispiel #11
0
        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);
        }
Beispiel #12
0
        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);
        }
Beispiel #13
0
        public void NotExistPropShouldFail()
        {
            var val = CommonMacros.Iif(SdmapCompilerContext.CreateEmpty(),
                                       "",
                                       new { A = new bool?() },
                                       new object[] { "B", "true", "false" });

            Assert.False(val.IsSuccess);
        }
Beispiel #14
0
        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);
        }
Beispiel #15
0
        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);
        }
Beispiel #16
0
        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);
        }
Beispiel #20
0
        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);
        }
Beispiel #23
0
 private Result <string> CallIterate(object self, string joiner, string text)
 {
     return(CommonMacros.Iterate(SdmapCompilerContext.CreateEmpty(),
                                 "", self, new object[] { joiner, text }));
 }
Beispiel #24
0
 private Result <string> CallEach(object self,
                                  string prop, string joiner, string text)
 {
     return(CommonMacros.Each(SdmapCompilerContext.CreateEmpty(),
                              "", self, new object[] { prop, joiner, text }));
 }
Beispiel #25
0
 public static SqlItemVisitor CreateEmpty()
 {
     return(new SqlItemVisitor(SdmapCompilerContext.CreateEmpty()));
 }
Beispiel #26
0
 private Result <string> CallHasProp(object self, string prop, string result)
 {
     return(CommonMacros.HasProp(SdmapCompilerContext.CreateEmpty(), "", self, new[] { prop, result }));
 }
Beispiel #27
0
 private Result <string> CallIsNotLike(object self,
                                       string prop, string regex, string result)
 {
     return(CommonMacros.IsNotLike(SdmapCompilerContext.CreateEmpty(),
                                   "", self, new object[] { prop, regex, result }));
 }