Fumitoshi Ukai | e520f26 | 2015-03-31 17:27:03 +0900 | [diff] [blame] | 1 | package main |
| 2 | |
| 3 | import ( |
| 4 | "reflect" |
| 5 | "testing" |
| 6 | ) |
| 7 | |
| 8 | func 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 Hamaji | 21a9b5f | 2015-04-01 02:42:59 +0900 | [diff] [blame] | 50 | } else if got, want := tc.in[rest:], tc.rest; got != want { |
Fumitoshi Ukai | e520f26 | 2015-03-31 17:27:03 +0900 | [diff] [blame] | 51 | t.Errorf(`parseExpr(%q)=_, %q, _; want _, %q, _`, tc.in, got, want) |
| 52 | } |
| 53 | } |
| 54 | } |