예제 #1
0
        public void DocumentCommentWithNoContents()
        {
            JSBuilder builder = new JSBuilder();

            builder.DocumentationComment(comment => { });
            Assert.AreEqual("", builder.ToString());
        }
예제 #2
0
        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());
        }
예제 #3
0
        public void InsertNewLine()
        {
            JSBuilder builder = new JSBuilder();

            builder.InsertNewLine(0);
            Assert.AreEqual("\n", builder.ToString());
        }
예제 #4
0
        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());
        }
예제 #5
0
        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());
        }
예제 #6
0
        public void Constructor()
        {
            JSBuilder builder = new JSBuilder();

            Assert.AreEqual("", builder.ToString());
            Assert.IsFalse(builder.WriteNewLineBeforeNextText);
        }
예제 #7
0
        public void InsertWithNoPositions()
        {
            JSBuilder builder = new JSBuilder();

            builder.Insert(0, "abcd");
            Assert.AreEqual("abcd", builder.ToString());
        }
예제 #8
0
        public void TextWithNewLine()
        {
            JSBuilder builder = new JSBuilder();

            builder.Text("\n");
            Assert.AreEqual("\n", builder.ToString());
            Assert.IsFalse(builder.WriteNewLineBeforeNextText);
        }
예제 #9
0
        public void LineWithText()
        {
            JSBuilder builder = new JSBuilder();

            builder.Line("Hello");
            Assert.AreEqual("Hello", builder.ToString());
            Assert.IsTrue(builder.WriteNewLineBeforeNextText);
        }
예제 #10
0
        public void LineWithNoArguments()
        {
            JSBuilder builder = new JSBuilder();

            builder.Line();
            Assert.AreEqual("", builder.ToString());
            Assert.IsTrue(builder.WriteNewLineBeforeNextText);
        }
예제 #11
0
        public void LineWithEmptyTwice()
        {
            JSBuilder builder = new JSBuilder();

            builder.Line("");
            builder.Line("");
            Assert.AreEqual("\n", builder.ToString());
            Assert.IsTrue(builder.WriteNewLineBeforeNextText);
        }
예제 #12
0
        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());
        }
예제 #13
0
        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);
        }
예제 #14
0
        public void IfBlockWithSurroundingEmptyLines()
        {
            JSBuilder builder = new JSBuilder();

            builder.Line();
            builder.If("true", ifBlock =>
            {
            });
            builder.Line();
            AssertEx.EqualLines(
                new[]
            {
                "",
                "if (true) {",
                "}",
                ""
            },
                builder.ToString());
        }
예제 #15
0
        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());
        }
예제 #16
0
        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());
        }