47 lines
1.1 KiB
Go
47 lines
1.1 KiB
Go
package punctuation
|
||
|
||
import (
|
||
"context"
|
||
"strings"
|
||
"testing"
|
||
)
|
||
|
||
func TestCleanExcessive(t *testing.T) {
|
||
cases := []struct {
|
||
in, want string
|
||
}{
|
||
{"привет,,", "привет,"},
|
||
{"привет,.", "привет,"},
|
||
{"hello..", "hello."},
|
||
{"what??", "what?"},
|
||
{"ok!!!", "ok!"},
|
||
{"а. б. в.", "а. б. в."},
|
||
}
|
||
for _, tc := range cases {
|
||
got := CleanExcessive(tc.in)
|
||
if got != tc.want {
|
||
t.Errorf("CleanExcessive(%q) = %q, want %q", tc.in, got, tc.want)
|
||
}
|
||
}
|
||
}
|
||
|
||
func TestHasTerminalPunct_comma(t *testing.T) {
|
||
if !hasTerminalPunct("привет,") {
|
||
t.Fatal("comma should count as terminal for heuristic")
|
||
}
|
||
if hasTerminalPunct("привет") {
|
||
t.Fatal("bare word should not")
|
||
}
|
||
}
|
||
|
||
func TestHeuristic_noCommaPeriod(t *testing.T) {
|
||
h := Heuristic{}
|
||
out, err := h.Restore(context.Background(), "привет, мир", "ru")
|
||
if err != nil {
|
||
t.Fatal(err)
|
||
}
|
||
if strings.Contains(out, ",.") {
|
||
t.Fatalf("unexpected comma+period: %q", out)
|
||
}
|
||
}
|