Skip to content

Commit f3efe59

Browse files
author
ntwigg
committed
Add a smaller test for maintaining this in the long-term.
1 parent 6e24222 commit f3efe59

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

jvm/selfie-lib/src/commonMain/kotlin/com/diffplug/selfie/SelfieImplementations.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ class StringSelfie(
212212
* Returns a serialized form of only the given facets if they are available, silently omits missing
213213
* facets.
214214
*/
215-
private fun serializeOnlyFacets(snapshot: Snapshot, keys: Collection<String>): String {
215+
internal fun serializeOnlyFacets(snapshot: Snapshot, keys: Collection<String>): String {
216216
val writer = StringBuilder()
217217
for (key in keys) {
218218
if (key.isEmpty()) {
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* Copyright (C) 2025 DiffPlug
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.diffplug.selfie
17+
18+
import io.kotest.assertions.throwables.shouldThrow
19+
import io.kotest.matchers.shouldBe
20+
import kotlin.test.Test
21+
22+
class SelfieImplementationsTest {
23+
@Test
24+
fun issue_529() {
25+
val empty = Snapshot.of("")
26+
val emptyPlusFacet = Snapshot.of("").plusFacet("new-facet", "new-facet-value")
27+
val exception =
28+
shouldThrow<StringIndexOutOfBoundsException> {
29+
serializeOnlyFacets(empty, listOf("new-facet"))
30+
}
31+
exception.message shouldBe "String index out of range: -1"
32+
}
33+
}

0 commit comments

Comments
 (0)