Skip to content
Merged
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
25 changes: 15 additions & 10 deletions sjsonnet/src/sjsonnet/stdlib/ManifestModule.scala
Original file line number Diff line number Diff line change
Expand Up @@ -486,17 +486,22 @@ object ManifestModule extends AbstractFunctionModule {
case (k, v) => Seq(k + " = " + render(v))
}
}
val lines = materialized.obj
val mainLines = materialized.obj
.get("main")
.fold(Iterable[String]())(x => sect(x.asInstanceOf[ujson.Obj])) ++
materialized.obj
.get("sections")
.fold(Iterable[String]())(x =>
// TODO remove the `toSeq` once this is fixed in scala3
x.obj.toSeq.flatMap { case (k, v) =>
Seq("[" + k + "]") ++ sect(v.asInstanceOf[ujson.Obj])
}
)
.fold(Iterable[String]())(x => sect(x.asInstanceOf[ujson.Obj]))
// Official std.jsonnet accesses `ini.sections` directly, so a missing `sections`
// field is an error rather than being silently treated as empty (issue #799).
// `main` stays optional, matching `std.objectHas(ini, 'main')` in the upstream impl.
val sectionLines = materialized.obj.get("sections") match {
case Some(x) =>
// TODO remove the `toSeq` once this is fixed in scala3
x.obj.toSeq.flatMap { case (k, v) =>
Seq("[" + k + "]") ++ sect(v.asInstanceOf[ujson.Obj])
}
case None =>
Error.fail("Field does not exist: sections", pos)(ev)
}
val lines = mainLines ++ sectionLines
lines.flatMap(Seq(_, "\n")).mkString
},
/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
std.manifestIni({ main: { a: '1' } })
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
sjsonnet.Error: [std.manifestIni] Field does not exist: sections
at [<root>].(error.manifestini_requires_sections.jsonnet:1:16)
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Issue #799: std.manifestIni follows official Jsonnet — `sections` is required (a missing
// `sections` field is an error, see error.manifestini_requires_sections), while `main` is optional.
std.assertEqual(
std.manifestIni({ main: { a: '1', b: '2' }, sections: { s: { b: '2' } } }),
'a = 1\nb = 2\n[s]\nb = 2\n'
) &&
std.assertEqual(
std.manifestIni({ sections: { s: { b: '2' } } }),
'[s]\nb = 2\n'
) &&
std.assertEqual(
std.manifestIni({ sections: {} }),
''
) &&
true
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
true
Loading