()
| 12 | } |
| 13 | |
| 14 | public void utfConversions() throws Exception { |
| 15 | String[] valid = { |
| 16 | "abc", |
| 17 | "абв", |
| 18 | "\ud835\udc00", // valid surrogate pair (U+1D400) |
| 19 | }; |
| 20 | for (String s : valid) { |
| 21 | try (var ms = new ManagedString(s)) { |
| 22 | assertEquals(s, ms.toString()); |
| 23 | } |
| 24 | } |
| 25 | |
| 26 | // Malformed UTF-16 must throw IllegalArgumentException. |
| 27 | String[] invalid = { |
| 28 | "\udc00", // lone low surrogate (first) |
| 29 | "A\udc00B", // lone low surrogate (middle) |
| 30 | "\ud835", // lone high surrogate (truncated) |
| 31 | "hello\ud83d", // lone high surrogate (at end) |
| 32 | "\ud835X\ud835", // high surrogate not followed by low |
| 33 | "\ud83d\ud83d", // high surrogate followed by high surrogate |
| 34 | "\ud835\u0041", // high surrogate followed by BMP char |
| 35 | }; |
| 36 | for (String s : invalid) { |
| 37 | assertThrows(IllegalArgumentException.class, () -> { |
| 38 | new ManagedString(s).close(); |
| 39 | }); |
| 40 | } |
| 41 | } |
| 42 | } |
nothing calls this directly
no test coverage detected