summaryrefslogtreecommitdiff
path: root/re_test.go
blob: 447c60f114a258228d2df1bf6b533e1e48cf8dde (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
package main

import "testing"

func TestRE(t *testing.T) {
	testCases := []struct {
		r, s, x string
	}{
		{"s/ddd/xxx/", "abd ddd xxx", "abd xxx xxx"},
		{"s,ddd,xxx,", "abd ddd xxx", "abd xxx xxx"},
		{"s/ddd/xxx", "abd ddd xxx", "abd xxx xxx"},
		{"s/x$/X", "abd ddd xxx", "abd ddd xxX"},
		{"s/ /A", "abd ddd xxx", "abdAdddAxxx"},
		{"s///", "abd ddd xxx", "abd ddd xxx"},
		{"s//", "abd ddd xxx", "abd ddd xxx"},
		{"s/", "abd ddd xxx", ""},
		{"S//", "abd ddd xxx", ""},
		{"s/^d/X", "abd ddd xxx", "abd ddd xxx"},
	}
	for _, tc := range testCases {
		t.Run(tc.r, func(t *testing.T) {
			res := re(tc.s, tc.r)
			if res != tc.x {
				t.Errorf("got %q, want %q", res, tc.x)
			}
		})
	}
}