Skip to content
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
32 changes: 6 additions & 26 deletions sjsonnet/src/sjsonnet/Format.scala
Original file line number Diff line number Diff line change
Expand Up @@ -725,41 +725,21 @@ object Format {
)
}
case _: Val.True =>
val b = 1
formatted.conversion match {
case 'd' | 'i' | 'u' => formatInteger(formatted, b)
case 'o' => formatOctal(formatted, b)
case 'x' => formatHexadecimal(formatted, b)
case 'X' => formatHexadecimal(formatted, b).toUpperCase
case 'e' => formatExponent(formatted, b).toLowerCase
case 'E' => formatExponent(formatted, b)
case 'f' | 'F' => formatFloat(formatted, b)
case 'g' => formatGeneric(formatted, b).toLowerCase
case 'G' => formatGeneric(formatted, b)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#212 @stephenamar-db is this by design?

case 'c' =>
Error.fail("%c expected number or string, got boolean")
case 's' => widenRaw(formatted, "true")
case _ =>
case 'c' =>
Error.fail("%c expected number or string, got boolean")
case _ =>
Error.fail(
"expected number or string at position %d, got boolean".format(i)
)
}
case _: Val.False =>
val b = 0
formatted.conversion match {
case 'd' | 'i' | 'u' => formatInteger(formatted, b)
case 'o' => formatOctal(formatted, b)
case 'x' => formatHexadecimal(formatted, b)
case 'X' => formatHexadecimal(formatted, b).toUpperCase
case 'e' => formatExponent(formatted, b).toLowerCase
case 'E' => formatExponent(formatted, b)
case 'f' | 'F' => formatFloat(formatted, b)
case 'g' => formatGeneric(formatted, b).toLowerCase
case 'G' => formatGeneric(formatted, b)
case 'c' =>
Error.fail("%c expected number or string, got boolean")
case 's' => widenRaw(formatted, "false")
case _ =>
case 'c' =>
Error.fail("%c expected number or string, got boolean")
case _ =>
Error.fail(
"expected number or string at position %d, got boolean".format(i)
)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"%d" % true
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
sjsonnet.Error: [std.format] expected number or string at position 0, got boolean
at [<root>].(error.format_d_boolean.jsonnet:1:6)
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"%e" % true
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
sjsonnet.Error: [std.format] expected number or string at position 0, got boolean
at [<root>].(error.format_e_boolean.jsonnet:1:6)
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"%f" % false
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
sjsonnet.Error: [std.format] expected number or string at position 0, got boolean
at [<root>].(error.format_f_boolean.jsonnet:1:6)
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"%g" % true
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
sjsonnet.Error: [std.format] expected number or string at position 0, got boolean
at [<root>].(error.format_g_boolean.jsonnet:1:6)
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"%o" % true
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
sjsonnet.Error: [std.format] expected number or string at position 0, got boolean
at [<root>].(error.format_o_boolean.jsonnet:1:6)
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"%x" % true
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
sjsonnet.Error: [std.format] expected number or string at position 0, got boolean
at [<root>].(error.format_x_boolean.jsonnet:1:6)
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Regression test: %s must still work with booleans after the type-error fix.
// Verified against cpp-jsonnet 0.21.0, go-jsonnet 0.22.0, jrsonnet 0.5.0-pre99.
std.assertEqual("%s" % true, "true") &&
std.assertEqual("%s" % false, "false") &&
std.assertEqual("%10s" % true, " true") &&
std.assertEqual("%-10s" % false, "false ") &&
std.assertEqual("val: %s" % true, "val: true") &&
std.assertEqual("%s %s" % [true, false], "true false") &&
true
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
true
Loading