Skip to content

Commit

Permalink
Add tests for SR-14108.
Browse files Browse the repository at this point in the history
  • Loading branch information
YOCKOW committed Jul 14, 2021
1 parent 08979ae commit aa91d36
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions Tests/Foundation/Tests/TestDateFormatter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class TestDateFormatter: XCTestCase {
("test_dateFrom", test_dateFrom),
("test_dateParseAndFormatWithJapaneseCalendar", test_dateParseAndFormatWithJapaneseCalendar),
("test_orderOfPropertySetters", test_orderOfPropertySetters),
("test_copy_sr14108", test_copy_sr14108),
]
}

Expand Down Expand Up @@ -527,4 +528,29 @@ class TestDateFormatter: XCTestCase {
}
}
}

// Confirm that https://bugs.swift.org/browse/SR-14108 is fixed.
func test_copy_sr14108() throws {
let date = Date(timeIntervalSinceReferenceDate: 0)

let original = DateFormatter()
original.timeZone = TimeZone(identifier: DEFAULT_TIMEZONE)
original.locale = Locale(identifier: DEFAULT_LOCALE)
original.dateFormat = "yyyy-MM-dd HH:mm:ss z"
XCTAssertEqual(original.string(from: date), "2001-01-01 00:00:00 GMT")

let copied = try XCTUnwrap(original.copy() as? DateFormatter)
XCTAssertEqual(original.timeZone, copied.timeZone)
XCTAssertEqual(original.locale, copied.locale)
XCTAssertEqual(copied.string(from: date), "2001-01-01 00:00:00 GMT")

copied.timeZone = TimeZone(abbreviation: "JST")
copied.locale = Locale(identifier: "ja_JP")
copied.dateFormat = "yyyy/MM/dd hh:mm:ssxxxxx"

XCTAssertNotEqual(original.timeZone, copied.timeZone)
XCTAssertNotEqual(original.locale, copied.locale)
XCTAssertEqual(original.string(from: date), "2001-01-01 00:00:00 GMT")
XCTAssertEqual(copied.string(from: date), "2001/01/01 09:00:00+09:00")
}
}

0 comments on commit aa91d36

Please sign in to comment.