test cases sourced from tldp.org http://www.tldp.org/LDP/abs/html/parameter-substitution.html
(t *testing.T)
| 6 | // http://www.tldp.org/LDP/abs/html/parameter-substitution.html |
| 7 | |
| 8 | func TestExpand(t *testing.T) { |
| 9 | var expressions = []struct { |
| 10 | params map[string]string |
| 11 | input string |
| 12 | output string |
| 13 | }{ |
| 14 | // text-only |
| 15 | { |
| 16 | params: map[string]string{}, |
| 17 | input: "abcdEFGH28ij", |
| 18 | output: "abcdEFGH28ij", |
| 19 | }, |
| 20 | // length |
| 21 | { |
| 22 | params: map[string]string{"var01": "abcdEFGH28ij"}, |
| 23 | input: "${#var01}", |
| 24 | output: "12", |
| 25 | }, |
| 26 | // uppercase first |
| 27 | { |
| 28 | params: map[string]string{"var01": "abcdEFGH28ij"}, |
| 29 | input: "${var01^}", |
| 30 | output: "AbcdEFGH28ij", |
| 31 | }, |
| 32 | // uppercase |
| 33 | { |
| 34 | params: map[string]string{"var01": "abcdEFGH28ij"}, |
| 35 | input: "${var01^^}", |
| 36 | output: "ABCDEFGH28IJ", |
| 37 | }, |
| 38 | // lowercase first |
| 39 | { |
| 40 | params: map[string]string{"var01": "ABCDEFGH28IJ"}, |
| 41 | input: "${var01,}", |
| 42 | output: "aBCDEFGH28IJ", |
| 43 | }, |
| 44 | // lowercase |
| 45 | { |
| 46 | params: map[string]string{"var01": "ABCDEFGH28IJ"}, |
| 47 | input: "${var01,,}", |
| 48 | output: "abcdefgh28ij", |
| 49 | }, |
| 50 | // substring with position |
| 51 | { |
| 52 | params: map[string]string{"path_name": "/home/bozo/ideas/thoughts.for.today"}, |
| 53 | input: "${path_name:11}", |
| 54 | output: "ideas/thoughts.for.today", |
| 55 | }, |
| 56 | // substring with position and length |
| 57 | { |
| 58 | params: map[string]string{"path_name": "/home/bozo/ideas/thoughts.for.today"}, |
| 59 | input: "${path_name:11:5}", |
| 60 | output: "ideas", |
| 61 | }, |
| 62 | // default not used |
| 63 | { |
| 64 | params: map[string]string{"var": "abc"}, |
| 65 | input: "${var=xyz}", |
nothing calls this directly
no test coverage detected
searching dependent graphs…