Skip to content

Commit 44008ed

Browse files
committed
Add test for footer links (and fix incorrect link)
1 parent d511bbf commit 44008ed

File tree

3 files changed

+64
-33
lines changed

3 files changed

+64
-33
lines changed

Help/literals.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,4 +185,4 @@ for row in data {
185185
```
186186

187187
---
188-
[Index](index.md) | Next: [Expressions](expressions.md)
188+
[Index](index.md) | Next: [Symbols](symbols.md)

Help/symbols.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,4 @@ for i in 1 to 5 {
4646
```
4747

4848
---
49-
[Index](index.md) | Next: [Functions](functions.md)
49+
[Index](index.md) | Next: [Expressions](expressions.md)

ShapeScriptTests/MetadataTests.swift

Lines changed: 62 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,33 @@ private func findHeadings(in string: String) -> [String] {
5353
.map { String($0.dropFirst(3)) }
5454
}
5555

56+
private let geometryLinks = [
57+
("Primitives", "primitives.md"),
58+
("Options", "options.md"),
59+
("Materials", "materials.md"),
60+
("Transforms", "transforms.md"),
61+
("Bounds", "bounds.md"),
62+
("Groups", "groups.md"),
63+
("Paths", "paths.md"),
64+
("Text", "text.md"),
65+
("Builders", "builders.md"),
66+
("Constructive Solid Geometry", "csg.md"),
67+
]
68+
69+
private let syntaxLinks = [
70+
("Comments", "comments.md"),
71+
("Literals", "literals.md"),
72+
("Symbols", "symbols.md"),
73+
("Expressions", "expressions.md"),
74+
("Functions", "functions.md"),
75+
("Commands", "commands.md"),
76+
("Control Flow", "control-flow.md"),
77+
("Blocks", "blocks.md"),
78+
("Scope", "scope.md"),
79+
("Debugging", "debugging.md"),
80+
("Import", "import.md"),
81+
]
82+
5683
class MetadataTests: XCTestCase {
5784
// MARK: Releases
5885

@@ -80,33 +107,6 @@ class MetadataTests: XCTestCase {
80107
// MARK: Help
81108

82109
func testUpdateIndex() throws {
83-
let geometryLinks = [
84-
("Primitives", "primitives.md"),
85-
("Options", "options.md"),
86-
("Materials", "materials.md"),
87-
("Transforms", "transforms.md"),
88-
("Bounds", "bounds.md"),
89-
("Groups", "groups.md"),
90-
("Paths", "paths.md"),
91-
("Text", "text.md"),
92-
("Builders", "builders.md"),
93-
("Constructive Solid Geometry", "csg.md"),
94-
]
95-
96-
let syntaxLinks = [
97-
("Comments", "comments.md"),
98-
("Literals", "literals.md"),
99-
("Symbols", "symbols.md"),
100-
("Expressions", "expressions.md"),
101-
("Functions", "functions.md"),
102-
("Commands", "commands.md"),
103-
("Control Flow", "control-flow.md"),
104-
("Blocks", "blocks.md"),
105-
("Scope", "scope.md"),
106-
("Debugging", "debugging.md"),
107-
("Import", "import.md"),
108-
]
109-
110110
func findSections(in string: String) -> [(String, String)] {
111111
findHeadings(in: string).compactMap { heading in
112112
let fragment = heading.lowercased()
@@ -153,6 +153,36 @@ class MetadataTests: XCTestCase {
153153
try index.write(to: helpIndexURL, atomically: true, encoding: .utf8)
154154
}
155155

156+
func testHelpFooterLinks() throws {
157+
let indexLinks = [
158+
("Overview", "overview.md"),
159+
("Getting Started", "getting-started.md"),
160+
("Camera Control", "camera-control.md"),
161+
] + geometryLinks + syntaxLinks + [
162+
("Export", "export.md"),
163+
("Examples", "examples.md"),
164+
("Glossary", "glossary.md"),
165+
]
166+
167+
let urlRegex = try! NSRegularExpression(pattern: "Next: \\[([^\\]]+)\\]\\(([^\\)]+)\\)", options: [])
168+
169+
for (i, (_, path)) in indexLinks.dropLast().enumerated() {
170+
let fileURL = helpDirectory.appendingPathComponent(path)
171+
let text = try XCTUnwrap(String(contentsOf: fileURL))
172+
let nsText = text as NSString
173+
let range = NSRange(location: 0, length: nsText.length)
174+
guard let match = urlRegex.firstMatch(in: text, options: [], range: range) else {
175+
XCTFail("No Next: link found in \(path)")
176+
continue
177+
}
178+
let next: (name: String, path: String) = indexLinks[i + 1]
179+
let name = nsText.substring(with: match.range(at: 1))
180+
XCTAssertEqual(name, next.name, "Next link name in \(path) should be \(next.name)")
181+
let path = nsText.substring(with: match.range(at: 2))
182+
XCTAssertEqual(path, next.path, "Next link url in \(path) should be \(next.path)")
183+
}
184+
}
185+
156186
func testHelpLinks() throws {
157187
let enumerator =
158188
try XCTUnwrap(FileManager.default.enumerator(atPath: helpDirectory.path))
@@ -162,11 +192,12 @@ class MetadataTests: XCTestCase {
162192
var referencedImages = Set<String>()
163193
for case let file as String in enumerator where file.hasSuffix(".md") {
164194
let fileURL = helpDirectory.appendingPathComponent(file)
165-
let text = try XCTUnwrap(String(contentsOf: fileURL)) as NSString
166-
var range = NSRange(location: 0, length: text.length)
167-
for match in urlRegex.matches(in: text as String, options: [], range: range) {
195+
let text = try XCTUnwrap(String(contentsOf: fileURL))
196+
let nsText = text as NSString
197+
var range = NSRange(location: 0, length: nsText.length)
198+
for match in urlRegex.matches(in: text, options: [], range: range) {
168199
range = NSRange(location: match.range.upperBound, length: range.length - match.range.upperBound)
169-
var url = text.substring(with: match.range(at: 1))
200+
var url = nsText.substring(with: match.range(at: 1))
170201
var fragment = ""
171202
let parts = url.components(separatedBy: "#")
172203
guard !url.hasPrefix("http") else {

0 commit comments

Comments
 (0)