@@ -58,6 +58,11 @@ final class GenerativeModelTests: XCTestCase {
5858 ] . sorted ( )
5959 let testModelResourceName =
6060 " projects/test-project-id/locations/test-location/publishers/google/models/test-model "
61+ let dateFormatter = {
62+ let dateFormatter = DateFormatter ( )
63+ dateFormatter. dateFormat = " yyyy-MM-dd "
64+ return dateFormatter
65+ } ( )
6166
6267 var urlSession : URLSession !
6368 var model : GenerativeModel !
@@ -134,6 +139,7 @@ final class GenerativeModelTests: XCTestCase {
134139 forResource: " unary-success-citations " ,
135140 withExtension: " json "
136141 )
142+ let expectedPublicationDate = try XCTUnwrap ( dateFormatter. date ( from: " 2019-05-10 " ) )
137143
138144 let response = try await model. generateContent ( testPrompt)
139145
@@ -149,8 +155,10 @@ final class GenerativeModelTests: XCTestCase {
149155 XCTAssertEqual ( citationSource1. endIndex, 128 )
150156 XCTAssertNil ( citationSource1. title)
151157 XCTAssertNil ( citationSource1. license)
158+ XCTAssertNil ( citationSource1. publicationDate)
152159 let citationSource2 = try XCTUnwrap ( citationMetadata. citations [ 1 ] )
153160 XCTAssertEqual ( citationSource2. title, " some-citation-2 " )
161+ XCTAssertEqual ( citationSource2. publicationDate, expectedPublicationDate)
154162 XCTAssertEqual ( citationSource2. startIndex, 130 )
155163 XCTAssertEqual ( citationSource2. endIndex, 265 )
156164 XCTAssertNil ( citationSource2. uri)
@@ -161,6 +169,7 @@ final class GenerativeModelTests: XCTestCase {
161169 XCTAssertEqual ( citationSource3. endIndex, 431 )
162170 XCTAssertEqual ( citationSource3. license, " mit " )
163171 XCTAssertNil ( citationSource3. title)
172+ XCTAssertNil ( citationSource3. publicationDate)
164173 }
165174
166175 func testGenerateContent_success_quoteReply( ) async throws {
@@ -1052,6 +1061,7 @@ final class GenerativeModelTests: XCTestCase {
10521061 forResource: " streaming-success-citations " ,
10531062 withExtension: " txt "
10541063 )
1064+ let expectedPublicationDate = try XCTUnwrap ( dateFormatter. date ( from: " 2014-03-30 " ) )
10551065
10561066 let stream = try model. generateContentStream ( " Hi " )
10571067 var citations = [ Citation] ( )
@@ -1072,18 +1082,19 @@ final class GenerativeModelTests: XCTestCase {
10721082 . contains {
10731083 $0. startIndex == 0 && $0. endIndex == 128
10741084 && $0. uri == " https://www.example.com/some-citation-1 " && $0. title == nil
1075- && $0. license == nil
1085+ && $0. license == nil && $0 . publicationDate == nil
10761086 } )
10771087 XCTAssertTrue ( citations
10781088 . contains {
10791089 $0. startIndex == 130 && $0. endIndex == 265 && $0. uri == nil
10801090 && $0. title == " some-citation-2 " && $0. license == nil
1091+ && $0. publicationDate == expectedPublicationDate
10811092 } )
10821093 XCTAssertTrue ( citations
10831094 . contains {
10841095 $0. startIndex == 272 && $0. endIndex == 431
10851096 && $0. uri == " https://www.example.com/some-citation-3 " && $0. title == nil
1086- && $0. license == " mit "
1097+ && $0. license == " mit " && $0 . publicationDate == nil
10871098 } )
10881099 XCTAssertFalse ( citations. contains { $0. uri? . isEmpty ?? false } )
10891100 XCTAssertFalse ( citations. contains { $0. title? . isEmpty ?? false } )
0 commit comments