public void DefaultSnippet_SimpleDefault_GetsLua()
        {
            var gen  = new DefaultSnippet();
            var lua  = new LuaSkeleton(new Context(), true);
            var code = gen.Convert(lua, "result", new List <IExpression> {
                new Constant("the_default_value"),
                Funcs.Id,
                new Constant("value")
            });

            Assert.Contains("if (result == nil) then\n    result = \"the_default_value\"", code);
        }
        public void ToLua_NestedMapping_Table()
        {
            var mapping = new Mapping(
                new[] { "a" },
                new[]
            {
                new Mapping(new[] { "b" },
                            new[]
                {
                    new Constant(42),
                }
                            )
            }
                );
            var luaPrinter = new LuaSkeleton(new Context(), false);
            var result     = luaPrinter.MappingToLua(mapping);

            Assert.Equal("{\n    a = {\n        b = 42\n    }\n}", result);
        }
        public void ToLua_SimpleMapping_Table()
        {
            var mapping = new Mapping(
                new[] { "a", "b", "c" },
                new[]
            {
                new Constant(5),
                new Constant(6),
                new Constant(7),
            }
                );

            var luaPrinter = new LuaSkeleton(new Context(), false);
            var result     = luaPrinter.MappingToLua(mapping);

            Assert.Equal(
                "{\n    a = 5,\n    b = 6,\n    c = 7\n}"
                , result);
        }
        public void FirstOfSnippet_SimpleFirstOf_GetLua()
        {
            var gen = new FirstMatchOfSnippet();
            var lua = new LuaSkeleton(new Context(), true);

            // FirstMatchOf: [a] -> (Tags -> [a]) -> Tags -> a

            // Order: [string]
            var order = new Constant(new List <IExpression> {
                new Constant("bicycle"),
                new Constant("access")
            });

            // Func: (Tags -> [a])
            var func = new Apply(
                Funcs.StringStringToTags,
                new Mapping(
                    new[] { "bicycle", "access" },
                    new IExpression[] {
                Funcs.Id,
                Funcs.Id
            }
                    )
                );

            var tags = new LuaLiteral(new[] { Typs.Tags }, "tags");

            var code = gen.Convert(lua, "result",
                                   new List <IExpression> {
                order,
                func,
                tags
            }
                                   );

            // First the more general ones!
            Assert.Equal(
                "if (tags[\"access\"] ~= nil) then\n    result = tags[\"access\"]\n    \nend\nif (tags[\"bicycle\"] ~= nil) then\n    result = tags[\"bicycle\"]\n    \nend\n",
                code);
        }