Skip to content

Commit

Permalink
Merge branch 'main' of github.com:smithy-lang/smithy-kotlin into misc…
Browse files Browse the repository at this point in the history
…-kotlin-2.1.0
  • Loading branch information
lauzadis committed Dec 16, 2024
2 parents c6fc3cd + 7085c8a commit 3471a8e
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Changelog

## [1.3.30] - 12/16/2024

## [1.3.29] - 12/12/2024

## [1.3.28] - 12/03/2024
Expand Down
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ kotlinx.atomicfu.enableNativeIrTransformation=false
org.gradle.jvmargs=-Xmx2G -XX:MaxMetaspaceSize=1G

# SDK
sdkVersion=1.3.30-SNAPSHOT
sdkVersion=1.3.31-SNAPSHOT

# codegen
codegenVersion=0.33.30-SNAPSHOT
codegenVersion=0.33.31-SNAPSHOT
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,20 @@ public fun Any?.type(): String = when (this) {
else -> throw Exception("Undetected type for: $this")
}

// Collection `flattenIfPossible` functions
@InternalApi
@JvmName("noOpUnnestedCollection")
public inline fun <reified T> Collection<T>.flattenIfPossible(): Collection<T> = this

@InternalApi
@JvmName("flattenNestedCollection")
public inline fun <reified T> Collection<Collection<T>>.flattenIfPossible(): Collection<T> = flatten()

// List `flattenIfPossible` functions
@InternalApi
@JvmName("noOpUnnestedCollection")
public inline fun <reified T> List<T>.flattenIfPossible(): List<T> = this

@InternalApi
@JvmName("flattenNestedCollection")
public inline fun <reified T> List<List<T>>.flattenIfPossible(): List<T> = flatten()
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package aws.smithy.kotlin.runtime.util

import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertTrue

class JmesPathTest {
@Test
fun flattenNestedLists() {
val nestedList = listOf(
listOf(1, 2, 3),
listOf(4, 5),
listOf(6),
)
val flattenedList = nestedList.flattenIfPossible()
assertEquals(listOf(1, 2, 3, 4, 5, 6), flattenedList)
}

@Test
fun flattenEmptyNestedLists() {
val nestedList = listOf(
listOf<Int>(),
listOf(),
listOf(),
)
val flattenedList = nestedList.flattenIfPossible()
assertTrue(flattenedList.isEmpty())
}

@Test
fun flattenNestedEmptyAndNonEmptyNestedLists() {
val nestedList = listOf(
listOf(1, 2),
listOf(),
listOf(3, 4, 5),
)
val flattenedList = nestedList.flattenIfPossible()
assertEquals(listOf(1, 2, 3, 4, 5), flattenedList)
}

@Test
fun flattenList() {
val nestedList = listOf(
listOf(1, 2, 3),
)
val flattenedList = nestedList.flattenIfPossible()
assertEquals(listOf(1, 2, 3), flattenedList)
}
}

0 comments on commit 3471a8e

Please sign in to comment.