forked from ANT0071/ShapeScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRegressionTests.swift
More file actions
55 lines (50 loc) · 1.87 KB
/
RegressionTests.swift
File metadata and controls
55 lines (50 loc) · 1.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
//
// RegressionTests.swift
// ShapeScriptTests
//
// Created by Nick Lockwood on 27/07/2023.
// Copyright © 2023 Nick Lockwood. All rights reserved.
//
@testable import ShapeScript
import XCTest
private let projectDirectory: URL = testsDirectory.deletingLastPathComponent()
private let exampleURLs: [URL] = try! FileManager.default
.contentsOfDirectory(
at: projectDirectory.appendingPathComponent("Examples"),
includingPropertiesForKeys: nil
)
.filter { $0.pathExtension == "shape" }
private let testShapesURLs: [URL] = try! FileManager.default
.contentsOfDirectory(
at: testsDirectory.appendingPathComponent("TestShapes"),
includingPropertiesForKeys: nil
)
.filter { $0.pathExtension == "shape" }
.filter {
#if os(iOS)
return !$0.deletingPathExtension().lastPathComponent.hasSuffix("-mac")
#else
return !$0.deletingPathExtension().lastPathComponent.hasSuffix("-ios")
#endif
}
final class RegressionTests: XCTestCase {
func testExamples() throws {
XCTAssertFalse(exampleURLs.isEmpty)
XCTAssertFalse(testShapesURLs.isEmpty)
for url in exampleURLs + testShapesURLs {
let name = url.lastPathComponent
let input = try String(contentsOf: url)
let program = try parse(input)
let delegate = TestDelegate(directory: url.deletingLastPathComponent())
let context = EvaluationContext(source: program.source, delegate: delegate)
XCTAssertNoThrow(try program.evaluate(in: context), "\(name) errored")
for (i, geometry) in context.children.compactMap({
$0.value as? Geometry
}).enumerated() {
XCTAssert(geometry.isWatertight { false }, """
\(name) object \(i + 1) was not watertight
""")
}
}
}
}