From 9e578a9e19d90d948347d999da03d47c02e9cc64 Mon Sep 17 00:00:00 2001 From: BroodjeAap Date: Thu, 11 Aug 2022 19:10:05 +0000 Subject: [PATCH] added tests for regex match --- scraping_test.go | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/scraping_test.go b/scraping_test.go index a1adeaa..0413133 100644 --- a/scraping_test.go +++ b/scraping_test.go @@ -123,6 +123,37 @@ func TestFilterReplace(t *testing.T) { } } +func TestFilterMatch(t *testing.T) { + var tests = []struct { + Input string + Query string + Want []string + }{ + {"0123456789", "0123|789", []string{"0123", "789"}}, + {"0123456789", "abc|321", []string{}}, + {"0123456789", "[0-9]{3}", []string{"012", "345", "678"}}, + {"世界日本語", "日本", []string{"日本"}}, + {"世界日本語_世界日本語_世界日本語", "日本", []string{"日本", "日本", "日本"}}, + } + + for _, test := range tests { + testname := fmt.Sprintf("%s", test.Query) + t.Run(testname, func(t *testing.T) { + want := []string{} + getFilterResultMatch( + test.Input, + &Filter{ + From: test.Query, + }, + &want, + ) + if !reflect.DeepEqual(test.Want, want) { + t.Errorf("Got %s, want %s", want, test.Want) + } + }) + } +} + func TestFilterSubstring(t *testing.T) { var tests = []struct { Input string