@@ -2,6 +2,7 @@ package de.cketti.codepoints
22
33import kotlin.test.assertEquals
44import kotlin.test.Test
5+ import kotlin.test.assertFailsWith
56
67class StringExtensionsTest {
78 @Test
@@ -120,4 +121,34 @@ class StringExtensionsTest {
120121 assertEquals(0 , " \uD83E\uDD95\uD83E\uDD96 " .offsetByCodePoints(index = 3 , codePointOffset = - 2 ))
121122 assertEquals(0 , " \uD83E\uDD95\uD83E\uDD96 " .offsetByCodePoints(index = 1 , codePointOffset = - 1 ))
122123 }
124+
125+ @Test
126+ fun offsetByCodePoints_with_invalid_index () {
127+ assertFailsWith<IndexOutOfBoundsException > {
128+ " a" .offsetByCodePoints(index = - 1 , codePointOffset = 0 )
129+ }
130+
131+ assertFailsWith<IndexOutOfBoundsException > {
132+ " a" .offsetByCodePoints(index = 2 , codePointOffset = 0 )
133+ }
134+ }
135+
136+ @Test
137+ fun offsetByCodePoints_with_invalid_codePointOffset () {
138+ assertFailsWith<IndexOutOfBoundsException > {
139+ " a" .offsetByCodePoints(index = 0 , codePointOffset = 2 )
140+ }
141+
142+ assertFailsWith<IndexOutOfBoundsException > {
143+ " a" .offsetByCodePoints(index = 1 , codePointOffset = - 2 )
144+ }
145+
146+ assertFailsWith<IndexOutOfBoundsException > {
147+ " \uD83E\uDD95 " .offsetByCodePoints(index = 0 , codePointOffset = 2 )
148+ }
149+
150+ assertFailsWith<IndexOutOfBoundsException > {
151+ " \uD83E\uDD95 " .offsetByCodePoints(index = 2 , codePointOffset = - 2 )
152+ }
153+ }
123154}
0 commit comments