public void DocumentCommentWithNoContents() { JSBuilder builder = new JSBuilder(); builder.DocumentationComment(comment => { }); Assert.AreEqual("", builder.ToString()); }
public void NestedElseIfBlocks() { JSBuilder builder = new JSBuilder(); builder.If("a1", ifBlock1 => { ifBlock1.If("b1", ifBlock2 => { }) .ElseIf("b2", elseIfBlock2 => { }); }) .ElseIf("a2", elseIfBlock1 => { });; AssertEx.EqualLines( new[] { "if (a1) {", " if (b1) {", " } else if (b2) {", " }", "} else if (a2) {", "}", }, builder.ToString()); }
public void InsertNewLine() { JSBuilder builder = new JSBuilder(); builder.InsertNewLine(0); Assert.AreEqual("\n", builder.ToString()); }
public void NestedElseBlocks() { JSBuilder builder = new JSBuilder(); builder.If("a", ifBlock1 => { ifBlock1.If("b", ifBlock2 => { }) .Else(elseBlock2 => { }); }) .Else(elseBlock1 => { });; AssertEx.EqualLines( new[] { "if (a) {", " if (b) {", " } else {", " }", "} else {", "}", }, builder.ToString()); }
public void InsertBetweenExistingPositions() { JSBuilder builder = new JSBuilder(); builder.Text("ab"); BuilderPosition p1 = builder.CreatePosition(); builder.Text("cd"); BuilderPosition p2 = builder.CreatePosition(); builder.Text("ef"); Assert.AreEqual(2, p1.CharactersAfterPreviousPosition); Assert.AreEqual(2, p1.GetIndexInBuilder()); Assert.AreEqual(2, p2.CharactersAfterPreviousPosition); Assert.AreEqual(4, p2.GetIndexInBuilder()); builder.Insert(3, "Z"); Assert.AreEqual("abcZdef", builder.ToString()); Assert.AreEqual(2, p1.CharactersAfterPreviousPosition); Assert.AreEqual(2, p1.GetIndexInBuilder()); Assert.AreEqual(3, p2.CharactersAfterPreviousPosition); Assert.AreEqual(5, p2.GetIndexInBuilder()); }
public void Constructor() { JSBuilder builder = new JSBuilder(); Assert.AreEqual("", builder.ToString()); Assert.IsFalse(builder.WriteNewLineBeforeNextText); }
public void InsertWithNoPositions() { JSBuilder builder = new JSBuilder(); builder.Insert(0, "abcd"); Assert.AreEqual("abcd", builder.ToString()); }
public void TextWithNewLine() { JSBuilder builder = new JSBuilder(); builder.Text("\n"); Assert.AreEqual("\n", builder.ToString()); Assert.IsFalse(builder.WriteNewLineBeforeNextText); }
public void LineWithText() { JSBuilder builder = new JSBuilder(); builder.Line("Hello"); Assert.AreEqual("Hello", builder.ToString()); Assert.IsTrue(builder.WriteNewLineBeforeNextText); }
public void LineWithNoArguments() { JSBuilder builder = new JSBuilder(); builder.Line(); Assert.AreEqual("", builder.ToString()); Assert.IsTrue(builder.WriteNewLineBeforeNextText); }
public void LineWithEmptyTwice() { JSBuilder builder = new JSBuilder(); builder.Line(""); builder.Line(""); Assert.AreEqual("\n", builder.ToString()); Assert.IsTrue(builder.WriteNewLineBeforeNextText); }
public void InsertAtAnExistingPosition() { JSBuilder builder = new JSBuilder(); BuilderPosition p = builder.CreatePosition(); builder.Insert(0, "abcd"); Assert.AreEqual("abcd", builder.ToString()); Assert.AreEqual(4, p.CharactersAfterPreviousPosition); Assert.AreEqual(4, p.GetIndexInBuilder()); }
private static string ParameterListActionToString(Action <JSParameterList> parameterListAction) { string parameterListString = null; if (parameterListAction != null) { JSBuilder parameterListBuilder = new JSBuilder(); JSParameterList parameterList = new JSParameterList(parameterListBuilder); parameterListAction(parameterList); parameterListString = parameterListBuilder.ToString(); } return(parameterListString); }
public void IfBlockWithSurroundingEmptyLines() { JSBuilder builder = new JSBuilder(); builder.Line(); builder.If("true", ifBlock => { }); builder.Line(); AssertEx.EqualLines( new[] { "", "if (true) {", "}", "" }, builder.ToString()); }
public void IfBlockWithSurroundingLines() { JSBuilder builder = new JSBuilder(); builder.Line("const x = 5;"); builder.If("true", ifBlock => { }); builder.Line("const y = 6;"); AssertEx.EqualLines( new[] { "const x = 5;", "if (true) {", "}", "const y = 6;" }, builder.ToString()); }
public void IfBlockInTryBlock() { JSBuilder builder = new JSBuilder(); builder.Try(tryBlock => { tryBlock.If("true", ifBlock => { }); }) .Catch("error", catchBlock1 => { }); AssertEx.EqualLines( "try {" + Environment.NewLine + " if (true) {" + Environment.NewLine + " }" + Environment.NewLine + "} catch (error) {" + Environment.NewLine + "}", builder.ToString()); }