Skip to content

Commit 0235209

Browse files
eggrobinmarkusicu
andauthored
Post-16 invariants (#940)
* Test MCM stability * Fix line numbers for invariant test failures * Bindestrich Co-authored-by: Markus Scherer <[email protected]> --------- Co-authored-by: Markus Scherer <[email protected]>
1 parent 1f2d9a0 commit 0235209

File tree

2 files changed

+21
-7
lines changed

2 files changed

+21
-7
lines changed

unicodetools/src/main/java/org/unicode/text/UCD/TestUnicodeInvariants.java

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ public static int testInvariants(String inputFile, String suffix, boolean doRang
184184
}
185185
final var noComments = new StringBuilder();
186186
final List<String> lines = new ArrayList<>();
187-
final List<Integer> lineBeginnings = new ArrayList();
187+
final List<Integer> lineBeginnings = new ArrayList<>();
188188
try (final BufferedReader in = getInputReader(inputFile)) {
189189
in.lines()
190190
.forEach(
@@ -234,7 +234,24 @@ public static int testInvariants(String inputFile, String suffix, boolean doRang
234234
position -> {
235235
for (int i = 0; i < lineBeginnings.size(); ++i) {
236236
if (lineBeginnings.get(i) > position.getIndex()) {
237-
return i; // 1-based line number.
237+
// The error is before the beginning of line i (0-based), thus
238+
// on line i (1-based).
239+
return i;
240+
} else if (lineBeginnings.get(i) == position.getIndex()) {
241+
// The position in a beginning of line; this happens when a
242+
// statement has been successfully parsed, but then fails for
243+
// non-syntactic reasons.
244+
// The parse position is then the beginning of the next
245+
// statement.
246+
// Backtrack to the last nonempty line (ignoring comments),
247+
// which is the last line of the failing statement.
248+
int indexInTrimmedSource = position.getIndex();
249+
while (lineBeginnings.get(i) == indexInTrimmedSource
250+
&& indexInTrimmedSource > 0) {
251+
--indexInTrimmedSource;
252+
--i;
253+
}
254+
return i + 1;
238255
}
239256
}
240257
return lineBeginnings.size();

unicodetools/src/main/resources/org/unicode/text/UCD/UnicodeInvariantTest.txt

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -746,11 +746,8 @@ In \P{Other_Joining_Type=Deduce_From_General_Category}, Joining_Type = Other_Joi
746746
[ \p{Other_Joining_Type=Deduce_From_General_Category} & [\p{gc=Mn}\p{gc=Me}\p{gc=Cf}] ] ⊆ \p{Joining_Type=Transparent}
747747
[ \p{Other_Joining_Type=Deduce_From_General_Category} - [\p{gc=Mn}\p{gc=Me}\p{gc=Cf}] ] ⊆ \p{Joining_Type=Non_Joining}
748748

749-
## Modifier_Combining_Mark stability. Not yet testable, since MCM does not exist before 16.0.
750-
# NOTICE TO THE MAINTAINER: The following line is intended to fail after 16.0;
751-
# When it does, remove it and uncomment the line after it.
752-
\p{gc=Cn} = \p{U16:gc=Cn} # ☚ REMOVE ME WHEN I FAIL…
753-
# … AND UNCOMMENT ME. ☛ # In \P{U-1:gc=Cn}, Modifier_Combining_Mark = U-1:Modifier_Combining_Mark
749+
## Modifier_Combining_Mark stability.
750+
In \P{U-1:gc=Cn}, Modifier_Combining_Mark = U-1:Modifier_Combining_Mark
754751

755752
##########################
756753
# LineBreak property

0 commit comments

Comments
 (0)