mirror of
https://github.com/mikefarah/yq.git
synced 2026-07-10 08:35:42 +00:00
Convert octal for Lua output
Lua doesn't have the 0oNNN syntax for octal integers, only decimal and hexadecimal, hence those can be passed trough as is while octal needs special treatment.
This commit is contained in:
parent
096497cdfc
commit
ba90b795da
@ -184,7 +184,12 @@ func (le *luaEncoder) encodeAny(writer io.Writer, node *yaml.Node) error {
|
|||||||
return writeString(writer, strings.ToLower(node.Value))
|
return writeString(writer, strings.ToLower(node.Value))
|
||||||
case "!!int":
|
case "!!int":
|
||||||
if strings.HasPrefix(node.Value, "0o") {
|
if strings.HasPrefix(node.Value, "0o") {
|
||||||
return fmt.Errorf("Lua encoder NYI -- octal") // FIXME
|
var octalValue int
|
||||||
|
err := node.Decode(&octalValue)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return writeString(writer, fmt.Sprintf("%d", octalValue))
|
||||||
}
|
}
|
||||||
return writeString(writer, strings.ToLower(node.Value))
|
return writeString(writer, strings.ToLower(node.Value))
|
||||||
case "!!float":
|
case "!!float":
|
||||||
|
|||||||
@ -46,8 +46,8 @@ var luaScenarios = []formatScenario{
|
|||||||
{
|
{
|
||||||
skipDoc: true,
|
skipDoc: true,
|
||||||
description: "Scalar int",
|
description: "Scalar int",
|
||||||
input: "- 1\n- 2\n- 0x10\n- -999\n",
|
input: "- 1\n- 2\n- 0x10\n- 0o30\n- -999\n",
|
||||||
expected: "return {1,2,0x10,-999,};\n",
|
expected: "return {1,2,0x10,24,-999,};\n",
|
||||||
scenarioType: "encode",
|
scenarioType: "encode",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user