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(); } } }
private static MustacheSpec.MustacheTest[] GetSpecs(string name) { var spec = new MustacheSpec(name); return spec.MustacheTests.ToArray(); }
public void Sections(MustacheSpec.MustacheTest test) { RunMustacheSpecs(test); }
public void Partials(MustacheSpec.MustacheTest test) { RunMustacheSpecs(test); }
public void Inverted(MustacheSpec.MustacheTest test) { RunMustacheSpecs(test); }
public void Interpolation(MustacheSpec.MustacheTest test) { RunMustacheSpecs(test); }
public void Comments(MustacheSpec.MustacheTest test) { RunMustacheSpecs(test); }
private static MustacheSpec.MustacheTest[] GetSpecs(string name) { var spec = new MustacheSpec(name); return(spec.MustacheTests.ToArray()); }