Exemplo n.º 1
0
        public void TwoIsEmptyWithOr()
        {
            var code = "sql v1{#if(!isEmpty(A) || !isEmpty(B))   {OK}}";
            var rt   = new SdmapCompiler();

            rt.AddSourceCode(code);
            var result1 = rt.Emit("v1", new { A = "", B = "" });
            var result2 = rt.Emit("v1", new { A = new int[0], B = "abc" });
            var result3 = rt.Emit("v1", new { A = "b", B = "b" });

            Assert.Equal("", result1);
            Assert.Equal("OK", result2);
            Assert.Equal("OK", result3);
        }
Exemplo n.º 2
0
        public static string Run(string code, string sqlId, object obj = null)
        {
            var c = new SdmapCompiler();

            c.AddSourceCode(code);
            return(c.Emit(sqlId, obj));
        }
Exemplo n.º 3
0
        public void ReferencedDefDepInMacro()
        {
            var rt = new SdmapCompiler();

            rt.AddSourceCode("sql v1{#def<A, 'A'>#def<B, sql{#deps<A>B}>#isNotNull<B, sql {#deps<B>C}}}");
            string result = rt.Emit("v1", new { B = "" });

            Assert.Equal("ABC", result);
        }
Exemplo n.º 4
0
        public void IncludedDefAlsoWorks()
        {
            var rt = new SdmapCompiler();

            rt.AddSourceCode("sql v1{#include<v2>3#deps<B>} sql v2{1#def<B, '2'>}");
            string result = rt.Emit("v1", null);

            Assert.Equal("123", result);
        }
Exemplo n.º 5
0
        public void DefDepEmitAll()
        {
            var rt = new SdmapCompiler();

            rt.AddSourceCode("sql v1{#def<A, 'A'>#def<B, sql{#deps<A>B}>#deps<B>}");
            string result = rt.Emit("v1", null);

            Assert.Equal("AB", result);
        }
Exemplo n.º 6
0
        public void WillLoadOnEqual(bool load)
        {
            var rt = new SdmapCompiler();

            rt.AddSourceCode("sql v1{#def<A, 'A'>#isEqual<A, true, sql {#deps<A>B}>}");
            string result = rt.Emit("v1", new { A = load });

            Assert.Equal(load ? "AB" : "", result);
        }
Exemplo n.º 7
0
        public void WillKeepsOrder()
        {
            var rt = new SdmapCompiler();

            rt.AddSourceCode("sql v1{#def<C, 'C'>#def<A, 'A'>#def<B, sql{B}>#deps<A,B,C>}");
            string result = rt.Emit("v1", null);

            Assert.Equal("CAB", result);
        }
Exemplo n.º 8
0
        public void Smoke()
        {
            var rt = new SdmapCompiler();

            rt.AddSourceCode("sql v1{#def<id, 'test'>#deps<id>}");
            string result = rt.Emit("v1", null);

            Assert.Equal("test", result);
        }
Exemplo n.º 9
0
        public void YesNo(bool input, string expected)
        {
            var code = "sql v1{#iif<A, 'Yes#', 'No!<>'}";
            var rt   = new SdmapCompiler();

            rt.AddSourceCode(code);
            var result = rt.Emit("v1", new { A = input });

            Assert.Equal(expected, result);
        }
Exemplo n.º 10
0
        public void IncludeSameNs()
        {
            var code1 = "namespace ns{sql v1{#include<v2>#include<v2>} sql v2{v2}}";
            var rt    = new SdmapCompiler();

            rt.AddSourceCode(code1);
            var result = rt.Emit("ns.v1", null);

            Assert.Equal("v2v2", result);
        }
Exemplo n.º 11
0
        public void Include()
        {
            var code = "sql v1{#include<v2>} sql v2{Life is good}";
            var rt   = new SdmapCompiler();

            rt.AddSourceCode(code);
            var result = rt.Emit("v1", null);

            Assert.Equal("Life is good", result);
        }
Exemplo n.º 12
0
        public void IncludeWithSql()
        {
            var code1 = "namespace ns{sql v1{#include<v2>} sql v2{#iif<P, sql{A}, sql{B}>}}";
            var rt    = new SdmapCompiler();

            rt.AddSourceCode(code1);
            var result = rt.Emit("ns.v1", new { P = true });

            Assert.Equal("A", result);
        }
Exemplo n.º 13
0
        public void IifPropTest()
        {
            var code = @"sql v1{#iif<A, #prop<IsTrue>, #prop<IsFalse>>}";
            var rt   = new SdmapCompiler();

            rt.AddSourceCode(code);
            var result = rt.Emit("v1", new { A = true, IsTrue = "A=True", IsFalse = "A=False" });

            Assert.Equal("A=True", result);
        }
Exemplo n.º 14
0
        public void Simple()
        {
            var code = "sql v1{#isEqual<A, true, #prop<B>>}";
            var rt   = new SdmapCompiler();

            rt.AddSourceCode(code);
            var result = rt.Emit("v1", new { A = true, B = "Yes" });

            Assert.Equal("Yes", result);
        }
Exemplo n.º 15
0
        public void isNotEmpty()
        {
            var code = "sql v1{#isNotEmpty<A, sql{@A}>}";
            var rt   = new SdmapCompiler();

            rt.AddSourceCode(code);
            var result = rt.Emit("v1", new { A = "NotEmpty" });

            Assert.Equal("@A", result);
        }
Exemplo n.º 16
0
        public void CanShowDouble()
        {
            var code = "sql v1{#prop<V>}";
            var rt   = new SdmapCompiler();

            rt.AddSourceCode(code);
            var result = rt.Emit("v1", new { V = 3.14 });

            Assert.Equal("3.14", result);
        }
Exemplo n.º 17
0
        public void TrueWillEmit()
        {
            var code = "sql v1{#if(A){HelloWorld}}";
            var rt   = new SdmapCompiler();

            rt.AddSourceCode(code);
            var result = rt.Emit("v1", new { A = true });

            Assert.Equal("HelloWorld", result);
        }
Exemplo n.º 18
0
        public void CanShowValue()
        {
            var code = "sql v1{#val<>}";
            var rt   = new SdmapCompiler();

            rt.AddSourceCode(code);
            var result = rt.Emit("v1", "Hello World");

            Assert.Equal("Hello World", result);
        }
Exemplo n.º 19
0
        public void PropInSubSql()
        {
            var code = "sql v1{#isNotEmpty<A, sql{#prop<A>}>}";
            var rt   = new SdmapCompiler();

            rt.AddSourceCode(code);
            var result = rt.Emit("v1", new { A = "NotEmpty" });

            Assert.Equal("NotEmpty", result);
        }
Exemplo n.º 20
0
        public void IfNotNull()
        {
            var code = "sql v1{#isNotEmpty<A, sql{@A}>}";
            var rt   = new SdmapCompiler();

            rt.AddSourceCode(code);
            var result = rt.Emit("v1", new { A = " " });

            Assert.Equal(string.Empty, result);
        }
Exemplo n.º 21
0
        public void EmptyValueTest()
        {
            var code = "sql v1{#val<>}";
            var rt   = new SdmapCompiler();

            rt.AddSourceCode(code);
            var result = rt.Emit("v1", null);

            Assert.Equal(string.Empty, result);
        }
Exemplo n.º 22
0
        public void CanShowEmpty()
        {
            var code = "namespace v1{sql v1{#prop<V>}}";
            var rt   = new SdmapCompiler();

            rt.AddSourceCode(code);
            var result = rt.Emit("v1.v1", new { V = (int?)null });

            Assert.Equal(string.Empty, result);
        }
Exemplo n.º 23
0
        public void CanShowString()
        {
            var code = "sql v1{#prop<Name>}";
            var rt   = new SdmapCompiler();

            rt.AddSourceCode(code);
            var result = rt.Emit("v1", new { Name = "Hello World" });

            Assert.Equal("Hello World", result);
        }
Exemplo n.º 24
0
        public void IsEqualIntOk()
        {
            var code = "sql v1{#isEqual<A, 3, 'Yes'>}";
            var rt   = new SdmapCompiler();

            rt.AddSourceCode(code);
            var result = rt.Emit("v1", new { A = 3 });

            Assert.Equal("Yes", result);
        }
Exemplo n.º 25
0
        public void FalseWontEmit()
        {
            var code = "sql v1{#if(A){HelloWorld}}";
            var rt   = new SdmapCompiler();

            rt.AddSourceCode(code);
            var result = rt.Emit("v1", new { A = false });

            Assert.Equal("", result);
        }
Exemplo n.º 26
0
        public void IsEqualEnum(FileAccess?enumVal, string literal, bool canEmit)
        {
            var code = $"sql v1{{#isEqual<A, {literal}, 'Yes'>}}";
            var rt   = new SdmapCompiler();

            rt.AddSourceCode(code);
            var result   = rt.Emit("v1", new { A = enumVal });
            var expected = canEmit ? "Yes" : "";

            Assert.Equal(expected, result);
        }
Exemplo n.º 27
0
        public void CanShowDate()
        {
            var code = "sql v1{#prop<V>}";
            var now  = DateTime.Now;
            var rt   = new SdmapCompiler();

            rt.AddSourceCode(code);
            var result = rt.Emit("v1", new { V = now });

            Assert.Equal(now.ToString(), result);
        }
Exemplo n.º 28
0
        public void CanNestNamespaceUsingDot()
        {
            var code =
                "namespace ns1.ns2{sql v1{Hello}}";
            var rt = new SdmapCompiler();

            rt.AddSourceCode(code);
            var result = rt.Emit("ns1.ns2.v1", null);

            Assert.Equal("Hello", result);
        }
Exemplo n.º 29
0
        public void DirectIncludeCanBeProcessed()
        {
            var rt = new SdmapCompiler();

            rt.AddSourceCode(@"
sql v1 {#include<v2>}
sql v2 {#def<K, 'Test'>#deps<K>}");
            string result = rt.Emit("v1", new { A = true });

            Assert.Equal("Test", result);
        }
Exemplo n.º 30
0
        public void CanReferenceOtherInOneNamespace()
        {
            var code =
                "namespace ns{sql v1{1#include<v2>} \r\n" +
                "sql v2{2}}";
            var rt = new SdmapCompiler();

            rt.AddSourceCode(code);
            var result = rt.Emit("ns.v1", new { A = true });

            Assert.Equal("12", result);
        }