blob: bdc94fb7deec30953dd29d329c77f0c5728e49b2 [file] [log] [blame]
Fumitoshi Ukaie520f262015-03-31 17:27:03 +09001package main
2
3import (
4 "reflect"
5 "testing"
6)
7
8func TestParseExpr(t *testing.T) {
9 for _, tc := range []struct {
10 in string
11 args []string
12 rest string
13 isErr bool
14 }{
15 {
16 in: "foo",
17 isErr: true,
18 },
19 {
20 in: "(foo)",
21 args: []string{"foo"},
22 },
23 {
24 in: "{foo}",
25 args: []string{"foo"},
26 },
27 {
28 in: "(lhs,rhs)",
29 args: []string{"lhs", "rhs"},
30 },
31 {
32 in: "(subst $(space),$(,),$(foo))/bar",
33 args: []string{"subst $(space)", "$(,)", "$(foo)"},
34 rest: "/bar",
35 },
36 } {
37 args, rest, err := parseExpr(tc.in)
38 if tc.isErr {
39 if err == nil {
40 t.Errorf(`parseExpr(%q)=_, _, nil; want error`, tc.in)
41 }
42 continue
43 }
44 if err != nil {
45 t.Errorf(`parseExpr(%q)=_, _, %v; want nil error`, tc.in, err)
46 continue
47 }
48 if got, want := args, tc.args; !reflect.DeepEqual(got, want) {
49 t.Errorf(`parseExpr(%q)=%q, _, _; want %q, _, _`, tc.in, got, want)
Shinichiro Hamaji21a9b5f2015-04-01 02:42:59 +090050 } else if got, want := tc.in[rest:], tc.rest; got != want {
Fumitoshi Ukaie520f262015-03-31 17:27:03 +090051 t.Errorf(`parseExpr(%q)=_, %q, _; want _, %q, _`, tc.in, got, want)
52 }
53 }
54}