Beispiel #1
0
        public void IfBlockInTryBlock()
        {
            TSBuilder builder = new TSBuilder();

            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());
        }
Beispiel #2
0
        public void ExportInterfaceWithExtendedTypeTwiceWithProperties()
        {
            TSBuilder builder = new TSBuilder();

            builder.ExportInterface("A", "L", tsInterface =>
            {
                tsInterface.Property("y", "number");
            });
            builder.ExportInterface("B", "M", tsInterface =>
            {
                tsInterface.Property("z", "boolean");
            });
            AssertEx.EqualLines(new[]
            {
                "export interface A extends L {",
                "  y: number;",
                "}",
                "export interface B extends M {",
                "  z: boolean;",
                "}"
            },
                                builder);
        }
Beispiel #3
0
        public void DocumentationCommentWithWrappedDescription()
        {
            TSBuilder builder = new TSBuilder(10);

            builder.DocumentationComment(comment =>
            {
                comment.Description("This is my long description that will get wrapped.");
            });
            // The AutoRest WordWrap() function seems to include the trailing newline character in
            // its wordwrap algorithm. " * This is" is 10 characters long, so it shouldn't get
            // wrapped, but AutoRest WordWrap() wraps it.
            AssertEx.EqualLines(
                "/**\n" +
                " * This\n" +
                " * is my\n" +
                " * long\n" +
                " * description\n" +
                " * that\n" +
                " * will\n" +
                " * get\n" +
                " * wrapped.\n" +
                " */",
                builder);
        }
Beispiel #4
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);
        }
Beispiel #5
0
 /// <summary>
 /// Create a new parameter list builder.
 /// </summary>
 /// <param name="builder">The TSBuilder that will be used to collect the generated text.</param>
 public TSParameterList(TSBuilder builder)
 {
     this.builder = builder;
 }
Beispiel #6
0
 public TSClass(TSBuilder builder)
 {
     this.builder = builder;
     currentState = State.Start;
 }
 /// <summary>
 /// Create a new JSON object.
 /// </summary>
 /// <param name="builder">The TSBuilder that this TSObject will emit to.</param>
 public TSObject(TSBuilder builder)
 {
     this.builder = builder;
 }
 public TSInterface(TSBuilder builder)
 {
     this.builder = builder;
 }
Beispiel #9
0
 /// <summary>
 /// Create a new TSValue that will emit to the provided TSBuilder.
 /// </summary>
 /// <param name="builder">The TSBuilder this TSValue will emit to.</param>
 public TSValue(TSBuilder builder)
 {
     this.builder = builder;
 }
 public TSTryBlock(TSBuilder builder)
     : base(builder)
 {
 }
Beispiel #11
0
        public void HasChangedLinesSinceWithZeroIndexAndEmptyBuilder()
        {
            TSBuilder builder = new TSBuilder();

            Assert.IsFalse(builder.HasChangedLinesSince(0));
        }
Beispiel #12
0
 /// <summary>
 /// Create a new TSFile at the provided file path.
 /// </summary>
 /// <param name="filePath">The file path that the TSFile will be created at.</param>
 public TSFile(string filePath)
 {
     FilePath = filePath;
     builder  = new TSBuilder();
 }
 public TSIfBlock(TSBuilder builder)
     : base(builder)
 {
 }
Beispiel #14
0
        public void HasChangedLinesSinceWithNegativeIndexAndEmptyBuilder()
        {
            TSBuilder builder = new TSBuilder();

            Assert.ThrowsException <IndexOutOfRangeException>(() => builder.HasChangedLinesSince(-1));
        }
Beispiel #15
0
 /// <summary>
 /// Create a new export object.
 /// </summary>
 /// <param name="builder">The TSBuilder that this TSExport will emit to.</param>
 public TSExport(TSBuilder builder)
 {
     this.builder = builder;
 }
Beispiel #16
0
 /// <summary>
 /// Create a new JSON array.
 /// </summary>
 /// <param name="builder">The TSBuilder that this TSArray will emit to.</param>
 public TSArray(TSBuilder builder)
 {
     this.builder = builder;
 }
 public TSDocumentationComment(TSBuilder builder, int commentWordWrapWidth)
 {
     this.builder          = builder;
     previousWordWrapWidth = builder.WordWrapWidth;
     builder.WordWrapWidth = commentWordWrapWidth;
 }
 /// <summary>
 /// Create a new TSArgumentList that will emit text to the provided TSBuilder.
 /// </summary>
 /// <param name="builder">The TSBuilder to emit text to.</param>
 public TSArgumentList(TSBuilder builder)
     : base(builder)
 {
     argumentPositions = new List <BuilderPosition>();
 }
Beispiel #19
0
 public TSIntersectionType(TSBuilder builder)
 {
     this.builder = builder;
     currentState = State.Start;
 }
Beispiel #20
0
 public TSObjectType(TSBuilder builder)
 {
     this.builder = builder;
     currentState = State.Start;
 }