Skip to content

Commit

Permalink
fix flatten module order error
Browse files Browse the repository at this point in the history
Fixes gh-1998
  • Loading branch information
luozejiaqun committed Oct 23, 2024
1 parent 74f9198 commit 05c7a11
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ fun flatten(modules: List<Module>): Set<Module> {
}

// Add all the included modules to the stack if they haven't been visited yet.
for (module in current.includedModules) {
for (module in current.includedModules.asReversed()) {
if (module !in flatten) {
stack += module
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package org.koin.dsl

import org.koin.core.module.flatten
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertTrue

class FlattenTest {
Expand All @@ -12,17 +13,17 @@ class FlattenTest {
val m2 = module { }
val modules = m1 + m2

assertTrue { flatten(modules) == setOf(m1, m2) }
assertSetEqualsInOrder(flatten(modules), setOf(m1, m2))
}

@Test
fun test_flatten_common() {
val m1 = module { }
val m2 = module { }
val m3 = module { includes(m1) }
val m3 = module { includes(m1, m2) }
val modules = m3 + m2

assertTrue { flatten(modules) == setOf(m3, m1, m2) }
assertSetEqualsInOrder(flatten(modules), setOf(m3, m1, m2))
}

@Test
Expand All @@ -32,7 +33,7 @@ class FlattenTest {
val m3 = module { includes(m1) }
val modules = m3 + m2

assertTrue { flatten(modules) == setOf(m3, m1, m2) }
assertSetEqualsInOrder(flatten(modules), setOf(m3, m1, m2))
}

@Test
Expand All @@ -43,6 +44,10 @@ class FlattenTest {
val m3 = module { includes(m1) }
val modules = m3 + m2

assertTrue { flatten(modules) == setOf(m3, m1, m4, m2) }
assertSetEqualsInOrder(flatten(modules), setOf(m3, m1, m4, m2))
}

private fun assertSetEqualsInOrder(actual: Set<Any>, expected: Set<Any>) {
assertEquals(expected.toList(), actual.toList())
}
}

0 comments on commit 05c7a11

Please sign in to comment.