Skip to content

[TestJSONEncoder] - testEncodingDate still has an unhandled edge case #23894

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions test/stdlib/TestJSONEncoder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ class TestJSONEncoder : TestJSONEncoderSuper {
/// our precision requests in every case. This bug effects Darwin, FreeBSD, and Linux currently
/// causing this test (which uses the current time) to fail occasionally.
let evalEdgeCase: (Date, Date) -> () = { decodedDate, expectedDate in
if formattedLength(of: decodedDate.timeIntervalSinceReferenceDate) > DBL_DECIMAL_DIG + 2 {
if formattedLength(of: decodedDate.timeIntervalSinceReferenceDate) > DBL_DECIMAL_DIG {
let adjustedTimeIntervalSinceReferenceDate: (Date) -> Double = {
let adjustment = pow(10, Double(DBL_DECIMAL_DIG))
return Double(floor(adjustment * $0.timeIntervalSinceReferenceDate) / adjustment)
Expand Down Expand Up @@ -286,9 +286,15 @@ class TestJSONEncoder : TestJSONEncoderSuper {
}
}

// Test the above `snprintf` edge case evaluation with a known triggering case
let knownBadDate = Date(timeIntervalSinceReferenceDate: 0.0021413276231263384)
localTestRoundTrip(of: TopLevelWrapper(knownBadDate))
// Test the above `snprintf` edge case evaluation with known triggering cases

// Tests the two precision digits larger case
let knownBadDateTwoExtraDigits = Date(timeIntervalSinceReferenceDate: 0.0021413276231263384)
localTestRoundTrip(of: TopLevelWrapper(knownBadDateTwoExtraDigits))

// Tests the one precision digit larger case
let knownBadDateOneExtraDigit = Date(timeIntervalSinceReferenceDate: 576487829.7193049)
localTestRoundTrip(of: TopLevelWrapper(knownBadDateOneExtraDigit))

// We can't encode a top-level Date, so it'll be wrapped in a dictionary.
localTestRoundTrip(of: TopLevelWrapper(Date()))
Expand Down