| 10 | ) |
| 11 | |
| 12 | func Test_Write(t *testing.T) { |
| 13 | type input struct { |
| 14 | in []string |
| 15 | re *regexp.Regexp |
| 16 | repl string |
| 17 | } |
| 18 | type output struct { |
| 19 | wantsErr bool |
| 20 | out string |
| 21 | length int |
| 22 | } |
| 23 | tests := []struct { |
| 24 | name string |
| 25 | input input |
| 26 | output output |
| 27 | }{ |
| 28 | { |
| 29 | name: "single line input", |
| 30 | input: input{ |
| 31 | in: []string{"some input line that has wrong information"}, |
| 32 | re: regexp.MustCompile("wrong"), |
| 33 | repl: "right", |
| 34 | }, |
| 35 | output: output{ |
| 36 | wantsErr: false, |
| 37 | out: "some input line that has right information", |
| 38 | length: 42, |
| 39 | }, |
| 40 | }, |
| 41 | { |
| 42 | name: "multiple line input", |
| 43 | input: input{ |
| 44 | in: []string{"multiple lines\nin this\ninput lines"}, |
| 45 | re: regexp.MustCompile("lines"), |
| 46 | repl: "tests", |
| 47 | }, |
| 48 | output: output{ |
| 49 | wantsErr: false, |
| 50 | out: "multiple tests\nin this\ninput tests", |
| 51 | length: 34, |
| 52 | }, |
| 53 | }, |
| 54 | { |
| 55 | name: "no matches", |
| 56 | input: input{ |
| 57 | in: []string{"this line has no matches"}, |
| 58 | re: regexp.MustCompile("wrong"), |
| 59 | repl: "right", |
| 60 | }, |
| 61 | output: output{ |
| 62 | wantsErr: false, |
| 63 | out: "this line has no matches", |
| 64 | length: 24, |
| 65 | }, |
| 66 | }, |
| 67 | { |
| 68 | name: "no output", |
| 69 | input: input{ |