public void LineWithTextTwice() { JSBuilder builder = new JSBuilder(); builder.Line("Hello"); builder.Line("World"); Assert.AreEqual("Hello\nWorld", 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); }
private void SetCurrentState(State newState) { if (currentState == State.Start) { builder.Line("/**"); builder.AddToPrefix(" * "); } currentState = newState; }
private void SetCurrentState(State newState) { switch (currentState) { case State.PropertyDeclaration: builder.Line(); break; case State.Method: builder.Line(); break; } currentState = newState; }
private void SetCurrentState(State newState) { switch (currentState) { case State.Start: builder.Line(); break; case State.Element: builder.Line(","); break; default: throw new Exception($"Unrecognized current state: {currentState}"); } currentState = newState; }
public void LineWithNull() { JSBuilder builder = new JSBuilder(); builder.Line(null); Assert.AreEqual("", builder.ToString()); Assert.IsTrue(builder.WriteNewLineBeforeNextText); }
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()); }
/// <summary> /// Set the current state of this JSObject. Changing the state may add "\n" or ",\n". /// </summary> /// <param name="value"></param> private void SetCurrentState(State value) { switch (currentState) { case State.Start: builder.Line(); break; case State.LineComment: case State.BlockComment: break; case State.Property: builder.Line(","); break; default: throw new Exception($"Unrecognized current state: {currentState}"); } currentState = value; }
public void IfWithLineAfterwards() { JSBuilder builder = new JSBuilder(); builder.If("true", ifBlock => { }); builder.Line("Test"); AssertEx.EqualLines( new[] { "if (true) {", "}", "Test" }, builder); Assert.IsTrue(builder.WriteNewLineBeforeNextText); }
public void Line() { builder.Line(); }