-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathNaiveDateFormatStyleTests.swift
More file actions
84 lines (62 loc) · 3.05 KB
/
NaiveDateFormatStyleTests.swift
File metadata and controls
84 lines (62 loc) · 3.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import Foundation
import Testing
import NaiveDate
@Suite
struct NaiveDateFormatStyleTests {
@Test
func formattedNaiveDateAgainstDate_withoutParameters() throws {
let naiveDate = NaiveDate(year: 2024, month: 8, day: 12)
let foundationDate = try #require(Calendar.current.date(from: naiveDate))
let formattedFoundationDate = foundationDate.formatted()
let formattedNaiveDate = naiveDate.formatted()
#expect(formattedNaiveDate == formattedFoundationDate)
}
@Test
func formattedNaiveDateAgainstDate_numeric() throws {
let naiveDate = NaiveDate(year: 2024, month: 8, day: 12)
let foundationDate = try #require(Calendar.current.date(from: naiveDate))
let formattedFoundationDate = foundationDate.formatted(date: .numeric, time: .omitted)
let formattedNaiveDate = naiveDate.formatted(date: .numeric)
#expect(formattedNaiveDate == formattedFoundationDate)
}
@Test
func formattedNaiveDateTimeAgainstDate_withoutParameters() throws {
let naiveDate = NaiveDateTime(date: .init(year: 2024, month: 8, day: 12), time: .init(hour: 5, minute: 3, second: 1))
let foundationDate = try #require(Calendar.current.date(from: naiveDate))
let formattedFoundationDate = foundationDate.formatted()
let formattedNaiveDate = naiveDate.formatted()
#expect(formattedNaiveDate == formattedFoundationDate)
}
@Test
func formattedNaiveDateTimeAgainstDate_numeric() throws {
let naiveDate = NaiveDateTime(date: .init(year: 2024, month: 8, day: 12), time: .init(hour: 5, minute: 3, second: 1))
let foundationDate = try #require(Calendar.current.date(from: naiveDate))
let formattedFoundationDate = foundationDate.formatted(date: .numeric, time: .standard)
let formattedNaiveDate = naiveDate.formatted(date: .numeric, time: .standard)
#expect(formattedNaiveDate == formattedFoundationDate)
}
@Test
func localeSet_naiveDateTime() throws {
let locale = Locale(identifier: "en")
let formatStyle = NaiveDateTime.FormatStyle(date: .long, time: .shortened)
let sut = formatStyle.locale(locale)
let expectedFormatStyle = NaiveDateTime.FormatStyle(date: .long, time: .shortened, locale: locale)
#expect(sut == expectedFormatStyle)
}
@Test
func localeSet_naiveDate() throws {
let locale = Locale(identifier: "en")
let formatStyle = NaiveDate.FormatStyle(date: .long, time: .shortened)
let sut = formatStyle.locale(locale)
let expectedFormatStyle = NaiveDate.FormatStyle(date: .long, time: .shortened, locale: locale)
#expect(sut == expectedFormatStyle)
}
@Test
func localeSet_naiveTime() throws {
let locale = Locale(identifier: "en")
let formatStyle = NaiveTime.FormatStyle(date: .long, time: .shortened)
let sut = formatStyle.locale(locale)
let expectedFormatStyle = NaiveTime.FormatStyle(date: .long, time: .shortened, locale: locale)
#expect(sut == expectedFormatStyle)
}
}