blob: fdcdcd5b43f2d8c3324e1b1a3324442d588a6a29 [file] [log] [blame]
Shinichiro Hamajic5686fd2015-04-01 03:30:34 +09001package main
2
3import (
4 "testing"
5)
6
7func TestSubstPattern(t *testing.T) {
8 for _, tc := range []struct {
9 pat string
10 repl string
11 in string
12 want string
13 } {
14 {
15 pat: "%.c",
16 repl: "%.o",
17 in: "x.c",
18 want: "x.o",
19 },
20 {
21 pat: "c.%",
22 repl: "o.%",
23 in: "c.x",
24 want: "o.x",
25 },
26 {
27 pat: "%.c",
28 repl: "%.o",
29 in: "x.c.c",
30 want: "x.c.o",
31 },
32 {
33 pat: "%.c",
34 repl: "%.o",
35 in: "x.x y.c",
36 want: "x.x y.o",
37 },
38 {
39 pat: "%.%.c",
40 repl: "OK",
41 in: "x.%.c",
42 want: "OK",
43 },
44 {
45 pat: "x.c",
46 repl: "XX",
47 in: "x.c",
48 want: "XX",
49 },
50 {
51 pat: "x.c",
52 repl: "XX",
53 in: "x.c.c",
54 want: "x.c.c",
55 },
56 {
57 pat: "x.c",
58 repl: "XX",
59 in: "x.x.c",
60 want: "x.x.c",
61 },
62 } {
63 got := substPattern(tc.pat, tc.repl, tc.in)
64 if got != tc.want {
65 t.Errorf(`substPattern(%q,%q,%q)=%q, want %q`, tc.pat, tc.repl, tc.in, got, tc.want)
66 }
67 }
68}