-
-
Notifications
You must be signed in to change notification settings - Fork 75
Expand file tree
/
Copy pathExportSwiftTests.swift
More file actions
57 lines (52 loc) · 1.98 KB
/
Copy pathExportSwiftTests.swift
File metadata and controls
57 lines (52 loc) · 1.98 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
56
57
import Foundation
import SwiftSyntax
import SwiftParser
import Testing
@testable import BridgeJSCore
@Suite struct ExportSwiftTests {
private func snapshot(
swiftAPI: ExportSwift,
name: String? = nil,
filePath: String = #filePath,
function: String = #function,
sourceLocation: Testing.SourceLocation = #_sourceLocation
) throws {
let (outputSwift, outputSkeleton) = try #require(try swiftAPI.finalize())
try assertSnapshot(
name: name,
filePath: filePath,
function: function,
sourceLocation: sourceLocation,
input: outputSwift.data(using: .utf8)!,
fileExtension: "swift"
)
let encoder = JSONEncoder()
encoder.outputFormatting = [.prettyPrinted, .sortedKeys]
let outputSkeletonData = try encoder.encode(outputSkeleton)
try assertSnapshot(
name: name,
filePath: filePath,
function: function,
sourceLocation: sourceLocation,
input: outputSkeletonData,
fileExtension: "json"
)
}
static let inputsDirectory = URL(fileURLWithPath: #filePath).deletingLastPathComponent().appendingPathComponent(
"Inputs"
)
static func collectInputs() -> [String] {
let fileManager = FileManager.default
let inputs = try! fileManager.contentsOfDirectory(atPath: Self.inputsDirectory.path)
return inputs.filter { $0.hasSuffix(".swift") }
}
@Test(arguments: collectInputs())
func snapshot(input: String) throws {
let swiftAPI = ExportSwift(progress: .silent, moduleName: "TestModule")
let url = Self.inputsDirectory.appendingPathComponent(input)
let sourceFile = Parser.parse(source: try String(contentsOf: url, encoding: .utf8))
try swiftAPI.addSourceFile(sourceFile, input)
let name = url.deletingPathExtension().lastPathComponent
try snapshot(swiftAPI: swiftAPI, name: name)
}
}