File: regexp_test.go

package info (click to toggle)
golang-github-containers-storage 1.59.1%2Bds1-2
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 4,184 kB
  • sloc: sh: 630; ansic: 389; makefile: 143; awk: 12
file content (37 lines) | stat: -rw-r--r-- 650 bytes parent folder | download | duplicates (5)
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
35
36
37
package regexp

import (
	"testing"
)

type partOfRegexp interface {
	FindStringSubmatch(s string) []string
	MatchString(s string) bool
	NumSubexp() int
}

var _ partOfRegexp = &Regexp{}

func TestMatchString(t *testing.T) {
	r := Delayed(`[0-9]+`)

	if !r.MatchString("100") {
		t.Fatalf("Should have matched")
	}

	if r.MatchString("test") {
		t.Fatalf("Should not have matched")
	}
}

func TestFindStringSubmatch(t *testing.T) {
	r := Delayed(`a=([0-9]+).*b=([0-9]+)`)

	if len(r.FindStringSubmatch("a=1,b=2")) != 3 {
		t.Fatalf("Should have matched 3")
	}

	if len(r.FindStringSubmatch("a=1")) != 0 {
		t.Fatalf("Should not have matched 0")
	}
}