|
41 | 41 | import sun.text.Normalizer;
|
42 | 42 | import jdk.internal.icu.text.NormalizerBase;
|
43 | 43 |
|
| 44 | +import java.util.HexFormat; |
| 45 | + |
44 | 46 | import static java.text.Normalizer.Form.*;
|
45 | 47 |
|
46 | 48 | public class ICUBasicTest extends IntlTest {
|
@@ -149,7 +151,8 @@ public void TestCombiningMarks() {
|
149 | 151 |
|
150 | 152 | if (!expected.equals(result)) {
|
151 | 153 | errln("Reordering of combining marks failed. Expected: " +
|
152 |
| - toHexString(expected) + " Got: "+ toHexString(result)); |
| 154 | + HexFormat.of().withDelimiter(" ").formatHex(expected.getBytes()) |
| 155 | + + " Got: "+ HexFormat.of().withDelimiter(" ").formatHex(result.getBytes())); |
153 | 156 | }
|
154 | 157 | }
|
155 | 158 |
|
@@ -191,16 +194,22 @@ public void TestVerisign() throws Exception {
|
191 | 194 |
|
192 | 195 | String result = NormalizerBase.normalize(input, NFD);
|
193 | 196 | if (!result.equals(output)) {
|
194 |
| - errln("FAIL input: " + toHexString(input) + "\n" + |
195 |
| - " decompose: " + toHexString(result) + "\n" + |
196 |
| - " expected: " + toHexString(output)); |
| 197 | + errln("FAIL input: " + HexFormat.of().withDelimiter(" ") |
| 198 | + .formatHex(input.getBytes()) + "\n" + |
| 199 | + " decompose: " + HexFormat.of().withDelimiter(" ") |
| 200 | + .formatHex(result.getBytes()) + "\n" + |
| 201 | + " expected: " + HexFormat.of().withDelimiter(" ") |
| 202 | + .formatHex(output.getBytes())); |
197 | 203 | }
|
198 | 204 |
|
199 | 205 | result = NormalizerBase.normalize(input, NFC);
|
200 | 206 | if (!result.equals(output)) {
|
201 |
| - errln("FAIL input: " + toHexString(input) + "\n" + |
202 |
| - " compose: " + toHexString(result) + "\n" + |
203 |
| - " expected: " + toHexString(output)); |
| 207 | + errln("FAIL input: " + HexFormat.of().withDelimiter(" ") |
| 208 | + .formatHex(input.getBytes()) + "\n" + |
| 209 | + " compose: " + HexFormat.of().withDelimiter(" ") |
| 210 | + .formatHex(output.getBytes()) + "\n" + |
| 211 | + " expected: " + HexFormat.of().withDelimiter(" ") |
| 212 | + .formatHex(output.getBytes())); |
204 | 213 | }
|
205 | 214 | }
|
206 | 215 | }
|
@@ -231,21 +240,27 @@ public void TestZeroIndex() throws Exception {
|
231 | 240 | String exp = DATA[i+1];
|
232 | 241 |
|
233 | 242 | if (b.equals(exp)) {
|
234 |
| - logln("Ok: " + toHexString(a) + " x COMPOSE_COMPAT => " + |
235 |
| - toHexString(b)); |
| 243 | + logln("Ok: " + HexFormat.of().withDelimiter(" ") |
| 244 | + .formatHex(a.getBytes()) + " x COMPOSE_COMPAT => " + |
| 245 | + HexFormat.of().withDelimiter(" ") |
| 246 | + .formatHex(b.getBytes())); |
236 | 247 | } else {
|
237 |
| - errln("FAIL: " + toHexString(a) + " x COMPOSE_COMPAT => " + |
238 |
| - toHexString(b) + ", expect " + toHexString(exp)); |
| 248 | + errln("FAIL: " + HexFormat.of().withDelimiter(" ") |
| 249 | + .formatHex(b.getBytes()) + " x COMPOSE_COMPAT => " + |
| 250 | + HexFormat.of().withDelimiter(" ") |
| 251 | + .formatHex(a.getBytes()) + ", expect " + |
| 252 | + HexFormat.of().withDelimiter(" ") |
| 253 | + .formatHex(exp.getBytes())); |
239 | 254 | }
|
240 | 255 |
|
241 | 256 | a = NormalizerBase.normalize(b, NFD);
|
242 | 257 | exp = DATA[i+2];
|
243 | 258 | if (a.equals(exp)) {
|
244 |
| - logln("Ok: " + toHexString(b) + " x DECOMP => " + |
245 |
| - toHexString(a)); |
| 259 | + logln("Ok: " + HexFormat.of().withDelimiter(" ").formatHex(b.getBytes()) + " x DECOMP => " + |
| 260 | + HexFormat.of().withDelimiter(" ").formatHex(a.getBytes())); |
246 | 261 | } else {
|
247 |
| - errln("FAIL: " + toHexString(b) + " x DECOMP => " + |
248 |
| - toHexString(a) + ", expect " + toHexString(exp)); |
| 262 | + errln("FAIL: " + HexFormat.of().withDelimiter(" ").formatHex(b.getBytes()) + " x DECOMP => " + |
| 263 | + HexFormat.of().withDelimiter(" ").formatHex(a.getBytes()) + ", expect " + HexFormat.of().withDelimiter(" ").formatHex(exp.getBytes())); |
249 | 264 | }
|
250 | 265 | }
|
251 | 266 | }
|
@@ -382,25 +397,33 @@ private void checkCompositionExclusion_320(String s) throws Exception {
|
382 | 397 | String c = NormalizerBase.normalize(b, NFC);
|
383 | 398 |
|
384 | 399 | if (c.equals(a)) {
|
385 |
| - errln("FAIL: " + toHexString(a) + " x DECOMP_COMPAT => " + |
386 |
| - toHexString(b) + " x COMPOSE => " + |
387 |
| - toHexString(c) + " for the latest Unicode"); |
| 400 | + errln("FAIL: " + HexFormat.of().withDelimiter(" ") |
| 401 | + .formatHex(a.getBytes()) + " x DECOMP_COMPAT => " + |
| 402 | + HexFormat.of().withDelimiter(" ") |
| 403 | + .formatHex(b.getBytes()) + " x COMPOSE => " + |
| 404 | + HexFormat.of().withDelimiter(" ") |
| 405 | + .formatHex(c.getBytes()) + " for the latest Unicode"); |
388 | 406 | } else if (verbose) {
|
389 |
| - logln("Ok: " + toHexString(a) + " x DECOMP_COMPAT => " + |
390 |
| - toHexString(b) + " x COMPOSE => " + |
391 |
| - toHexString(c) + " for the latest Unicode"); |
| 407 | + logln("Ok: " + HexFormat.of().withDelimiter(" ") |
| 408 | + .formatHex(a.getBytes()) + " x DECOMP_COMPAT => " + |
| 409 | + HexFormat.of().withDelimiter(" ") |
| 410 | + .formatHex(b.getBytes()) + " x COMPOSE => " + |
| 411 | + HexFormat.of().withDelimiter(" ") |
| 412 | + .formatHex(c.getBytes()) + " for the latest Unicode"); |
392 | 413 | }
|
393 | 414 |
|
394 | 415 | b = NormalizerBase.normalize(a, NFKD, Normalizer.UNICODE_3_2);
|
395 | 416 | c = NormalizerBase.normalize(b, NFC, Normalizer.UNICODE_3_2);
|
396 | 417 | if (c.equals(a)) {
|
397 |
| - errln("FAIL: " + toHexString(a) + " x DECOMP_COMPAT => " + |
398 |
| - toHexString(b) + " x COMPOSE => " + |
399 |
| - toHexString(c) + " for Unicode 3.2.0"); |
| 418 | + errln("FAIL: " + HexFormat.of().withDelimiter(" ") |
| 419 | + .formatHex(a.getBytes()) + " x DECOMP_COMPAT => " + |
| 420 | + HexFormat.of().withDelimiter(" ").formatHex(b.getBytes()) + " x COMPOSE => " + |
| 421 | + HexFormat.of().withDelimiter(" ").formatHex(c.getBytes()) + " for Unicode 3.2.0"); |
400 | 422 | } else if (verbose) {
|
401 |
| - logln("Ok: " + toHexString(a) + " x DECOMP_COMPAT => " + |
402 |
| - toHexString(b) + " x COMPOSE => " + |
403 |
| - toHexString(c) + " for Unicode 3.2.0"); |
| 423 | + logln("Ok: " + HexFormat.of().withDelimiter(" ") |
| 424 | + .formatHex(a.getBytes()) + " x DECOMP_COMPAT => " + |
| 425 | + HexFormat.of().withDelimiter(" ").formatHex(b.getBytes()) + " x COMPOSE => " + |
| 426 | + HexFormat.of().withDelimiter(" ").formatHex(c.getBytes()) + " for Unicode 3.2.0"); |
404 | 427 | }
|
405 | 428 | }
|
406 | 429 |
|
@@ -572,15 +595,18 @@ private void staticTest(java.text.Normalizer.Form form,
|
572 | 595 | int outCol) throws Exception {
|
573 | 596 | for (int i = 0; i < tests.length; i++) {
|
574 | 597 | String input = tests[i][0];
|
575 |
| - logln("Normalizing '" + input + "' (" + toHexString(input) + ")" ); |
| 598 | + logln("Normalizing '" + input + "' (" + HexFormat.of() |
| 599 | + .withDelimiter(" ").formatHex(input.getBytes()) + ")" ); |
576 | 600 |
|
577 | 601 | String expect =tests[i][outCol];
|
578 | 602 | String output = java.text.Normalizer.normalize(input, form);
|
579 | 603 |
|
580 | 604 | if (!output.equals(expect)) {
|
581 | 605 | errln("FAIL: case " + i
|
582 |
| - + " expected '" + expect + "' (" + toHexString(expect) + ")" |
583 |
| - + " but got '" + output + "' (" + toHexString(output) + ")" |
| 606 | + + " expected '" + expect + "' (" + HexFormat.of() |
| 607 | + .withDelimiter(" ").formatHex(expect.getBytes()) + ")" |
| 608 | + + " but got '" + output + "' (" + HexFormat.of() |
| 609 | + .withDelimiter(" ").formatHex(output.getBytes()) + ")" |
584 | 610 | );
|
585 | 611 | }
|
586 | 612 | }
|
|
0 commit comments