File tree 4 files changed +44
-6
lines changed
commonMain/kotlin/dev/snipme/highlights/internal/locator
commonTest/kotlin/dev/snipme/highlights/internal/locator
4 files changed +44
-6
lines changed Original file line number Diff line number Diff line change
1
+ ## [ 0.7.1]
2
+
3
+ ### Fixed
4
+ - unclosed string notation during input
5
+
1
6
## [ 0.7.0]
2
7
3
8
### Added
Original file line number Diff line number Diff line change @@ -13,7 +13,7 @@ plugins {
13
13
}
14
14
15
15
group = " dev.snipme"
16
- version = " 0.7.0 "
16
+ version = " 0.7.1 "
17
17
18
18
kotlin {
19
19
// Android
Original file line number Diff line number Diff line change @@ -14,16 +14,23 @@ internal object StringLocator {
14
14
15
15
private fun findStrings (code : String ): List <PhraseLocation > {
16
16
val locations = mutableListOf<PhraseLocation >()
17
- val textIndices = mutableListOf<Int >()
18
17
19
18
// Find index of each string delimiter like " or ' or """
20
19
STRING_DELIMITERS .forEach {
20
+ val textIndices = mutableListOf<Int >()
21
21
textIndices + = code.indicesOf(it)
22
- }
23
22
24
- // For given indices find words between
25
- for (i in START_INDEX .. textIndices.lastIndex step TWO_ELEMENTS ) {
26
- locations.add(PhraseLocation (textIndices[i], textIndices[i + 1 ] + QUOTE_ENDING_POSITION ))
23
+ // For given indices find words between
24
+ for (i in START_INDEX .. textIndices.lastIndex step TWO_ELEMENTS ) {
25
+ if (textIndices.getOrNull(i + 1 ) != null ) {
26
+ locations.add(
27
+ PhraseLocation (
28
+ textIndices[i],
29
+ textIndices[i + 1 ] + QUOTE_ENDING_POSITION
30
+ )
31
+ )
32
+ }
33
+ }
27
34
}
28
35
29
36
return locations
Original file line number Diff line number Diff line change 1
1
package dev.snipme.highlights.internal.locator
2
2
3
+ import dev.snipme.highlights.internal.printResults
3
4
import dev.snipme.highlights.model.PhraseLocation
4
5
import kotlin.test.assertEquals
5
6
import kotlin.test.Test
@@ -68,4 +69,29 @@ internal class StringLocatorTest {
68
69
assertEquals(PhraseLocation (20 , 23 ), result[0 ])
69
70
assertEquals(PhraseLocation (8 , 11 ), result[1 ])
70
71
}
72
+
73
+ @Test
74
+ fun `No returns location of unclosed string phrase` () {
75
+ val testCode = """
76
+ val b = "a
77
+ val a = 'a
78
+ """ .trimIndent()
79
+
80
+ val result = StringLocator .locate(testCode)
81
+
82
+ assertEquals(0 , result.size)
83
+ }
84
+
85
+ @Test
86
+ fun `Returns location only of closed string phrase` () {
87
+ val testCode = """
88
+ val b = 'a
89
+ val a = "a"
90
+ """ .trimIndent()
91
+
92
+ val result = StringLocator .locate(testCode)
93
+
94
+ assertEquals(1 , result.size)
95
+ assertEquals(PhraseLocation (19 , 22 ), result[0 ])
96
+ }
71
97
}
You can’t perform that action at this time.
0 commit comments