@@ -202,6 +202,18 @@ public boolean contentEquals(byte[] array) {
202
202
}
203
203
204
204
public interface TestStrings {
205
+
206
+ default void runWithErrorDecorator (AbstractTruffleString a , byte [] array , TruffleString .CodeRange codeRange , boolean isValid , TruffleString .Encoding encoding , int [] codepoints ,
207
+ int [] byteIndices ) {
208
+ try {
209
+ run (a , array , codeRange , isValid , encoding , codepoints , byteIndices );
210
+ } catch (Throwable t ) {
211
+ String msg = String .format ("string: %s, array: %s, codeRange: %s, isValid: %b, encoding: %s, codepoints: %s, byteIndices: %s" , a .toStringDebug (),
212
+ Arrays .toString (array ), codeRange , isValid , encoding , Arrays .toString (codepoints ), Arrays .toString (byteIndices ));
213
+ throw new RuntimeException (msg , t );
214
+ }
215
+ }
216
+
205
217
void run (AbstractTruffleString a , byte [] array , TruffleString .CodeRange codeRange , boolean isValid , TruffleString .Encoding encoding , int [] codepoints , int [] byteIndices ) throws Exception ;
206
218
}
207
219
@@ -409,17 +421,17 @@ public static void forAllStrings(TruffleString.Encoding[] encodings, boolean con
409
421
byte [] encodedValidPadded = pad (dat .encodedValid );
410
422
TruffleString substring = TruffleString .fromByteArrayUncached (encodedValidPadded , 1 , dat .encodedValid .length , encoding , false );
411
423
TruffleString nativeSubstring = TruffleString .fromNativePointerUncached (PointerObject .create (encodedValidPadded ), 1 , dat .encodedValid .length , encoding , false );
412
- test .run (substring .concatUncached (nativeSubstring , encoding , true ), concatBytes , codeRangeValid , true , encoding , concatCodepoints , concatByteIndices );
424
+ test .runWithErrorDecorator (substring .concatUncached (nativeSubstring , encoding , true ), concatBytes , codeRangeValid , true , encoding , concatCodepoints , concatByteIndices );
413
425
if (isAsciiCompatible (encoding )) {
414
426
byte [] array = encoding == UTF_32 ? lazyLongBytesUTF32 : encoding == UTF_16 ? lazyLongBytesUTF16 : lazyLongBytes ;
415
- test .run (TruffleString .fromLongUncached (10 , encoding , true ), array , TruffleString .CodeRange .ASCII , true , encoding , lazyLongCodePoints , byteIndices01 );
427
+ test .runWithErrorDecorator (TruffleString .fromLongUncached (10 , encoding , true ), array , TruffleString .CodeRange .ASCII , true , encoding , lazyLongCodePoints , byteIndices01 );
416
428
}
417
429
}
418
430
}
419
431
}
420
432
421
- protected static void checkStringVariants (byte [] array , TruffleString .CodeRange codeRange , boolean isValid , TruffleString .Encoding encoding , int [] codepoints , int [] byteIndices , TestStrings test )
422
- throws Exception {
433
+ protected static void checkStringVariants (byte [] array , TruffleString .CodeRange codeRange , boolean isValid , TruffleString .Encoding encoding , int [] codepoints , int [] byteIndices ,
434
+ TestStrings test ) {
423
435
byte [] arrayPadded = pad (array );
424
436
for (AbstractTruffleString string : new AbstractTruffleString []{
425
437
TruffleString .fromByteArrayUncached (array , 0 , array .length , encoding , false ),
@@ -434,9 +446,9 @@ protected static void checkStringVariants(byte[] array, TruffleString.CodeRange
434
446
MutableTruffleString .fromNativePointerUncached (PointerObject .create (arrayPadded ), 1 , array .length , encoding , false ),
435
447
MutableTruffleString .fromNativePointerUncached (PointerObject .create (arrayPadded ), 1 , array .length , encoding , true ),
436
448
}) {
437
- test .run (string , array , codeRange , isValid , encoding , codepoints , byteIndices );
449
+ test .runWithErrorDecorator (string , array , codeRange , isValid , encoding , codepoints , byteIndices );
438
450
if ((encoding == UTF_16 || encoding == UTF_32 ) && string .isImmutable () && string .isManaged ()) {
439
- test .run (((TruffleString ) string ).asNativeUncached (PointerObject ::create , encoding , true , false ), array , codeRange , isValid , encoding , codepoints , byteIndices );
451
+ test .runWithErrorDecorator (((TruffleString ) string ).asNativeUncached (PointerObject ::create , encoding , true , false ), array , codeRange , isValid , encoding , codepoints , byteIndices );
440
452
}
441
453
}
442
454
if (encoding == UTF_16LE ) {
@@ -450,7 +462,7 @@ protected static void checkStringVariants(byte[] array, TruffleString.CodeRange
450
462
Assert .assertSame (codeRangeImprecise , codeRange );
451
463
}
452
464
}
453
- test .run (fromJavaString , array , codeRange , isValid , encoding , codepoints , byteIndices );
465
+ test .runWithErrorDecorator (fromJavaString , array , codeRange , isValid , encoding , codepoints , byteIndices );
454
466
}
455
467
if (codeRange == TruffleString .CodeRange .ASCII && isAsciiCompatible (encoding )) {
456
468
byte [] bytesUTF16 = new byte [(codepoints .length + 1 ) * 2 ];
@@ -460,7 +472,7 @@ protected static void checkStringVariants(byte[] array, TruffleString.CodeRange
460
472
TStringTestUtil .writeValue (bytesUTF16 , 1 , codepoints .length , 0xffff );
461
473
TruffleString string = TruffleString .fromByteArrayUncached (bytesUTF16 , 0 , bytesUTF16 .length , UTF_16 , false ).substringByteIndexUncached (0 , bytesUTF16 .length - 2 , UTF_16 ,
462
474
true ).switchEncodingUncached (encoding );
463
- test .run (string , array , codeRange , isValid , encoding , codepoints , byteIndices );
475
+ test .runWithErrorDecorator (string , array , codeRange , isValid , encoding , codepoints , byteIndices );
464
476
}
465
477
if (codeRange == TruffleString .CodeRange .ASCII && isAsciiCompatible (encoding ) || codeRange == TruffleString .CodeRange .LATIN_1 && isUTF16 (encoding )) {
466
478
byte [] bytesUTF32 = new byte [(codepoints .length + 1 ) * 4 ];
@@ -470,7 +482,7 @@ protected static void checkStringVariants(byte[] array, TruffleString.CodeRange
470
482
TStringTestUtil .writeValue (bytesUTF32 , 2 , codepoints .length , 0x10ffff );
471
483
TruffleString string = TruffleString .fromByteArrayUncached (bytesUTF32 , 0 , bytesUTF32 .length , UTF_32 , false ).substringByteIndexUncached (0 , bytesUTF32 .length - 4 , UTF_32 ,
472
484
true ).switchEncodingUncached (encoding );
473
- test .run (string , array , codeRange , isValid , encoding , codepoints , byteIndices );
485
+ test .runWithErrorDecorator (string , array , codeRange , isValid , encoding , codepoints , byteIndices );
474
486
}
475
487
}
476
488
0 commit comments