Esempio n. 1
0
        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());
        }
Esempio n. 2
0
        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());
        }
Esempio n. 3
0
        public void IfWithEmptyBlock()
        {
            TSBuilder builder = new TSBuilder();

            builder.If("true", ifBlock => { });
            AssertEx.EqualLines(
                new[]
            {
                "if (true) {",
                "}"
            },
                builder);
            Assert.IsTrue(builder.WriteNewLineBeforeNextText);
        }
Esempio n. 4
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);
        }
Esempio n. 5
0
        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);
        }
Esempio n. 6
0
        public void IfBlockWithSurroundingEmptyLines()
        {
            TSBuilder builder = new TSBuilder();

            builder.Line();
            builder.If("true", ifBlock =>
            {
            });
            builder.Line();
            AssertEx.EqualLines(
                new[]
            {
                "",
                "if (true) {",
                "}",
                ""
            },
                builder.ToString());
        }
Esempio n. 7
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());
        }
Esempio n. 8
0
        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());
        }
Esempio n. 9
0
        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);
        }
Esempio n. 10
0
 public TSIfBlock If(string condition, Action <TSBlock> thenAction)
 {
     SetCurrentState(State.If);
     return(builder.If(condition, thenAction));
 }