compiler: Support Querying For Files In Preprocessed Code
Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
This commit is contained in:
@@ -185,6 +185,27 @@ import TreeSitterP4
|
||||
#expect(source.getSource(annotated: true) == expected)
|
||||
}
|
||||
|
||||
@Test func test_preprocessor_nested_includes_get_file_location() async throws {
|
||||
let sm = SourceManager(["./TestData/Sources/"], FileManager()) // Add a FileManager to get absolute paths.
|
||||
let prep = SourceCodePreprocessor(sm)
|
||||
let file = FilePath.init(stringLiteral: "./TestData/Sources/file-loc.p4")
|
||||
|
||||
let source = try! (#UseOkResult(prep.preprocess(file)))
|
||||
|
||||
let expected_file = FilePath.init(FileManager().currentDirectoryPath + "/" + file.string)
|
||||
.lexicallyNormalized()
|
||||
let expected_nested_file = sm.firstExisting("file-loc-parser.p4")!.lexicallyNormalized()
|
||||
let expected_nested_nested_file = sm.firstExisting("file-loc-parser-state.p4")!
|
||||
.lexicallyNormalized()
|
||||
|
||||
let found_file = try! #require(source.pathForLocation(0))
|
||||
let found_nested_file = try! #require(source.pathForLocation(55))
|
||||
let found_nested_nested_file = try! #require(source.pathForLocation(78))
|
||||
|
||||
#expect(found_file == expected_file)
|
||||
#expect(found_nested_file == expected_nested_file)
|
||||
#expect(found_nested_nested_file == expected_nested_nested_file)
|
||||
}
|
||||
|
||||
@Test func test_source_location_contains() async throws {
|
||||
let outer = SourceLocation(0..<500)
|
||||
|
||||
Reference in New Issue
Block a user