Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

flatten module order error #1999

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,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())
}
}