feat(json2go): support manual input

This commit is contained in:
Oleksandr Smirnov 2025-12-08 17:38:43 +02:00
parent 72dd68f25f
commit bc3ce2fdf4
No known key found for this signature in database
4 changed files with 18 additions and 2 deletions

View file

@ -72,8 +72,9 @@ end)
-- :GoJson -- :GoJson
cmd("GoJson", function(opts) cmd("GoJson", function(opts)
require("gopher.json2go").json2go(opts.fargs[1]) local inp = ((opts.args ~= "" and opts.args) or nil)
end, "?") require("gopher.json2go").json2go(inp)
end, "*")
-- :GoTest -- :GoTest
cmd("GoTestAdd", function() cmd("GoTestAdd", function()

2
spec/fixtures/json2go/manual_input.go vendored Normal file
View file

@ -0,0 +1,2 @@
package main

View file

@ -0,0 +1,7 @@
package main
type AutoGenerated struct {
User struct {
Name string `json:"name"`
} `json:"user"`
}

View file

@ -14,6 +14,12 @@ json2go["should convert interativly"] = function()
end end
json2go["should convert argument"] = function() json2go["should convert argument"] = function()
local rs = t.setup_test("json2go/manual", child, { 2, 0 })
child.cmd [[GoJson {"user": {"name": "user-ovic"}}]]
child.cmd "write"
t.eq(t.readfile(rs.tmp), rs.fixtures.output)
t.cleanup(rs)
end end
return T return T