public void Preprocess_ControlBlockAfterIncludedTemplateWithClassFeatureBlock_ReturnsValidCSharpOutput() { string input = InputTemplate_ControlBlockAfterIncludedTemplateWithClassFeatureBlock; DummyHost host = CreateDummyHostForControlBlockAfterIncludedTemplateWithClassFeatureBlockTest(); string expectedOutput = TemplatingEngineHelper.CleanCodeDom(Output_ControlBlockAfterIncludedTemplateWithClassFeatureBlock.Replace("\\n", Environment.NewLine.Replace("\r", "\\r").Replace("\n", "\\n")), "\n"); string output = Preprocess(input, host); Assert.AreEqual(expectedOutput, output, output); }
public void DefaultLanguage() { DummyHost host = new DummyHost(); string template = @"<#= DateTime.Now #>"; ParsedTemplate pt = ParsedTemplate.FromText(template, host); Assert.AreEqual(0, host.Errors.Count); TemplateSettings settings = TemplatingEngine.GetSettings(host, pt); Assert.AreEqual(settings.Language, "C#"); }
DummyHost CreateDummyHostForControlBlockAfterIncludedTemplateWithClassFeatureBlockTest() { DummyHost host = new DummyHost(); string includeTemplateFileName = @"d:\test\IncludedFile.tt"; host.Locations.Add(includeTemplateFileName, includeTemplateFileName); host.Contents.Add(includeTemplateFileName, IncludedTemplate_ControlBlockAfterIncludedTemplate); return(host); }
public void ParseTest() { string tf = "test.input"; ParsedTemplate pt = new ParsedTemplate("test.input"); Tokeniser tk = new Tokeniser(tf, ParseSample1); DummyHost host = new DummyHost(); pt.Parse(host, tk); Assert.AreEqual(0, pt.Errors.Count); var content = new List <TemplateSegment> (pt.Content); var dirs = new List <Directive> (pt.Directives); Assert.AreEqual(1, dirs.Count); Assert.AreEqual(6, content.Count); Assert.AreEqual("template", dirs[0].Name); Assert.AreEqual(1, dirs[0].Attributes.Count); Assert.AreEqual("C#v3.5", dirs[0].Attributes["language"]); Assert.AreEqual(new Location(tf, 1, 1), dirs[0].TagStartLocation); Assert.AreEqual(new Location(tf, 1, 34), dirs[0].EndLocation); Assert.AreEqual("Line One" + Environment.NewLine + "Line Two" + Environment.NewLine, content[0].Text); Assert.AreEqual(Environment.NewLine + "foo" + Environment.NewLine, content[1].Text); Assert.AreEqual("Line Three ", content[2].Text); Assert.AreEqual(" bar ", content[3].Text); Assert.AreEqual(Environment.NewLine + "Line Four" + Environment.NewLine, content[4].Text); Assert.AreEqual(" " + Environment.NewLine + "baz \\#>" + Environment.NewLine, content[5].Text); Assert.AreEqual(SegmentType.Content, content[0].Type); Assert.AreEqual(SegmentType.Block, content[1].Type); Assert.AreEqual(SegmentType.Content, content[2].Type); Assert.AreEqual(SegmentType.Expression, content[3].Type); Assert.AreEqual(SegmentType.Content, content[4].Type); Assert.AreEqual(SegmentType.Helper, content[5].Type); Assert.AreEqual(new Location(tf, 4, 1), content[1].TagStartLocation); Assert.AreEqual(new Location(tf, 7, 12), content[3].TagStartLocation); Assert.AreEqual(new Location(tf, 9, 1), content[5].TagStartLocation); Assert.AreEqual(new Location(tf, 2, 1), content[0].StartLocation); Assert.AreEqual(new Location(tf, 4, 3), content[1].StartLocation); Assert.AreEqual(new Location(tf, 7, 1), content[2].StartLocation); Assert.AreEqual(new Location(tf, 7, 15), content[3].StartLocation); Assert.AreEqual(new Location(tf, 7, 22), content[4].StartLocation); Assert.AreEqual(new Location(tf, 9, 4), content[5].StartLocation); Assert.AreEqual(new Location(tf, 6, 3), content[1].EndLocation); Assert.AreEqual(new Location(tf, 7, 22), content[3].EndLocation); Assert.AreEqual(new Location(tf, 11, 3), content[5].EndLocation); }
//NOTE: we set the newline property on the code generator so that the whole files has matching newlines, // in order to match the newlines in the verbatim code blocks void Generate(string input, string expectedOutput, string newline) { DummyHost host = new DummyHost(); string className = "GeneratedTextTransformation4f504ca0"; string code = GenerateCode(host, input, className, newline); Assert.AreEqual(0, host.Errors.Count); var generated = TemplatingEngineHelper.CleanCodeDom(code, newline); expectedOutput = TemplatingEngineHelper.CleanCodeDom(expectedOutput, newline); Assert.AreEqual(expectedOutput, generated); }
string Preprocess(string input, DummyHost host) { string className = "PreprocessedTemplate"; string classNamespace = "Templating"; string language = null; string[] references = null; TemplatingEngine engine = new TemplatingEngine(); string output = engine.PreprocessTemplate(input, host, className, classNamespace, out language, out references); ReportErrors(host.Errors); if (output != null) { return(TemplatingEngineHelper.CleanCodeDom(output, "\n")); } return(null); }
string Preprocess(string input) { DummyHost host = new DummyHost(); return(Preprocess(input, host)); }