Пример #1
0
        public void LineWithText()
        {
            TSBuilder builder = new TSBuilder();

            builder.Line("Hello");
            Assert.AreEqual("Hello", builder.ToString());
            Assert.IsTrue(builder.WriteNewLineBeforeNextText);
        }
Пример #2
0
        public void LineWithNoArguments()
        {
            TSBuilder builder = new TSBuilder();

            builder.Line();
            Assert.AreEqual("", builder.ToString());
            Assert.IsTrue(builder.WriteNewLineBeforeNextText);
        }
Пример #3
0
        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;
        }
Пример #4
0
 public void ObjectType(Action <TSObjectType> objectTypeAction)
 {
     SetCurrentState(State.TypeDeclaration);
     builder.Line("{");
     builder.IncreaseIndent();
     objectTypeAction?.Invoke(new TSObjectType(builder));
     builder.DecreaseIndent();
     builder.Text("}");
 }
Пример #5
0
        public void IfBlockWithSurroundingEmptyLines()
        {
            TSBuilder builder = new TSBuilder();

            builder.Line();
            builder.If("true", ifBlock =>
            {
            });
            builder.Line();
            AssertEx.EqualLines(
                new[]
            {
                "",
                "if (true) {",
                "}",
                ""
            },
                builder.ToString());
        }
Пример #6
0
        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());
        }
Пример #7
0
        /// <summary>
        /// Set the current state of this TSObject. 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;
        }
Пример #8
0
        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);
        }
Пример #9
0
 public void Line()
 {
     builder.Line();
 }