Esempio n. 1
0
        private static void RunMustacheSpecs(MustacheSpec.MustacheTest test)
        {
            TemplateLocator testDataTemplateLocator = name =>
            {
                if (test.Partials != null && test.Partials[name] != null)
                {
                    var template = new Template();
                    template.Load(new StringReader(test.Partials[name].ToString()));
                    return template;
                };

                return null;
            };

            var rendered = Render.StringToString(test.Template, test.Example, testDataTemplateLocator);
            Assert.AreEqual(test.Expected, rendered, "JSON object rendering failed for " + test.Description);

            rendered = Render.StringToString(test.Template, test.StronglyTypedExample, testDataTemplateLocator);
            Assert.AreEqual(test.Expected, rendered, "Strongly typed rendering failed for " + test.Description);

            var templ = new Template();
            templ.Load(new StringReader(test.Template));

            if (!test.Name.ToLower().Contains("context miss") &&
                !test.Name.ToLower().Contains("broken chain") &&
                !(test.SpecName == "inverted" && (test.Name == "List" || test.Name == "Context")))
            {
                try
                {
                    var compiledTemplate = templ.Compile(
                    test.StronglyTypedExample != null ? test.StronglyTypedExample.GetType() : typeof(object),
                    testDataTemplateLocator);
                    rendered = compiledTemplate(test.StronglyTypedExample);
                    Assert.AreEqual(test.Expected, rendered, "Compiled Template rendering failed for " + test.Description);
                }
                catch (Nustache.Core.NustacheException ex)
                {
                    if (ex.Message.StartsWith("Unsupported:"))
                    {
                        Assert.Inconclusive(ex.Message);
                    }
                }
            }
            else
            {
                bool gotException = false;
                try
                {
                    var compiledTemplate = templ.Compile(
                        test.StronglyTypedExample != null ? test.StronglyTypedExample.GetType() : typeof(object),
                        testDataTemplateLocator);
                }
                catch (Compilation.CompilationException)
                {
                    gotException = true;
                }

                Assert.IsTrue(gotException, "Expected test to throw a compilation exception for an invalid template");
            }
        }
        public static void Run()
        {
            var specs = new [] { "comments", "delimiters", "interpolation", "inverted", "partials", "sections" };

            foreach (var spec in specs)
            {
                var specDefinition = new MustacheSpec(spec);

                if (specDefinition.StronglyTypedExamples.Children().Any())
                {
                    var generator = new Xamasoft.JsonClassGenerator.JsonClassGenerator();
                    generator.SingleFile = true;
                    generator.TargetFolder = "../../Mustache_Spec/examples/";
                    generator.Namespace = FullTestClassNamespace(spec);
                    generator.MainClass = spec;
                    generator.Example = specDefinition.StronglyTypedExamples.ToString();
                    generator.ExplicitDeserialization = true;
                    generator.GenerateClasses();
                }
            }
        }
Esempio n. 3
0
        public static void Run()
        {
            var specs = new [] { "comments", "delimiters", "interpolation", "inverted", "partials", "sections" };

            foreach (var spec in specs)
            {
                var specDefinition = new MustacheSpec(spec);

                if (specDefinition.StronglyTypedExamples.Children().Any())
                {
                    var generator = new Xamasoft.JsonClassGenerator.JsonClassGenerator();
                    generator.SingleFile              = true;
                    generator.TargetFolder            = "../../Mustache_Spec/examples/";
                    generator.Namespace               = FullTestClassNamespace(spec);
                    generator.MainClass               = spec;
                    generator.Example                 = specDefinition.StronglyTypedExamples.ToString();
                    generator.ExplicitDeserialization = true;
                    generator.GenerateClasses();
                }
            }
        }
Esempio n. 4
0
        private static MustacheSpec.MustacheTest[] GetSpecs(string name)
        {
            var spec = new MustacheSpec(name);

            return spec.MustacheTests.ToArray();
        }
Esempio n. 5
0
 public void Sections(MustacheSpec.MustacheTest test)
 {
     RunMustacheSpecs(test);
 }
Esempio n. 6
0
 public void Partials(MustacheSpec.MustacheTest test)
 {
     RunMustacheSpecs(test);
 }
Esempio n. 7
0
 public void Inverted(MustacheSpec.MustacheTest test)
 {
     RunMustacheSpecs(test);
 }
Esempio n. 8
0
 public void Interpolation(MustacheSpec.MustacheTest test)
 {
     RunMustacheSpecs(test);
 }
Esempio n. 9
0
 public void Comments(MustacheSpec.MustacheTest test)
 {
     RunMustacheSpecs(test);
 }
Esempio n. 10
0
        private static MustacheSpec.MustacheTest[] GetSpecs(string name)
        {
            var spec = new MustacheSpec(name);

            return(spec.MustacheTests.ToArray());
        }