Skip to content

Commit c31a880

Browse files
committed
[incrParse] Allow whitespaces to be reparsed in test
This greatly improves the ergonomics of writing tests and outweighs the ability to test which whitespaces get parsed since their parsing overhead should be minimal.
1 parent 9bdc54a commit c31a880

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

test/incrParse/simple.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
// RUN: %incparse-test %s --test-case MULTI_EDIT_SAME_LINE
1111

1212
func foo() {
13-
}<reparse REPLACE>
13+
}
1414

15-
_ = <<REPLACE<6|||7>>></reparse REPLACE>
15+
<reparse REPLACE>_ = <<REPLACE<6|||7>>></reparse REPLACE>
1616
_ = <<REPLACE_BY_LONGER<6|||"Hello World">>>
1717
_ = <<REPLACE_BY_SHORTER<"Hello again"|||"a">>>
1818
<<INSERT<|||foo()>>>

tools/swift-syntax-test/swift-syntax-test.cpp

+11-1
Original file line numberDiff line numberDiff line change
@@ -509,9 +509,19 @@ bool verifyReusedRegions(ByteBasedSourceRangeSet ExpectedReparseRegions,
509509
bool NoUnexpectedParse = true;
510510

511511
for (auto ReparseRegion : UnexpectedReparseRegions.Ranges) {
512-
NoUnexpectedParse = false;
513512
auto ReparseRange = ReparseRegion.toSourceRange(SourceMgr, BufferID);
514513

514+
// To improve the ergonomics when writing tests we do not want to complain
515+
// about reparsed whitespaces.
516+
auto RangeStr =
517+
CharSourceRange(SourceMgr, ReparseRange.Start, ReparseRange.End).str();
518+
llvm::Regex WhitespaceOnlyRegex("^\\s*$", llvm::Regex::Newline);
519+
if (WhitespaceOnlyRegex.match(RangeStr)) {
520+
continue;
521+
}
522+
523+
NoUnexpectedParse = false;
524+
515525
llvm::errs() << "\nERROR: Unexpectedly reparsed following region:\n";
516526
ReparseRange.print(llvm::errs(), SourceMgr);
517527
}

0 commit comments

Comments
 (0)