-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0838bd1
commit fff8ae0
Showing
3 changed files
with
77 additions
and
4 deletions.
There are no files selected for viewing
File renamed without changes.
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 |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import XCTest | ||
import ThemePark | ||
|
||
struct MockStyler: Styling { | ||
func style(for query: Query) -> Style { | ||
switch query.key { | ||
case .editor(.background), .editor(.accessoryBackground): | ||
return Style(color: .red) | ||
default: | ||
return Style(color: .blue) | ||
} | ||
} | ||
|
||
var supportedVariants: Set<Variant> { | ||
[Variant(colorScheme: .light)] | ||
} | ||
} | ||
|
||
final class CodableStylerTests: XCTestCase { | ||
func testPassthrough() throws { | ||
let mock = MockStyler() | ||
let theme = CodableStyler(mock) | ||
let context = Query.Context(controlState: .active, variant: Variant(colorScheme: .light)) | ||
|
||
XCTAssertEqual( | ||
mock.style(for: .editor(.background), context: context), | ||
theme.style(for: .editor(.background), context: context) | ||
) | ||
|
||
XCTAssertEqual( | ||
mock.style(for: .syntax(.text), context: context), | ||
theme.style(for: .syntax(.text), context: context) | ||
) | ||
} | ||
|
||
func testPassthroughMismatchedVariant() throws { | ||
let mock = MockStyler() | ||
let theme = CodableStyler(mock) | ||
let context = Query.Context(controlState: .active, variant: Variant(colorScheme: .dark)) | ||
|
||
XCTAssertEqual( | ||
mock.style(for: .editor(.background), context: context), | ||
theme.style(for: .editor(.background), context: context) | ||
) | ||
|
||
XCTAssertEqual( | ||
mock.style(for: .syntax(.text), context: context), | ||
theme.style(for: .syntax(.text), context: context) | ||
) | ||
} | ||
|
||
func testEncodedDecodedPassthrough() throws { | ||
let mock = MockStyler() | ||
let theme = CodableStyler(mock) | ||
let context = Query.Context(controlState: .active, variant: Variant(colorScheme: .light)) | ||
|
||
let data = try JSONEncoder().encode(theme) | ||
let decodedTheme = try JSONDecoder().decode(CodableStyler.self, from: data) | ||
|
||
|
||
XCTAssertEqual( | ||
mock.style(for: .editor(.background), context: context), | ||
decodedTheme.style(for: .editor(.background), context: context) | ||
) | ||
|
||
XCTAssertEqual( | ||
mock.style(for: .syntax(.text), context: context), | ||
decodedTheme.style(for: .syntax(.text), context: context) | ||
) | ||
} | ||
} |