37 lines
857 B
Go
37 lines
857 B
Go
package extract
|
|
|
|
import (
|
|
"context"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestGrepIPv4(t *testing.T) {
|
|
in := "a 1.2.3.4 b 999.2.3.4 c\nx 10.0.0.1 y"
|
|
var got []string
|
|
err := Grep(context.Background(), strings.NewReader(in), Options{Mode: ModeIP}, func(s string) {
|
|
got = append(got, s)
|
|
})
|
|
if err != nil {
|
|
t.Fatalf("Grep: %v", err)
|
|
}
|
|
// Candidate matcher intentionally returns 999.2.3.4 too; validation happens elsewhere.
|
|
if len(got) != 3 {
|
|
t.Fatalf("got %d matches: %#v", len(got), got)
|
|
}
|
|
}
|
|
|
|
func TestGrepMAC(t *testing.T) {
|
|
in := "aa:bb:cc:dd:ee:ff aabb.ccdd.eeff 00-11-22-33-44-55"
|
|
var got []string
|
|
err := Grep(context.Background(), strings.NewReader(in), Options{Mode: ModeMAC}, func(s string) {
|
|
got = append(got, s)
|
|
})
|
|
if err != nil {
|
|
t.Fatalf("Grep: %v", err)
|
|
}
|
|
if len(got) != 3 {
|
|
t.Fatalf("got %d matches: %#v", len(got), got)
|
|
}
|
|
}
|