Skip to content

Commit

Permalink
Fix imports
Browse files Browse the repository at this point in the history
  • Loading branch information
alxarch committed Feb 11, 2019
1 parent 20409b2 commit c45e1c6
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 46 deletions.
7 changes: 0 additions & 7 deletions arguments.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,13 +200,6 @@ func splitArgV(s string) (string, string) {
return s, ""
}

func peekArg(args []string) (string, bool) {
if len(args) > 0 {
return args[0], true
}
return "", false
}

func (p *argParser) Eval() *Eval {
if p.eval == nil {
p.eval = new(Eval)
Expand Down
70 changes: 35 additions & 35 deletions arguments_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,14 @@ package ycat_test
import (
"bytes"
"context"
"fmt"
"io"
"strings"
"testing"

"github.com/alxarch/ycat"
)

func fullTest(t *testing.T) {
t.Helper()

}

type nopCloser struct {
io.Writer
}
Expand All @@ -24,43 +20,47 @@ func (nopCloser) Close() error {
}
func TestParseArgs(t *testing.T) {
type TestCase struct {
Args []string
Help bool
Err bool
NumTasks int
Stdin string
Output string
Args []string
Stdin string
Stdout string
}
tcs := []TestCase{
{nil, false, false, 2, "1", "1\n"},
{[]string{"testdata/foo.yaml"}, false, false, 2, "", "foo: bar\n"},
{[]string{"testdata/foo.yaml", "-e", `x + {bar: "baz"}`}, false, false, 2, "", "foo: bar\nbar: baz\n"},
{nil, "1", "1\n"},
{[]string{"-n"}, "", "null\n"},
{[]string{"-n", "-v", "y==foo", "-e", "y"}, "", "foo\n"},
{[]string{"-n", "--input-var", "y", "-e", "y"}, "", "null\n"},
{[]string{"testdata/foo.yaml", "-i", "foo=testdata/foo.libsonnet", "-e", "foo.hello(x, 'world')"}, "", "foo: bar\nname: world\n"},
{[]string{"testdata/foo.yaml"}, "", "foo: bar\n"},
{[]string{"-y", "testdata/foo.yaml"}, "", "foo: bar\n"},
{[]string{"testdata/foo.yaml", "-o", "j"}, "", `{"foo":"bar"}` + "\n"},
{[]string{"testdata/foo.yaml", "testdata/bar.json"}, "", "foo: bar\n---\nbar: foo\n"},
{[]string{"testdata/foo.yaml", "testdata/bar.json", "-a"}, "", "- foo: bar\n- bar: foo\n"},
{[]string{
"testdata/foo.yaml",
"-e", `{bar: "baz"} + x`,
}, "", "bar: baz\nfoo: bar\n"},
// {[]string{""}, false, false, 2, "1", "1\n"},
}
for i, tc := range tcs {
buf := &bytes.Buffer{}
stdout := &nopCloser{buf}
stdin := strings.NewReader(tc.Stdin)
tasks, help, err := ycat.ParseArgs(tc.Args, stdin, stdout)
if err != nil {
t.Fatal(i, err)
}
if len(tasks) != tc.NumTasks {
t.Errorf("%s Invalid tasks %d != %d", tc.Args, len(tasks), tc.NumTasks)
}
if help != tc.Help {
t.Errorf("Invalid help")
}

p := ycat.MakePipeline(context.Background(), tasks...)
for err := range p.Errors() {
name := fmt.Sprintf("%v", tc.Args)
t.Run(name, func(t *testing.T) {
buf := &bytes.Buffer{}
stdout := &nopCloser{buf}
stdin := strings.NewReader(tc.Stdin)
tasks, _, err := ycat.ParseArgs(tc.Args, stdin, stdout)
if err != nil {
t.Error(err)
t.Fatal(i, err)
}
p := ycat.MakePipeline(context.Background(), tasks...)
for err := range p.Errors() {
if err != nil {
t.Error(err)
}
}
if buf.String() != tc.Stdout {
t.Errorf("Wrong output: %q != %q", buf.String(), tc.Stdout)
}
}
if buf.String() != tc.Output {
t.Errorf("%#v Wrong output: %q != %q", tc.Args, buf.String(), tc.Output)
}
})
}

}
8 changes: 4 additions & 4 deletions eval.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,14 @@ func (v Var) Render(w *strings.Builder, name string) {
case FileVar:
switch path.Ext(v.Value) {
case ".json", ".libsonnet", ".jsonnet":
w.WriteString(`import("`)
w.WriteString(`import "`)
case ".yaml", ".yml":
w.WriteString(`importyaml("`)
w.WriteString(`importyaml "`)
default:
w.WriteString(`importstr("`)
w.WriteString(`importstr "`)
}
w.WriteString(v.Value)
w.WriteString("\");\n")
w.WriteString("\";\n")
default:
w.WriteString(`std.extVar("`)
w.WriteString(name)
Expand Down
3 changes: 3 additions & 0 deletions testdata/foo.libsonnet
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
hello(x, name):: x + {name: name},
}

0 comments on commit c45e1c6

Please sign in to comment.