Skip to content

Commit de01797

Browse files
committed
figure out indentation
1 parent 27636cc commit de01797

File tree

3 files changed

+40
-12
lines changed

3 files changed

+40
-12
lines changed

README.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -304,8 +304,8 @@ val dsl = YamlDSL().apply {
304304
str="""
305305
Multi line
306306
Strings are
307-
supported
308-
and
307+
supported
308+
and
309309
preserve their
310310
indentation!
311311
""".trimIndent()
@@ -326,10 +326,10 @@ This prints the YAML below:
326326
str: |
327327
Multi line
328328
Strings are
329-
supported
330-
and
329+
supported
330+
and
331331
preserve their
332-
indentation!
332+
indentation!
333333
map:
334334
foo: bar
335335
num: 3.141592653589793

src/commonTest/kotlin/com/jillesvangurp/jsondsl/YamlTest.kt

+30-3
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@ import kotlin.test.Test
55

66
class YamlTest {
77
val serializer = SimpleYamlSerializer()
8+
89
@Test
910
fun shouldProduceYaml() {
1011
val q = query {
11-
query = term("foo","bar") {
12-
boost=2.0
12+
query = term("foo", "bar") {
13+
boost = 2.0
1314
}
1415
}
1516
val yaml = serializer.serialize(q)
@@ -111,8 +112,34 @@ class YamlTest {
111112
// for now, I've passed this through yamllint.com and it seems OK
112113
println(yaml)
113114
}
114-
}
115115

116+
@Test
117+
fun shouldNotAddSpaces() {
118+
119+
val yml = withJsonDsl {
120+
val str = """
121+
Multi line
122+
Strings are
123+
supported
124+
and
125+
preserve their
126+
indentation!
127+
""".trimIndent()
128+
this["s"] = str
129+
this["a"] = """
130+
noIndent
131+
twoIndent
132+
fourIndent
133+
""".trimIndent()
134+
}.yaml()
135+
println(yml)
136+
yml.lines().let { lines ->
137+
val indent = lines.first { it.contains("noIndent") }.indexOf("noIndent")
138+
(lines.first { it.contains("twoIndent") }.indexOf("twoIndent") - indent) shouldBe 2
139+
(lines.first { it.contains("fourIndent") }.indexOf("fourIndent") - indent) shouldBe 4
140+
}
141+
}
142+
}
116143

117144

118145
val loremIpsumText = """

src/jvmTest/kotlin/com/jillesvangurp/jsondsl/readme/ReadmeGenerationTest.kt

+5-4
Original file line numberDiff line numberDiff line change
@@ -234,10 +234,10 @@ val readmeMd = sourceGitRepository.md {
234234
str="""
235235
Multi line
236236
Strings are
237-
supported
238-
and
237+
supported
238+
and
239239
preserve their
240-
indentation!
240+
indentation!
241241
""".trimIndent()
242242
map = mapOf(
243243
"foo" to "bar",
@@ -252,7 +252,8 @@ val readmeMd = sourceGitRepository.md {
252252
+"""
253253
This prints the YAML below:
254254
""".trimIndent()
255-
mdCodeBlock(it.stdOut,"yaml")
255+
256+
mdCodeBlock(it.stdOut,"yaml", reIndent = false)
256257
}
257258

258259
}

0 commit comments

Comments
 (0)