summaryrefslogtreecommitdiff
path: root/re_test.go
blob: 21aa15f8a1b4ffbd73dcbbaa0abf2ef3c8770290 (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
29
30
31
32
33
34
package main

import "testing"

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