-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Port from snakeyaml-engine] Issue 54: Insert a trailing space when a…
…lias is a simple key (#309) Closes #294 Ports: * https://bitbucket.org/snakeyaml/snakeyaml-engine/commits/1e74afe280795e6480ec72e7efee5afed44f2e25 * https://bitbucket.org/snakeyaml/snakeyaml-engine/commits/089376b4d2bbd7a0ee66808b7c1be8acc99feb04
- Loading branch information
Showing
4 changed files
with
96 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
...mmonTest/kotlin/it/krzeminski/snakeyaml/engine/kmp/issues/issue54/DumpWithoutSpaceTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package it.krzeminski.snakeyaml.engine.kmp.issues.issue54 | ||
|
||
import io.kotest.assertions.throwables.shouldThrow | ||
import io.kotest.core.spec.style.FunSpec | ||
import io.kotest.matchers.nulls.shouldNotBeNull | ||
import io.kotest.matchers.shouldBe | ||
import io.kotest.matchers.string.shouldContain | ||
import it.krzeminski.snakeyaml.engine.kmp.api.Dump | ||
import it.krzeminski.snakeyaml.engine.kmp.api.DumpSettings | ||
import it.krzeminski.snakeyaml.engine.kmp.api.Load | ||
import it.krzeminski.snakeyaml.engine.kmp.api.LoadSettings | ||
|
||
/** | ||
* Issue 54: add a space after anchor (when it is a simple key) | ||
*/ | ||
class DumpWithoutSpaceTest : FunSpec({ | ||
fun parse(data: String): Any? { | ||
val loadSettings = LoadSettings.builder().setAllowRecursiveKeys(true).build(); | ||
val load = Load(loadSettings); | ||
return load.loadOne(data); | ||
} | ||
|
||
test("The document does not have a space after the *1 alias") { | ||
shouldThrow<Exception> { | ||
parse( | ||
"""|--- &1 | ||
|hash: | ||
| :one: true | ||
| :two: true | ||
| *1: true""".trimMargin() | ||
) | ||
}.also { | ||
it.message shouldContain "could not find expected ':'" | ||
} | ||
} | ||
|
||
test("The output does include a space after the *1 alias") { | ||
val obj = parse( | ||
"""|--- &1 | ||
|hash: | ||
| :one: true | ||
| :two: true | ||
| *1 : true""".trimMargin() | ||
) | ||
obj.shouldNotBeNull() | ||
} | ||
|
||
test("Dump and load an alias") { | ||
val map = mutableMapOf<Any, Boolean>( | ||
":one" to true, | ||
) | ||
map[map] = true | ||
val dumpSettings = DumpSettings.builder().build() | ||
val dump = Dump(dumpSettings) | ||
val output = dump.dumpToString(map) | ||
output shouldBe """|&id001 | ||
|:one: true | ||
|*id001 : true | ||
|""".trimMargin() | ||
val recursive = parse(output) | ||
recursive.shouldNotBeNull() | ||
} | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters