Skip to content

Commit 99a78b5

Browse files
Add regression test for stableDecimalPlaces edge cases
1 parent 19b5c01 commit 99a78b5

1 file changed

Lines changed: 24 additions & 0 deletions

File tree

PikaTests/EditableColorValueTests.swift

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,28 @@ final class EditableColorValueTests: XCTestCase {
2323
// 0...720 is twice the reference span.
2424
XCTAssertEqual(dragUnitsPerPixel(for: 0 ... 720), 2.0)
2525
}
26+
27+
func test_stableDecimalPlaces_noDot_defaultsToTwo() {
28+
XCTAssertEqual(ColorComponentField.stableDecimalPlaces(for: "5"), 2)
29+
}
30+
31+
func test_stableDecimalPlaces_trailingDotNoDigits_clampsUpToTwo() {
32+
XCTAssertEqual(ColorComponentField.stableDecimalPlaces(for: "5."), 2)
33+
}
34+
35+
func test_stableDecimalPlaces_oneDecimal_clampsUpToTwo() {
36+
XCTAssertEqual(ColorComponentField.stableDecimalPlaces(for: "5.1"), 2)
37+
}
38+
39+
func test_stableDecimalPlaces_twoDecimals_keepsTwo() {
40+
XCTAssertEqual(ColorComponentField.stableDecimalPlaces(for: "5.12"), 2)
41+
}
42+
43+
func test_stableDecimalPlaces_fourDecimals_keepsFour() {
44+
XCTAssertEqual(ColorComponentField.stableDecimalPlaces(for: "5.1234"), 4)
45+
}
46+
47+
func test_stableDecimalPlaces_moreThanFourDecimals_clampsDownToFour() {
48+
XCTAssertEqual(ColorComponentField.stableDecimalPlaces(for: "5.123456"), 4)
49+
}
2650
}

0 commit comments

Comments
 (0)