Skip to content

Commit f790929

Browse files
authored
Merge pull request #1970 from ahoppen/ahoppen/more-verifications
2 parents 91d33db + 2175db3 commit f790929

File tree

1 file changed

+60
-0
lines changed

1 file changed

+60
-0
lines changed

CodeGeneration/Tests/ValidateSyntaxNodes/ValidateSyntaxNodes.swift

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -700,4 +700,64 @@ class ValidateSyntaxNodes: XCTestCase {
700700
]
701701
)
702702
}
703+
704+
/// Nodes ending with `List` should always be syntax collections
705+
func testNonCollectionNodesShouldntContainList() {
706+
var failures: [ValidationFailure] = []
707+
708+
for node in SYNTAX_NODES.compactMap(\.layoutNode) {
709+
if node.kind.syntaxType.description.contains("List") {
710+
failures.append(
711+
ValidationFailure(
712+
node: node.kind,
713+
message:
714+
"non-collection node should not contain 'List'"
715+
)
716+
)
717+
}
718+
}
719+
720+
assertFailuresMatchXFails(failures, expectedFailures: [])
721+
}
722+
723+
/// Children should always have a plural as their name instead of ending with 'List'.
724+
func testChildrenDontEndWithList() {
725+
var failures: [ValidationFailure] = []
726+
727+
for node in SYNTAX_NODES.compactMap(\.layoutNode) {
728+
for child in node.children {
729+
if child.name.contains("List") {
730+
failures.append(
731+
ValidationFailure(
732+
node: node.kind,
733+
message:
734+
"child '\(child.name)' should not contain 'List'"
735+
)
736+
)
737+
}
738+
}
739+
}
740+
741+
assertFailuresMatchXFails(failures, expectedFailures: [])
742+
}
743+
744+
/// Entry is such an ambiguous term that we shouldn’t use it.
745+
/// There are almost always better names
746+
func testNoEntryInTypeNames() {
747+
var failures: [ValidationFailure] = []
748+
749+
for node in SYNTAX_NODES {
750+
if node.kind.syntaxType.description.contains("Entry") {
751+
failures.append(
752+
ValidationFailure(
753+
node: node.kind,
754+
message:
755+
"non-collection node shouldn’t contain 'List'"
756+
)
757+
)
758+
}
759+
}
760+
761+
assertFailuresMatchXFails(failures, expectedFailures: [])
762+
}
703763
}

0 commit comments

Comments
 (0)