@@ -10,104 +10,88 @@ import XCTest
10
10
11
11
class VideoInfoTest : XCTestCase {
12
12
13
- func testPublishedDate( ) {
14
- let publishedDateFromYT = " 2022-06-10 "
15
- let publishedDateVariationTwo = " 1999-04-30 "
16
- let date = " 2000-01-01 "
17
-
18
- let getYearOfPublishedDate = publishedDateFromYT. formatter ( . year)
19
- let getMonthOfPublishedDate = publishedDateFromYT. formatter ( . month)
20
- let getDateOfPublishedDate = publishedDateFromYT. formatter ( . date)
21
- let getPublishedDate = publishedDateFromYT. formatter ( )
22
-
23
- let getYearOfVariationDate = publishedDateVariationTwo. formatter ( . year)
24
- let getMonthOfVariationDate = publishedDateVariationTwo. formatter ( . month)
25
- let getDateOfVariationDate = publishedDateVariationTwo. formatter ( . date)
26
- let getPublishedVariationDate = publishedDateVariationTwo. formatter ( )
27
-
28
- let getPublishedYearForJan = date. formatter ( . year)
29
- let getPublishedMonthForJan = date. formatter ( . month)
30
- let getPublishedDateForJan = date. formatter ( . date)
31
- let getCombinedDateForJan = date. formatter ( )
32
- let convertedDate = " \( getCombinedDateForJan) \( getPublishedYearForJan) "
33
-
34
- XCTAssertEqual ( getYearOfPublishedDate, " 2022 " )
35
- XCTAssertEqual ( getMonthOfPublishedDate, " Jun " )
36
- XCTAssertEqual ( getDateOfPublishedDate, " 10 " )
37
- XCTAssertEqual ( getPublishedDate, " 10 Jun " )
38
-
39
- XCTAssertEqual ( getYearOfVariationDate, " 1999 " )
40
- XCTAssertEqual ( getMonthOfVariationDate, " Apr " )
41
- XCTAssertEqual ( getDateOfVariationDate, " 30 " )
42
- XCTAssertEqual ( getPublishedVariationDate, " 30 Apr " )
43
-
44
- XCTAssertEqual ( getPublishedYearForJan, " 2000 " )
45
- XCTAssertEqual ( getPublishedMonthForJan, " Jan " )
46
- XCTAssertEqual ( getPublishedDateForJan, " 1 " )
47
- XCTAssertEqual ( getCombinedDateForJan, " 1 Jan " )
48
- XCTAssertEqual ( convertedDate, " 1 Jan 2000 " )
13
+ func testFormattedDate( ) {
14
+ let publishedDateFromYT = " 2022-12-12T07:05:08-08:00 "
15
+ let publishedDateVariationTwo = " 2023-11-25T14:30:00-05:00 "
16
+ let date = " 2021-08-18T10:45:20-03:00 "
17
+ let randomDate = " 2024-04-30T08:15:55+02:00 "
18
+
19
+ // Test cases for the new format (YYYY-MM-DDTHH:MM:SS-TZ)
20
+ XCTAssertEqual ( publishedDateFromYT. formattedDate ( . year) , " 2022 " )
21
+ XCTAssertEqual ( publishedDateFromYT. formattedDate ( . month) , " December " )
22
+ XCTAssertEqual ( publishedDateFromYT. formattedDate ( . date) , " 12 " )
23
+ XCTAssertEqual ( publishedDateFromYT. formattedDate ( ) , " 12 Dec " )
24
+
25
+ XCTAssertEqual ( publishedDateVariationTwo. formattedDate ( . year) , " 2023 " )
26
+ XCTAssertEqual ( publishedDateVariationTwo. formattedDate ( . month) , " November " )
27
+ XCTAssertEqual ( publishedDateVariationTwo. formattedDate ( . date) , " 25 " )
28
+ XCTAssertEqual ( publishedDateVariationTwo. formattedDate ( ) , " 25 Nov " )
29
+
30
+ XCTAssertEqual ( date. formattedDate ( . year) , " 2021 " )
31
+ XCTAssertEqual ( date. formattedDate ( . month) , " August " )
32
+ XCTAssertEqual ( date. formattedDate ( . date) , " 18 " )
33
+ XCTAssertEqual ( date. formattedDate ( ) , " 18 Aug " )
34
+
35
+ XCTAssertEqual ( randomDate. formattedDate ( . year) , " 2024 " )
36
+ XCTAssertEqual ( randomDate. formattedDate ( . month) , " April " )
37
+ XCTAssertEqual ( randomDate. formattedDate ( . date) , " 30 " )
38
+ XCTAssertEqual ( randomDate. formattedDate ( ) , " 30 Apr " )
49
39
}
50
40
51
- func testPublishedDateWithWrongInputs( ) {
52
- let invaildSingleRangeDate = " 20220610 "
53
- let invaildTwoRange = " 2022-06 "
41
+
42
+ func testFormattedDateWithWrongInputs( ) {
43
+ let invalidSingleRangeDate = " 20220610 "
44
+ let invalidTwoRange = " 2022-06 "
54
45
let wrongInput = " applle-marg-wqrq "
55
46
let publishedDateWithTwoCorrectValues = " 2022-06-13fh "
56
- let dateWithInvaildInputs = " 20222-12-12 "
57
- let dateWithInvaildMonthRange = " 20222-126-12 "
58
- let dateWithInvaildDateRange = " 20222-01-64 "
59
-
60
- let getInvaildRangeDateYear = invaildSingleRangeDate. formatter ( . year)
61
- let getInvaildSingleRaneDateMonth = invaildSingleRangeDate. formatter ( . month)
62
- let getInvaildSingleRangeDateDate = invaildSingleRangeDate. formatter ( . date)
63
- let getInvaildSingleRangeDate = invaildSingleRangeDate. formatter ( )
64
-
65
- let getInvaildTwoRangeDateYear = invaildTwoRange. formatter ( . year)
66
- let getInvaildTwoRangeDateMonth = invaildTwoRange. formatter ( . month)
67
- let getInvaildTwoRangeDateDate = invaildTwoRange. formatter ( . date)
68
- let getInvaildTwoRangeDate = invaildTwoRange. formatter ( )
69
-
70
- let getDateWithInvaildInputs = dateWithInvaildInputs. formatter ( . year)
71
- let getMonthWithInvaildInputs = dateWithInvaildInputs. formatter ( . month)
72
- let getYearWithInvaildInputs = dateWithInvaildInputs. formatter ( . date)
73
- let getFullDateWithInvaildInputs = dateWithInvaildInputs. formatter ( )
74
-
75
- XCTAssertEqual ( getInvaildRangeDateYear, " Not Mentioned " )
76
- XCTAssertEqual ( getInvaildSingleRaneDateMonth, " Not Mentioned " )
77
- XCTAssertEqual ( getInvaildSingleRangeDateDate, " Not Mentioned " )
78
- XCTAssertEqual ( getInvaildSingleRangeDate, " Not Mentioned " )
79
-
80
- XCTAssertEqual ( getInvaildTwoRangeDateYear, " Not Mentioned " )
81
- XCTAssertEqual ( getInvaildTwoRangeDateMonth, " Not Mentioned " )
82
- XCTAssertEqual ( getInvaildTwoRangeDateDate, " Not Mentioned " )
83
- XCTAssertEqual ( getInvaildTwoRangeDate, " Not Mentioned " )
84
-
85
- XCTAssertEqual ( wrongInput. formatter ( . year) , " Not Mentioned " )
86
- XCTAssertEqual ( wrongInput. formatter ( . month) , " Not Mentioned " )
87
- XCTAssertEqual ( wrongInput. formatter ( . date) , " Not Mentioned " )
88
- XCTAssertEqual ( wrongInput. formatter ( ) , " Not Mentioned " )
89
-
90
- XCTAssertEqual ( publishedDateWithTwoCorrectValues. formatter ( . year) , " Not Mentioned " )
91
- XCTAssertEqual ( publishedDateWithTwoCorrectValues. formatter ( . month) , " Not Mentioned " )
92
- XCTAssertEqual ( publishedDateWithTwoCorrectValues. formatter ( . date) , " Not Mentioned " )
93
- XCTAssertEqual ( publishedDateWithTwoCorrectValues. formatter ( ) , " Not Mentioned " )
94
-
95
- XCTAssertEqual ( getDateWithInvaildInputs, " Not Mentioned " )
96
- XCTAssertEqual ( getMonthWithInvaildInputs, " Not Mentioned " )
97
- XCTAssertEqual ( getYearWithInvaildInputs, " Not Mentioned " )
98
- XCTAssertEqual ( getFullDateWithInvaildInputs, " Not Mentioned " )
99
-
100
- XCTAssertEqual ( dateWithInvaildMonthRange. formatter ( . year) , " Not Mentioned " )
101
- XCTAssertEqual ( dateWithInvaildMonthRange. formatter ( . month) , " Not Mentioned " )
102
- XCTAssertEqual ( dateWithInvaildMonthRange. formatter ( . date) , " Not Mentioned " )
103
- XCTAssertEqual ( dateWithInvaildMonthRange. formatter ( ) , " Not Mentioned " )
104
-
105
- XCTAssertEqual ( dateWithInvaildDateRange. formatter ( . year) , " Not Mentioned " )
106
- XCTAssertEqual ( dateWithInvaildDateRange. formatter ( . month) , " Not Mentioned " )
107
- XCTAssertEqual ( dateWithInvaildDateRange. formatter ( . date) , " Not Mentioned " )
108
- XCTAssertEqual ( dateWithInvaildDateRange. formatter ( ) , " Not Mentioned " )
47
+ let dateWithInvalidInputs = " 20222-12-12 "
48
+ let dateWithInvalidMonthRange = " 20222-126-12 "
49
+ let dateWithInvalidDateRange = " 20222-01-64 "
50
+
51
+ // Invalid single-range date
52
+ XCTAssertEqual ( invalidSingleRangeDate. formattedDate ( . year) , " N/A " )
53
+ XCTAssertEqual ( invalidSingleRangeDate. formattedDate ( . month) , " N/A " )
54
+ XCTAssertEqual ( invalidSingleRangeDate. formattedDate ( . date) , " N/A " )
55
+ XCTAssertEqual ( invalidSingleRangeDate. formattedDate ( ) , " N/A " )
56
+
57
+ // Invalid two-range date
58
+ XCTAssertEqual ( invalidTwoRange. formattedDate ( . year) , " N/A " )
59
+ XCTAssertEqual ( invalidTwoRange. formattedDate ( . month) , " N/A " )
60
+ XCTAssertEqual ( invalidTwoRange. formattedDate ( . date) , " N/A " )
61
+ XCTAssertEqual ( invalidTwoRange. formattedDate ( ) , " N/A " )
62
+
63
+ // Invalid input
64
+ XCTAssertEqual ( wrongInput. formattedDate ( . year) , " N/A " )
65
+ XCTAssertEqual ( wrongInput. formattedDate ( . month) , " N/A " )
66
+ XCTAssertEqual ( wrongInput. formattedDate ( . date) , " N/A " )
67
+ XCTAssertEqual ( wrongInput. formattedDate ( ) , " N/A " )
68
+
69
+ // Date with mixed valid and invalid characters
70
+ XCTAssertEqual ( publishedDateWithTwoCorrectValues. formattedDate ( . year) , " N/A " )
71
+ XCTAssertEqual ( publishedDateWithTwoCorrectValues. formattedDate ( . month) , " N/A " )
72
+ XCTAssertEqual ( publishedDateWithTwoCorrectValues. formattedDate ( . date) , " N/A " )
73
+ XCTAssertEqual ( publishedDateWithTwoCorrectValues. formattedDate ( ) , " N/A " )
74
+
75
+ // Date with invalid year format
76
+ XCTAssertEqual ( dateWithInvalidInputs. formattedDate ( . year) , " N/A " )
77
+ XCTAssertEqual ( dateWithInvalidInputs. formattedDate ( . month) , " N/A " )
78
+ XCTAssertEqual ( dateWithInvalidInputs. formattedDate ( . date) , " N/A " )
79
+ XCTAssertEqual ( dateWithInvalidInputs. formattedDate ( ) , " N/A " )
80
+
81
+ // Date with invalid month range
82
+ XCTAssertEqual ( dateWithInvalidMonthRange. formattedDate ( . year) , " N/A " )
83
+ XCTAssertEqual ( dateWithInvalidMonthRange. formattedDate ( . month) , " N/A " )
84
+ XCTAssertEqual ( dateWithInvalidMonthRange. formattedDate ( . date) , " N/A " )
85
+ XCTAssertEqual ( dateWithInvalidMonthRange. formattedDate ( ) , " N/A " )
86
+
87
+ // Date with invalid date range
88
+ XCTAssertEqual ( dateWithInvalidDateRange. formattedDate ( . year) , " N/A " )
89
+ XCTAssertEqual ( dateWithInvalidDateRange. formattedDate ( . month) , " N/A " )
90
+ XCTAssertEqual ( dateWithInvalidDateRange. formattedDate ( . date) , " N/A " )
91
+ XCTAssertEqual ( dateWithInvalidDateRange. formattedDate ( ) , " N/A " )
109
92
}
110
93
94
+
111
95
func testViewsFormatter( ) {
112
96
let noViews = " 0 "
113
97
let hundredView = " 100 "
0 commit comments