Skip to content

Commit b716c73

Browse files
test: Adds a few missing description parser tests
1 parent 75cfce2 commit b716c73

File tree

1 file changed

+57
-0
lines changed

1 file changed

+57
-0
lines changed

Tests/GraphQLTests/LanguageTests/SchemaParserTests.swift

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,63 @@ class SchemaParserTests: XCTestCase {
111111
XCTAssert(result == expected)
112112
}
113113

114+
func testParsesTypeWithDescriptionString() throws {
115+
let doc = try parse(source: """
116+
"Description"
117+
type Hello {
118+
world: String
119+
}
120+
""")
121+
122+
let type = try XCTUnwrap(doc.definitions[0] as? ObjectTypeDefinition)
123+
124+
XCTAssertEqual(
125+
type.description?.value,
126+
"Description"
127+
)
128+
}
129+
130+
func testParsesTypeWithDescriptionMultiLineString() throws {
131+
let doc = try parse(source: #"""
132+
"""
133+
Description
134+
"""
135+
# Even with comments between them
136+
type Hello {
137+
world: String
138+
}
139+
"""#)
140+
141+
let type = try XCTUnwrap(doc.definitions[0] as? ObjectTypeDefinition)
142+
143+
XCTAssertEqual(
144+
type.description?.value,
145+
"Description"
146+
)
147+
}
148+
149+
func testParsesSchemaWithDescriptionMultiLineString() throws {
150+
let doc = try parse(source: """
151+
"Description"
152+
schema {
153+
query: Foo
154+
}
155+
""")
156+
157+
let type = try XCTUnwrap(doc.definitions[0] as? SchemaDefinition)
158+
159+
XCTAssertEqual(
160+
type.description?.value,
161+
"Description"
162+
)
163+
}
164+
165+
func testDescriptionFollowedBySomethingOtherThanTypeSystemDefinitionThrows() throws {
166+
XCTAssertThrowsError(
167+
try parse(source: #""Description" 1"#)
168+
)
169+
}
170+
114171
func testSchemeExtension() throws {
115172
// Based on Apollo Federation example schema: https://github.com/apollographql/apollo-federation-subgraph-compatibility/blob/main/COMPATIBILITY.md#products-schema-to-be-implemented-by-library-maintainers
116173
let source =

0 commit comments

Comments
 (0)