@@ -9,5 +9,72 @@ import XCTest
99import OpenAPIKit
1010
1111final class ExternalDocTests : XCTestCase {
12- // TODO: write tests
12+ func test_init( ) {
13+ let t1 = OpenAPI . ExternalDoc ( url: URL ( string: " http://google.com " ) !)
14+ XCTAssertNil ( t1. description)
15+
16+ let t2 = OpenAPI . ExternalDoc ( description: " hello world " ,
17+ url: URL ( string: " http://google.com " ) !)
18+ XCTAssertEqual ( t2. description, " hello world " )
19+ }
20+ }
21+
22+ // MARK: - Codable
23+ @available ( OSX 10 . 13 , * )
24+ extension ExternalDocTests {
25+ func test_descriptionAndUrl_encode( ) {
26+ let externalDoc = OpenAPI . ExternalDoc ( description: " hello world " ,
27+ url: URL ( string: " http://google.com " ) !)
28+
29+ let encodedExternalDoc = try ! testStringFromEncoding ( of: externalDoc)
30+
31+ XCTAssertEqual ( encodedExternalDoc,
32+ """
33+ {
34+ " description " : " hello world " ,
35+ " url " : " http: \\ / \\ /google.com "
36+ }
37+ """
38+ )
39+ }
40+
41+ func test_descriptionAndUrl_decode( ) {
42+ let externalDocsData =
43+ """
44+ {
45+ " description " : " hello world " ,
46+ " url " : " http: \\ / \\ /google.com "
47+ }
48+ """ . data ( using: . utf8) !
49+ let externalDocs = try ! testDecoder. decode ( OpenAPI . ExternalDoc. self, from: externalDocsData)
50+
51+ XCTAssertEqual ( externalDocs, OpenAPI . ExternalDoc ( description: " hello world " ,
52+ url: URL ( string: " http://google.com " ) !) )
53+ }
54+
55+ func test_onlyUrl_encode( ) {
56+ let externalDoc = OpenAPI . ExternalDoc ( url: URL ( string: " http://google.com " ) !)
57+
58+ let encodedExternalDoc = try ! testStringFromEncoding ( of: externalDoc)
59+
60+ XCTAssertEqual ( encodedExternalDoc,
61+ """
62+ {
63+ " url " : " http: \\ / \\ /google.com "
64+ }
65+ """
66+ )
67+ }
68+
69+ func test_onlyUrl_decode( ) {
70+ let externalDocsData =
71+ """
72+ {
73+ " url " : " http: \\ / \\ /google.com "
74+ }
75+ """ . data ( using: . utf8) !
76+ let externalDocs = try ! testDecoder. decode ( OpenAPI . ExternalDoc. self, from: externalDocsData)
77+
78+ XCTAssertEqual ( externalDocs, OpenAPI . ExternalDoc ( url: URL ( string: " http://google.com " ) !) )
79+ }
1380}
0 commit comments