|
1 | 1 | package de.cketti.codepoints |
2 | 2 |
|
3 | 3 | import kotlin.test.Test |
| 4 | +import kotlin.test.assertContentEquals |
4 | 5 | import kotlin.test.assertEquals |
| 6 | +import kotlin.test.assertFailsWith |
5 | 7 | import kotlin.test.assertFalse |
6 | 8 | import kotlin.test.assertTrue |
7 | 9 |
|
@@ -120,4 +122,75 @@ class CodePointsTest { |
120 | 122 | fun toCodePoint() { |
121 | 123 | assertEquals(0x1F995, CodePoints.toCodePoint('\uD83E', '\uDD95')) |
122 | 124 | } |
| 125 | + |
| 126 | + @Test |
| 127 | + fun toChars() { |
| 128 | + assertContentEquals(charArrayOf('a'), CodePoints.toChars('a'.code)) |
| 129 | + assertContentEquals(charArrayOf('\uFFFF'), CodePoints.toChars(0xFFFF)) |
| 130 | + assertContentEquals(charArrayOf('\uD83E', '\uDD95'), CodePoints.toChars("\uD83E\uDD95".codePointAt(0))) |
| 131 | + } |
| 132 | + |
| 133 | + @Test |
| 134 | + fun toCharsDestination() { |
| 135 | + val chars = charArrayOf('z', 'z', 'z') |
| 136 | + |
| 137 | + CodePoints.toChars('a'.code, chars, 0) |
| 138 | + assertContentEquals(charArrayOf('a', 'z', 'z'), chars) |
| 139 | + |
| 140 | + CodePoints.toChars('a'.code, chars, 2) |
| 141 | + assertContentEquals(charArrayOf('a', 'z', 'a'), chars) |
| 142 | + |
| 143 | + CodePoints.toChars("\uD83E\uDD95".codePointAt(0), chars, 0) |
| 144 | + assertContentEquals(charArrayOf('\uD83E', '\uDD95', 'a'), chars) |
| 145 | + |
| 146 | + CodePoints.toChars("\uD83E\uDD95".codePointAt(0), chars, 1) |
| 147 | + assertContentEquals(charArrayOf('\uD83E', '\uD83E', '\uDD95'), chars) |
| 148 | + } |
| 149 | + |
| 150 | + @Test |
| 151 | + fun toCharsDestinationTooSmall() { |
| 152 | + val chars = charArrayOf() |
| 153 | + |
| 154 | + assertFailsWith<IndexOutOfBoundsException> { |
| 155 | + CodePoints.toChars('a'.code, chars, 0) |
| 156 | + } |
| 157 | + assertFailsWith<IndexOutOfBoundsException> { |
| 158 | + CodePoints.toChars("\uD83E\uDD95".codePointAt(0), chars, 0) |
| 159 | + } |
| 160 | + } |
| 161 | + |
| 162 | + @Test |
| 163 | + fun toCharsDestinationOffsetInvalid() { |
| 164 | + val chars = charArrayOf('z', 'z') |
| 165 | + |
| 166 | + assertFailsWith<IndexOutOfBoundsException> { |
| 167 | + CodePoints.toChars('a'.code, chars, 2) |
| 168 | + } |
| 169 | + assertContentEquals(charArrayOf('z', 'z'), chars) |
| 170 | + |
| 171 | + assertFailsWith<IndexOutOfBoundsException> { |
| 172 | + CodePoints.toChars('a'.code, chars, -1) |
| 173 | + } |
| 174 | + assertContentEquals(charArrayOf('z', 'z'), chars) |
| 175 | + |
| 176 | + assertFailsWith<IndexOutOfBoundsException> { |
| 177 | + CodePoints.toChars("\uD83E\uDD95".codePointAt(0), chars, 2) |
| 178 | + } |
| 179 | + assertContentEquals(charArrayOf('z', 'z'), chars) |
| 180 | + |
| 181 | + assertFailsWith<IndexOutOfBoundsException> { |
| 182 | + CodePoints.toChars("\uD83E\uDD95".codePointAt(0), chars, -1) |
| 183 | + } |
| 184 | + assertContentEquals(charArrayOf('z', 'z'), chars) |
| 185 | + } |
| 186 | + |
| 187 | + @Test |
| 188 | + fun toCharsDestinationOffsetTooSmall() { |
| 189 | + val chars = charArrayOf('z', 'z') |
| 190 | + |
| 191 | + assertFailsWith<IndexOutOfBoundsException> { |
| 192 | + CodePoints.toChars("\uD83E\uDD95".codePointAt(0), chars, 1) |
| 193 | + } |
| 194 | + assertContentEquals(charArrayOf('z', 'z'), chars) |
| 195 | + } |
123 | 196 | } |
0 commit comments