@@ -525,6 +525,15 @@ private static void propertywiseAlikeLine(
525
525
}
526
526
}
527
527
528
+ private static String stringAt (UnicodeSet set , int i ) {
529
+ final int codePointsSize = set .size () - set .strings ().size ();
530
+ if (i < codePointsSize ) {
531
+ return Character .toString (set .charAt (i ));
532
+ } else {
533
+ return set .strings ().stream ().skip (i - codePointsSize ).findFirst ().get ();
534
+ }
535
+ }
536
+
528
537
private static void propertywiseCorrespondenceLine (
529
538
Set <String > ignoredProperties ,
530
539
UnicodeSet firstSet ,
@@ -538,13 +547,13 @@ private static void propertywiseCorrespondenceLine(
538
547
final List <UnicodeSet > sets = new ArrayList <>();
539
548
sets .add (firstSet );
540
549
expectToken (":" , pp , source );
550
+
551
+ // Index of the first set of multi-character strings (and of the first multi-character
552
+ // reference string).
553
+ // This is `m` in the documentation in UnicodeInvariantTest.txt.
554
+ int firstMultiCharacterIndex = -1 ;
541
555
do {
542
556
final var set = parseUnicodeSet (source , pp );
543
- if (set .hasStrings ()) {
544
- throw new BackwardParseException (
545
- "Set should contain only single code points for property comparison" ,
546
- pp .getIndex ());
547
- }
548
557
if (set .size () != firstSet .size ()) {
549
558
throw new BackwardParseException (
550
559
"Sets should have the same size for property correspondence (got "
@@ -554,18 +563,41 @@ private static void propertywiseCorrespondenceLine(
554
563
+ ")" ,
555
564
pp .getIndex ());
556
565
}
566
+ if (set .hasStrings () && set .strings ().size () != set .size ()) {
567
+ throw new BackwardParseException (
568
+ "Sets should be all strings or all code points for property correspondence" ,
569
+ pp .getIndex ());
570
+ }
571
+ if (firstMultiCharacterIndex == -1 ) {
572
+ if (set .hasStrings ()) {
573
+ firstMultiCharacterIndex = sets .size ();
574
+ }
575
+ } else if (!set .hasStrings ()) {
576
+ throw new BackwardParseException (
577
+ "Code points should come before strings in property correspondence" ,
578
+ pp .getIndex ());
579
+ }
557
580
sets .add (set );
558
581
} while (Lookahead .oneToken (pp , source ).accept (":" ));
559
- final List <Integer > referenceCodePoints = new ArrayList <>();
582
+ if (firstMultiCharacterIndex == -1 ) {
583
+ firstMultiCharacterIndex = sets .size ();
584
+ }
585
+ final List <String > referenceCodePoints = new ArrayList <>();
560
586
expectToken ("CorrespondTo" , pp , source );
561
587
do {
562
588
final var referenceSet = parseUnicodeSet (source , pp );
563
- if (referenceSet .hasStrings () || referenceSet .size () != 1 ) {
589
+ if (referenceSet .size () != 1 ) {
590
+ throw new BackwardParseException (
591
+ "reference should be a single code point or string for property correspondence" ,
592
+ pp .getIndex ());
593
+ }
594
+ if (referenceSet .hasStrings ()
595
+ != (referenceCodePoints .size () >= firstMultiCharacterIndex )) {
564
596
throw new BackwardParseException (
565
- "reference should be a single code point for property correspondence" ,
597
+ "Strings should correspond to strings for property correspondence" ,
566
598
pp .getIndex ());
567
599
}
568
- referenceCodePoints .add (referenceSet .charAt ( 0 ));
600
+ referenceCodePoints .add (referenceSet .iterator (). next ( ));
569
601
} while (Lookahead .oneToken (pp , source ).accept (":" ));
570
602
if (referenceCodePoints .size () != sets .size ()) {
571
603
throw new BackwardParseException (
@@ -608,8 +640,8 @@ public ExpectedPropertyDifference(String actualValueAlias, String referenceValue
608
640
expectedDifference = expectedPropertyDifferences .get (alias );
609
641
}
610
642
if (expectedDifference != null ) {
611
- for (int k = 0 ; k < sets . size () ; ++k ) {
612
- final int rk = referenceCodePoints .get (k );
643
+ for (int k = 0 ; k < firstMultiCharacterIndex ; ++k ) {
644
+ final int rk = referenceCodePoints .get (k ). codePointAt ( 0 ) ;
613
645
final String pRk = property .getValue (rk );
614
646
if (!Objects .equals (pRk , expectedDifference .referenceValueAlias )) {
615
647
errorMessageLines .add (
@@ -638,9 +670,9 @@ public ExpectedPropertyDifference(String actualValueAlias, String referenceValue
638
670
}
639
671
}
640
672
} else {
641
- for (int k = 0 ; k < sets . size () ; ++k ) {
673
+ for (int k = 0 ; k < firstMultiCharacterIndex ; ++k ) {
642
674
final UnicodeSet set = sets .get (k );
643
- final int rk = referenceCodePoints .get (k );
675
+ final int rk = referenceCodePoints .get (k ). codePointAt ( 0 ) ;
644
676
final String pRk = property .getValue (rk );
645
677
loop_over_set :
646
678
for (int i = 0 ; i < set .size (); ++i ) {
@@ -652,10 +684,9 @@ public ExpectedPropertyDifference(String actualValueAlias, String referenceValue
652
684
Integer lMatchingForReference = null ;
653
685
for (int l = 0 ; l < sets .size (); ++l ) {
654
686
final boolean pCkEqualsCl =
655
- Objects .equals (pCk , Character . toString (sets .get (l ). charAt ( i ) ));
687
+ Objects .equals (pCk , stringAt (sets .get (l ), i ));
656
688
final boolean pRkEqualsRl =
657
- Objects .equals (
658
- pRk , Character .toString (referenceCodePoints .get (l )));
689
+ Objects .equals (pRk , referenceCodePoints .get (l ));
659
690
if (pRkEqualsRl ) {
660
691
lMatchingForReference = l ;
661
692
if (pCkEqualsCl ) {
@@ -685,8 +716,7 @@ public ExpectedPropertyDifference(String actualValueAlias, String referenceValue
685
716
+ ")\t =\t "
686
717
+ pCk
687
718
+ "\t ≠\t "
688
- + Character .toString (
689
- sets .get (lMatchingForReference ).charAt (i ))
719
+ + stringAt (sets .get (lMatchingForReference ), i )
690
720
+ "\t whereas\t "
691
721
+ property .getName ()
692
722
+ "("
0 commit comments