Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions jvm/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed
- Off-by-one in the error message for a VCR key mismatch. ([#526](https://github.com/diffplug/selfie/pull/526))
- Fix `StringIndexOutOfBoundsException` when an empty snapshot had a facet added. (fixes [#529](https://github.com/diffplug/selfie/issues/529))
- Fix `ClassCastException` when multiple nested test cases need to update snapshot. (fixes [#531](https://github.com/diffplug/selfie/issues/531))

## [2.5.1] - 2025-03-04
### Fixed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -287,10 +287,12 @@ class ArraySet<K : Comparable<K>>(private val data: Array<Any>) : ListBackedSet<
else -> {
// TODO: use idxInsert and arrayCopy to do this faster, see ArrayMap#insert
val array = Array(size + 1) { if (it < size) data[it] else key }

if (key is String) {
array.sortWith(STRING_SLASHFIRST as Comparator<Any>)
} else {
(array as Array<K>).sort()
array.sortWith(
Comparator { a, b -> @Suppress("UNCHECKED_CAST") (a as K).compareTo(b as K) })
}
ArraySet(array)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2023-2024 DiffPlug
* Copyright (C) 2023-2025 DiffPlug
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -173,3 +173,40 @@ class ArrayMapTest {
map.minusSortedIndices(listOf(0, 2, 3, 6, 7, 8)).toString() shouldBe "{1=1, 4=4, 5=5}"
}
}

class ArraySetTest() {
@Test
fun empty() {
val empty = ArraySet.empty<String>()
assertEmpty(empty)
}

@Test
fun addition() {
var mySet = ArraySet.empty<String>()
assertEmpty(mySet)

mySet = mySet.plusOrThis("one")
assertSingle(mySet, "one")
mySet = mySet.plusOrThis("one")
assertSingle(mySet, "one")
mySet = mySet.plusOrThis("two")
assertDouble(mySet, "one", "two")
}
private fun assertEmpty(map: ArraySet<String>) {
map.size shouldBe 0
}
private fun assertSingle(map: ArraySet<String>, key: String) {
map.size shouldBe 1
map.contains(key) shouldBe true
}
private fun assertDouble(
map: ArraySet<String>,
key1: String,
key2: String,
) {
map.size shouldBe 2
map.contains(key1) shouldBe true
map.contains(key2) shouldBe true
}
}
Loading