mirror of
https://github.com/magefile/mage.git
synced 2026-10-24 06:19:18 +03:00
79 lines
1.5 KiB
Go
79 lines
1.5 KiB
Go
package parse
|
|
|
|
import (
|
|
"reflect"
|
|
"testing"
|
|
)
|
|
|
|
func TestParse(t *testing.T) {
|
|
info, err := Package("./testdata", []string{"func.go", "command.go", "alias.go", "repeating_synopsis.go", "subcommands.go"})
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
expected := []Function{
|
|
{
|
|
Name: "ReturnsNilError",
|
|
IsError: true,
|
|
Comment: "Synopsis for \"returns\" error. And some more text.",
|
|
Synopsis: `Synopsis for "returns" error.`,
|
|
},
|
|
{
|
|
Name: "ReturnsVoid",
|
|
},
|
|
{
|
|
Name: "TakesContextReturnsError",
|
|
IsError: true,
|
|
IsContext: true,
|
|
},
|
|
{
|
|
Name: "TakesContextReturnsVoid",
|
|
IsError: false,
|
|
IsContext: true,
|
|
},
|
|
{
|
|
Name: "RepeatingSynopsis",
|
|
IsError: true,
|
|
Comment: "RepeatingSynopsis chops off the repeating function name. Some more text.",
|
|
Synopsis: "chops off the repeating function name.",
|
|
},
|
|
{
|
|
Name: "Foobar",
|
|
Receiver: "Build",
|
|
IsError: true,
|
|
},
|
|
{
|
|
Name: "Baz",
|
|
Receiver: "Build",
|
|
IsError: false,
|
|
},
|
|
}
|
|
|
|
// DefaultIsError
|
|
if info.DefaultIsError != true {
|
|
t.Fatalf("expected DefaultIsError to be true")
|
|
}
|
|
|
|
// DefaultName
|
|
if info.DefaultName != "ReturnsNilError" {
|
|
t.Fatalf("expected DefaultName to be ReturnsNilError")
|
|
}
|
|
|
|
if info.Aliases["void"] != "ReturnsVoid" {
|
|
t.Fatalf("expected alias of void to be ReturnsVoid")
|
|
}
|
|
|
|
for _, fn := range expected {
|
|
found := false
|
|
for _, infoFn := range info.Funcs {
|
|
if reflect.DeepEqual(fn, infoFn) {
|
|
found = true
|
|
break
|
|
}
|
|
}
|
|
if !found {
|
|
t.Fatalf("expected:\n%#v\n\nto be in:\n%#v", fn, info.Funcs)
|
|
}
|
|
}
|
|
}
|