-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use arguments to test foreground and background colors
- Loading branch information
1 parent
5983dcf
commit 2396f5e
Showing
4 changed files
with
68 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,44 @@ | ||
@testable import TerminalUI | ||
import TerminalUI | ||
import TerminalUITesting | ||
import Testing | ||
|
||
@Suite("BackgroundColor", .tags(.viewModifier)) | ||
struct BackgroundColorTests { | ||
|
||
@Test("backgroundColor") | ||
func backgroundColor() { | ||
@Test("Text Output", arguments: [ | ||
(Color.`default`, "[49m"), | ||
(Color.black, "[40m"), | ||
(Color.red, "[41m"), | ||
(Color.green, "[42m"), | ||
(Color.yellow, "[43m"), | ||
(Color.blue, "[44m"), | ||
(Color.magenta, "[45m"), | ||
(Color.cyan, "[46m"), | ||
(Color.white, "[47m"), | ||
]) | ||
func textOutput(backgroundColor: Color, expected: String) { | ||
|
||
let text = Text("x") | ||
.backgroundColor(.blue) | ||
let app = TestApp { | ||
Text("a").backgroundColor(backgroundColor) | ||
} | ||
|
||
text.expect([ | ||
Position(x: 1, y: 0): Pixel("x", background: .blue), | ||
let stream = TestStream() | ||
app.run(stream: stream) | ||
|
||
#expect(stream.controlSequences == [ | ||
"[2J", // Clear screen | ||
"[?1049h", // Alternative buffer on | ||
"[?25l", // Cursor visibility off | ||
"[39m", // ForegroundColor default | ||
expected, // BackgroundColor | ||
"[22m", // Bold off | ||
"[23m", // Italic off | ||
"[24m", // Underline off | ||
"[25m", // Blinking off | ||
"[27m", // Inverse off | ||
"[28m", // Hidden off | ||
"[29m", // Strikethrough off | ||
"[0;1Ha", // Position + content | ||
]) | ||
} | ||
} |
40 changes: 33 additions & 7 deletions
40
Tests/TerminalUITests/ViewModifiers/ForegroundColorTests.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,44 @@ | ||
@testable import TerminalUI | ||
import TerminalUI | ||
import TerminalUITesting | ||
import Testing | ||
|
||
@Suite("ForegroundColor", .tags(.viewModifier)) | ||
struct ForegroundColorTests { | ||
|
||
@Test("foregroundColor") | ||
func foregroundColor() { | ||
@Test("Text Output", arguments: [ | ||
(Color.`default`, "[39m"), | ||
(Color.black, "[30m"), | ||
(Color.red, "[31m"), | ||
(Color.green, "[32m"), | ||
(Color.yellow, "[33m"), | ||
(Color.blue, "[34m"), | ||
(Color.magenta, "[35m"), | ||
(Color.cyan, "[36m"), | ||
(Color.white, "[37m"), | ||
]) | ||
func textOutput(foregroundColor: Color, expected: String) { | ||
|
||
let text = Text("x") | ||
.foregroundColor(.blue) | ||
let app = TestApp { | ||
Text("a").foregroundColor(foregroundColor) | ||
} | ||
|
||
text.expect([ | ||
Position(x: 1, y: 0): Pixel("x", foreground: .blue), | ||
let stream = TestStream() | ||
app.run(stream: stream) | ||
|
||
#expect(stream.controlSequences == [ | ||
"[2J", // Clear screen | ||
"[?1049h", // Alternative buffer on | ||
"[?25l", // Cursor visibility off | ||
expected, // ForegroundColor | ||
"[49m", // BackgroundColor default | ||
"[22m", // Bold off | ||
"[23m", // Italic off | ||
"[24m", // Underline off | ||
"[25m", // Blinking off | ||
"[27m", // Inverse off | ||
"[28m", // Hidden off | ||
"[29m", // Strikethrough off | ||
"[0;1Ha", // Position + content | ||
]) | ||
} | ||
} |