public void Should_Output_Expected_Ansi_For_Markup(string markup, string expected)
            {
                // Given
                var fixture = new AnsiConsoleFixture(ColorSystem.Standard, AnsiSupport.Yes);

                // When
                fixture.Console.Markup(markup);

                // Then
                fixture.Output.ShouldBe(expected);
            }
Beispiel #2
0
            public void Should_Write_Char_With_Format_Provider(AnsiSupport ansi)
            {
                // Given
                var fixture = new AnsiConsoleFixture(ColorSystem.Standard, ansi);

                // When
                fixture.Console.WriteLine(CultureInfo.InvariantCulture, 'P');

                // Then
                fixture.Output.ShouldBe("P" + Environment.NewLine);
            }
            public void Should_Be_Able_To_Escape_Tags(string markup, string expected)
            {
                // Given
                var fixture = new AnsiConsoleFixture(ColorSystem.Standard, AnsiSupport.Yes);

                // When
                fixture.Console.Markup(markup);

                // Then
                fixture.Output.ShouldBe(expected);
            }
Beispiel #4
0
            public void Should_Write_UInt32_With_Format_Provider(AnsiSupport ansi)
            {
                // Given
                var fixture = new AnsiConsoleFixture(ColorSystem.Standard, ansi);

                // When
                fixture.Console.Write(CultureInfo.InvariantCulture, 32U);

                // Then
                fixture.Output.ShouldBe("32");
            }
            public void Should_Throw_If_Encounters_Malformed_Tag(string markup, string expected)
            {
                // Given
                var fixture = new AnsiConsoleFixture(ColorSystem.Standard, AnsiSupport.Yes);

                // When
                var result = Record.Exception(() => fixture.Console.Markup(markup));

                // Then
                result.ShouldBeOfType <InvalidOperationException>()
                .Message.ShouldBe(expected);
            }
            public void Should_Throw_If_Tags_Are_Unbalanced()
            {
                // Given
                var fixture = new AnsiConsoleFixture(ColorSystem.Standard, AnsiSupport.Yes);

                // When
                var result = Record.Exception(() => fixture.Console.Markup("[yellow][blue]Hello[/]"));

                // Then
                result.ShouldBeOfType <InvalidOperationException>()
                .Message.ShouldBe("Unbalanced markup stack. Did you forget to close a tag?");
            }
            public void Should_Throw_If_Encounters_Closing_Tag()
            {
                // Given
                var fixture = new AnsiConsoleFixture(ColorSystem.Standard, AnsiSupport.Yes);

                // When
                var result = Record.Exception(() => fixture.Console.Markup("Hello[/]World"));

                // Then
                result.ShouldBeOfType <InvalidOperationException>()
                .Message.ShouldBe("Encountered closing tag when none was expected near position 5.");
            }
Beispiel #8
0
            public void Should_Reset_Colors_Correctly_After_Line_Break_In_Text()
            {
                // Given
                var fixture = new AnsiConsoleFixture(ColorSystem.Standard, AnsiSupport.Yes);

                // When
                fixture.Console.Background = ConsoleColor.Red;
                fixture.Console.WriteLine("Hello\nWorld");

                // Then
                fixture.Output.NormalizeLineEndings()
                .ShouldBe("Hello\nWorld\n");
            }
Beispiel #9
0
            public void Should_Write_Char_Array_With_Format_Provider(AnsiSupport ansi)
            {
                // Given
                var fixture = new AnsiConsoleFixture(ColorSystem.Standard, ansi);

                // When
                fixture.Console.Write(
                    CultureInfo.InvariantCulture,
                    new[] { 'P', 'a', 't', 'r', 'i', 'k' });

                // Then
                fixture.Output.ShouldBe("Patrik");
            }
Beispiel #10
0
            public void Should_Estimate_TrueColor_To_Nearest_Eight_Bit_Color(bool foreground, string expected)
            {
                // Given
                var fixture = new AnsiConsoleFixture(ColorSystem.EightBit);

                fixture.Console.SetColor(new Color(126, 127, 0), foreground);

                // When
                fixture.Console.Write("Hello");

                // Then
                fixture.Output.ShouldBe(expected);
            }
Beispiel #11
0
            public void Should_Return_Correct_Code_For_Known_Color(bool foreground, string expected)
            {
                // Given
                var fixture = new AnsiConsoleFixture(ColorSystem.EightBit);

                fixture.Console.SetColor(Color.Olive, foreground);

                // When
                fixture.Console.Write("Hello");

                // Then
                fixture.Output.ShouldBe(expected);
            }
Beispiel #12
0
            public void Should_Return_Eight_Bit_Ansi_Code_For_Known_Colors(bool foreground, string expected)
            {
                // Given
                var fixture = new AnsiConsoleFixture(ColorSystem.TrueColor);

                fixture.Console.SetColor(Color.Purple, foreground);

                // When
                fixture.Console.Write("Hello");

                // Then
                fixture.Output.ShouldBe(expected);
            }
Beispiel #13
0
            public void Should_Return_Correct_Code(bool foreground, string expected)
            {
                // Given
                var fixture = new AnsiConsoleFixture(ColorSystem.TrueColor);

                fixture.Console.SetColor(new Color(128, 0, 128), foreground);

                // When
                fixture.Console.Write("Hello");

                // Then
                fixture.Output.ShouldBe(expected);
            }
Beispiel #14
0
        public void Should_Write_Text_With_Multiple_Decorations_Correctly(Decoration decoration, string expected)
        {
            // Given
            var fixture = new AnsiConsoleFixture(ColorSystem.TrueColor);

            fixture.Console.Decoration = decoration;

            // When
            fixture.Console.Write("Hello World");

            // Then
            fixture.Output.ShouldBe(expected);
        }
Beispiel #15
0
            public void Should_Write_Formatted_String_With_Format_Provider(AnsiSupport ansi)
            {
                // Given
                var fixture = new AnsiConsoleFixture(ColorSystem.Standard, ansi);

                // When
                fixture.Console.WriteLine(
                    CultureInfo.InvariantCulture,
                    "Hello {0}! {1}",
                    "World", 32);

                // Then
                fixture.Output.ShouldBe("Hello World! 32" + Environment.NewLine);
            }
Beispiel #16
0
        public void Should_Combine_Decoration_And_Colors()
        {
            // Given
            var fixture = new AnsiConsoleFixture(ColorSystem.Standard);

            fixture.Console.Foreground = Color.RoyalBlue1;
            fixture.Console.Background = Color.NavajoWhite1;
            fixture.Console.Decoration = Decoration.Italic;

            // When
            fixture.Console.Write("Hello");

            // Then
            fixture.Output.ShouldBe("\u001b[3;90;47mHello\u001b[0m");
        }
Beispiel #17
0
        public void Should_Not_Include_Background_If_Set_To_Default_Color()
        {
            // Given
            var fixture = new AnsiConsoleFixture(ColorSystem.Standard);

            fixture.Console.Foreground = Color.RoyalBlue1;
            fixture.Console.Background = Color.Default;
            fixture.Console.Decoration = Decoration.Italic;

            // When
            fixture.Console.Write("Hello");

            // Then
            fixture.Output.ShouldBe("\u001b[3;90mHello\u001b[0m");
        }
Beispiel #18
0
        public void Should_Not_Include_Decoration_If_Set_To_None()
        {
            // Given
            var fixture = new AnsiConsoleFixture(ColorSystem.Standard);

            fixture.Console.Foreground = Color.RoyalBlue1;
            fixture.Console.Background = Color.NavajoWhite1;
            fixture.Console.Decoration = Decoration.None;

            // When
            fixture.Console.Write("Hello");

            // Then
            fixture.Output.ShouldBe("\u001b[90;47mHello\u001b[0m");
        }
Beispiel #19
0
            public void Should_Estimate_TrueColor_To_Nearest_Three_Bit_Color(
                bool foreground,
                byte r, byte g, byte b,
                string expected)
            {
                // Given
                var fixture = new AnsiConsoleFixture(ColorSystem.Legacy);

                fixture.Console.SetColor(new Color(r, g, b), foreground);

                // When
                fixture.Console.Write("Hello");

                // Then
                fixture.Output.ShouldBe(expected);
            }
Beispiel #20
0
            public void Should_Map_TrueColor_To_Nearest_Four_Bit_Color_If_Possible(
                bool foreground,
                byte r, byte g, byte b,
                string expected)
            {
                // Given
                var fixture = new AnsiConsoleFixture(ColorSystem.Standard);

                fixture.Console.SetColor(new Color(r, g, b), foreground);

                // When
                fixture.Console.Write("Hello");

                // Then
                fixture.Output.ShouldBe(expected);
            }