public void NestedElseBlocks() { TSBuilder builder = new TSBuilder(); 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 NestedElseIfBlocks() { TSBuilder builder = new TSBuilder(); 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 IfWithEmptyBlock() { TSBuilder builder = new TSBuilder(); builder.If("true", ifBlock => { }); AssertEx.EqualLines( new[] { "if (true) {", "}" }, builder); Assert.IsTrue(builder.WriteNewLineBeforeNextText); }
public void IfWithLineAfterwards() { TSBuilder builder = new TSBuilder(); builder.If("true", ifBlock => { }); builder.Line("Test"); AssertEx.EqualLines( new[] { "if (true) {", "}", "Test" }, builder); Assert.IsTrue(builder.WriteNewLineBeforeNextText); }
public void NestedIfBlocks() { TSBuilder builder = new TSBuilder(); builder.If("a", ifBlock1 => { Assert.IsTrue(builder.WriteNewLineBeforeNextText); AssertEx.EqualLines( "if (a) {", builder); ifBlock1.If("b", ifBlock2 => { Assert.IsTrue(builder.WriteNewLineBeforeNextText); AssertEx.EqualLines( new[] { "if (a) {", " if (b) {" }, builder); }); Assert.IsTrue(builder.WriteNewLineBeforeNextText); AssertEx.EqualLines( new[] { "if (a) {", " if (b) {", " }" }, builder); }); Assert.IsTrue(builder.WriteNewLineBeforeNextText); AssertEx.EqualLines( new[] { "if (a) {", " if (b) {", " }", "}" }, builder); }
public void IfBlockWithSurroundingEmptyLines() { TSBuilder builder = new TSBuilder(); builder.Line(); builder.If("true", ifBlock => { }); builder.Line(); AssertEx.EqualLines( new[] { "", "if (true) {", "}", "" }, builder.ToString()); }
public void IfBlockWithSurroundingLines() { TSBuilder builder = new TSBuilder(); 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 TryBlockInIfBlock() { TSBuilder builder = new TSBuilder(); builder.If("true", ifBlock => { ifBlock.Try(tryBlock => { }) .Catch("error", catchBlock2 => { }); }); AssertEx.EqualLines( "if (true) {" + Environment.NewLine + " try {" + Environment.NewLine + " } catch (error) {" + Environment.NewLine + " }" + Environment.NewLine + "}", builder.ToString()); }
public void IfElseIfWithTextBlocks() { TSBuilder builder = new TSBuilder(); builder.If("true", ifBlock => { ifBlock.Text("Hello"); }) .ElseIf("false", elseBlock => { elseBlock.Text("World"); }); AssertEx.EqualLines( new[] { "if (true) {", " Hello", "} else if (false) {", " World", "}" }, builder); Assert.IsTrue(builder.WriteNewLineBeforeNextText); }
public TSIfBlock If(string condition, Action <TSBlock> thenAction) { SetCurrentState(State.If); return(builder.If(condition, thenAction)); }