Skip to content

Commit

Permalink
update logging to include a current page marker even when diagnostics…
Browse files Browse the repository at this point in the history
…=false
  • Loading branch information
erdo committed Apr 6, 2024
1 parent fc15c7b commit 1166639
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 7 deletions.
6 changes: 3 additions & 3 deletions n8-core/src/main/kotlin/co/early/n8/NavigationState.kt
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ sealed class Navigation<L, T> {
return "\n" + render(
builder = StringBuilder(),
incDiagnostics = diagnostics,
current = diagnostics
current = true
).toString()
}

Expand Down Expand Up @@ -220,7 +220,7 @@ sealed class Navigation<L, T> {
return "\n" + render(
builder = StringBuilder(),
incDiagnostics = diagnostics,
current = diagnostics
current = true
).toString()
}

Expand Down Expand Up @@ -298,7 +298,7 @@ sealed class Navigation<L, T> {
return "\n" + render(
builder = StringBuilder(),
incDiagnostics = diagnostics,
current = diagnostics
current = true
).toString()
}

Expand Down
8 changes: 6 additions & 2 deletions n8-core/src/main/kotlin/co/early/n8/NavigationStateExt.kt
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,10 @@ private fun <L, T> EndNode<L, T>.render(
if (current) {
append(" <--- Current Item")
}
} else {
if (current) {
append(" <---")
}
}
return this
}
Expand Down Expand Up @@ -311,7 +315,7 @@ private fun <L, T> TabHost<L, T>.render(
if (index == selectedTabHistory.last()) {
tab.render(pad, builder, incDiagnostics, current)
} else {
tab.render(pad, builder, incDiagnostics)
tab.render(pad, builder, incDiagnostics, false)
}
append(",\n")
}
Expand Down Expand Up @@ -344,7 +348,7 @@ private fun <L, T> BackStack<L, T>.render(
if (index == lastIndex) {
stackItem.render(pad, builder, incDiagnostics, current)
} else {
stackItem.render(pad, builder, incDiagnostics)
stackItem.render(pad, builder, incDiagnostics, false)
}
append(",\n")
}
Expand Down
74 changes: 74 additions & 0 deletions n8-core/src/test/kotlin/co/early/n8/NavigationExtensionsTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,80 @@ class NavigationExtensionsTest {
)
}

@Test
fun `when logging nav graph without diagnostics, output is correct`() {

// arrange
val nav = backStackOf(
endNodeOf(A) ,
endNodeOf(B) ,
tabsOf(
selectedTabHistory = listOf(0),
tabHostId = "TABS_01",
backStackOf(
endNodeOf(X1) ,
endNodeOf(C) ,
endNodeOf(D) ,
tabsOf(
selectedTabHistory = listOf(0,1),
tabHostId = "TABS_02",
backStackOf(
endNodeOf(Y1) ,
endNodeOf(E)
),
backStackOf(
endNodeOf(Y2)
)
)
),
backStackOf(
endNodeOf(X1)
),
backStackOf(
endNodeOf(X2)
)
)
)

Fore.i(nav.toString(false))

// assert
assertEquals(
"\n" +
"backStackOf( \n" +
" endNodeOf(A),\n" +
" endNodeOf(B),\n" +
" tabsOf( \n" +
" tabHostId = TABS_01\n" +
" selectedTabHistory = listOf(0),\n" +
" backStackOf( \n" +
" endNodeOf(X1),\n" +
" endNodeOf(C),\n" +
" endNodeOf(D),\n" +
" tabsOf( \n" +
" tabHostId = TABS_02\n" +
" selectedTabHistory = listOf(0,1),\n" +
" backStackOf( \n" +
" endNodeOf(Y1),\n" +
" endNodeOf(E)\n" +
" ),\n" +
" backStackOf( \n" +
" endNodeOf(Y2) <---\n" +
" )\n" +
" )\n" +
" ),\n" +
" backStackOf( \n" +
" endNodeOf(X1)\n" +
" ),\n" +
" backStackOf( \n" +
" endNodeOf(X2)\n" +
" )\n" +
" )\n" +
")",
nav.toString(false)
)
}

@Test
fun `given a BackStack, createdBackCopy is correct`() {

Expand Down
2 changes: 0 additions & 2 deletions n8-core/src/test/kotlin/co/early/n8/TestLocationsNested.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,9 @@ class NestedExample {
@Serializable
data object TabAbc : TabHost()


@Serializable
data object TabAbcStructural : TabHost()


@Serializable
data object TabX12 : TabHost()

Expand Down

0 comments on commit 1166639

Please sign in to comment.