mirror of
https://github.com/TECHNOFAB11/docsonnet.git
synced 2026-02-02 07:35:11 +01:00
feat(lib): fn.withArgs
This commit is contained in:
parent
0d8cf83b56
commit
4c6f532e05
6 changed files with 199 additions and 127 deletions
|
|
@ -98,9 +98,13 @@ func loadField(name string, field map[string]interface{}, parent map[string]inte
|
|||
}
|
||||
|
||||
func loadFn(name string, msi map[string]interface{}) Field {
|
||||
h, ok := msi["help"].(string)
|
||||
if !ok {
|
||||
h = ""
|
||||
}
|
||||
fn := Function{
|
||||
Name: name,
|
||||
Help: msi["help"].(string),
|
||||
Help: h,
|
||||
}
|
||||
if args, ok := msi["args"]; ok {
|
||||
fn.Args = loadArgs(args.([]interface{}))
|
||||
|
|
|
|||
48
pkg/render/render_test.go
Normal file
48
pkg/render/render_test.go
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
package render
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/sh0rez/docsonnet/pkg/docsonnet"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestSortFields(t *testing.T) {
|
||||
api := docsonnet.Fields{
|
||||
"new": dfn(),
|
||||
"newNamed": dfn(),
|
||||
|
||||
"aaa": dfn(),
|
||||
"bbb": dobj(),
|
||||
"ccc": dfn(),
|
||||
|
||||
"metadata": dobj(),
|
||||
}
|
||||
|
||||
sorted := []string{
|
||||
"new",
|
||||
"newNamed",
|
||||
|
||||
"aaa",
|
||||
"ccc",
|
||||
|
||||
"bbb",
|
||||
"metadata",
|
||||
}
|
||||
|
||||
res := sortFields(api)
|
||||
|
||||
assert.Equal(t, sorted, res)
|
||||
}
|
||||
|
||||
func dobj() docsonnet.Field {
|
||||
return docsonnet.Field{
|
||||
Object: &docsonnet.Object{},
|
||||
}
|
||||
}
|
||||
|
||||
func dfn() docsonnet.Field {
|
||||
return docsonnet.Field{
|
||||
Function: &docsonnet.Function{},
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue