(t *testing.T)
| 15 | } |
| 16 | |
| 17 | func TestParse(t *testing.T) { |
| 18 | testCases := map[string]*testCase{ |
| 19 | "Single Replace": { |
| 20 | input: " test abc ${Test} ", |
| 21 | replace: func(value string) (interface{}, error) { return "test", nil }, |
| 22 | output: " test abc test ", |
| 23 | }, |
| 24 | "Var Name 2": { |
| 25 | input: " test abc ${Test} ", |
| 26 | replace: func(value string) (interface{}, error) { |
| 27 | if value != "Test" { |
| 28 | return "", errors.New("unexpected var name") |
| 29 | } |
| 30 | return "test", nil |
| 31 | }, |
| 32 | output: " test abc test ", |
| 33 | }, |
| 34 | "Var Name": { |
| 35 | input: " test abc $!{Test} ", |
| 36 | replace: func(value string) (interface{}, error) { |
| 37 | if value != "Test" { |
| 38 | return "", errors.New("unexpected var name") |
| 39 | } |
| 40 | return "test", nil |
| 41 | }, |
| 42 | output: " test abc test ", |
| 43 | }, |
| 44 | "Single Escape": { |
| 45 | input: " test abc $${Test} ", |
| 46 | replace: func(value string) (interface{}, error) { return "", errors.New("Shouldn't match at all") }, |
| 47 | output: " test abc ${Test} ", |
| 48 | }, |
| 49 | "Single Escape 2": { |
| 50 | input: " test abc $$${Test} ", |
| 51 | replace: func(value string) (interface{}, error) { return "", errors.New("Shouldn't match at all") }, |
| 52 | output: " test abc $${Test} ", |
| 53 | }, |
| 54 | "Multiple Replace": { |
| 55 | input: " test ${ABC}${Test} abc $${Test}${Test} ", |
| 56 | replace: func(value string) (interface{}, error) { return "test", nil }, |
| 57 | output: " test testtest abc ${Test}test ", |
| 58 | }, |
| 59 | "Multiple Replace 2": { |
| 60 | input: "${Test}${Test}${Test}", |
| 61 | replace: func(value string) (interface{}, error) { return value, nil }, |
| 62 | output: "TestTestTest", |
| 63 | }, |
| 64 | "Return integer": { |
| 65 | input: "${integer}", |
| 66 | replace: func(value string) (interface{}, error) { return "1", nil }, |
| 67 | output: "1", |
| 68 | }, |
| 69 | "Return bool": { |
| 70 | input: "${bool}", |
| 71 | replace: func(value string) (interface{}, error) { return "true", nil }, |
| 72 | output: "true", |
| 73 | }, |
| 74 | "Return error": { |
nothing calls this directly
no test coverage detected