diff --git a/scraping_test.go b/scraping_test.go index 1524d9a..cd5a21c 100644 --- a/scraping_test.go +++ b/scraping_test.go @@ -145,6 +145,7 @@ func TestFilterReplace(t *testing.T) { Var2 string Want string }{ + // remove tests {"0123456789", "0", "", "123456789"}, {"0123456789", "9", "", "012345678"}, {"0123456789", "3456", "", "012789"}, @@ -152,9 +153,25 @@ func TestFilterReplace(t *testing.T) { {"世界日本語", "世", "", "界日本語"}, {"世界日本語", "語", "", "世界日本"}, {"世界日_世界日_世界日", "界", "", "世日_世日_世日"}, - // TODO add replace tests - // TODO add regex tests - // TODO add regex replace tests + + // replace tests + {"0123456789", "0", "a", "a123456789"}, + {"0123456789", "9", "b", "012345678b"}, + {"0123456789", "3456", "abcd", "012abcd789"}, + {"0123456789_0123456789", "3456", "abcd", "012abcd789_012abcd789"}, + {"世界日本語", "世", "本語", "本語界日本語"}, + {"世界日本語", "語", "日", "世界日本日"}, + {"世界日_世界日_世界日", "界", "語", "世語日_世語日_世語日"}, + + // regex tests + {"0123456789", "0[0-9]{2}", "", "3456789"}, + {"0123456789", "[0-9]{2}9", "", "0123456"}, + {"0123456789", "[0-9]+", "", ""}, + {"Hello World!", "[eo]", "", "Hll Wrld!"}, + {"世界日本語", "[界本]", "", "世日語"}, + + // regex replace tests + {"123.65", "([0-9.]+)", "$1", "123.65"}, } for _, test := range tests { diff --git a/todo.md b/todo.md index a592b7b..47473f4 100644 --- a/todo.md +++ b/todo.md @@ -5,6 +5,5 @@ - trusted proxies in conf? - log things to db for cron runs - comments -- add test for regex replace with group - run/fix staticcheck - add browserless support ? \ No newline at end of file