More work on repeated string summarization.

This commit is contained in:
Storm Dragon committed 2026-10-29 14:45:51 -04:00
1 parent 3cf41e662c
commit 47f18fdd28
7 files changed
+122 -34

No files matched your search

+21 -7
View File
@@ -32,13 +32,17 @@ func TestTextSubstitutionsAndBoundaries(t *testing.T) {
{"(#####)", " 5 number "},
{"{#####}", " 5 number "},
{"<#####>", " 5 number "},
{"[#####-----]", " 5 number 5 dash "},
{"[-----#####]", " 5 dash 5 number "},
{"[#####----#####]", " 5 number 4 dash 5 number "},
{"[#####--]", " 5 number dash dash "},
{"Oo", "WTF?"},
} {
if got := processor.Process_text(trial.text, "some", options); got != trial.want {
t.Errorf("%q: %q, want %q", trial.text, got, trial.want)
}
}
for _, text := range []string{"hello :)!", "path/to:)file", "https://example.invalid/:)", "https://example.invalid/:-/", "(o_O)", "###", "##--##", "a####b", "../....", "https://example.invalid/####", "10000", "aaaa", "🙂🙂🙂🙂", "", "[]", "[###]", "[####)", "[##--##]", "[a####b]", "[../....]", "[https://example.invalid/####]"} {
for _, text := range []string{"hello :)!", "path/to:)file", "https://example.invalid/:)", "https://example.invalid/:-/", "(o_O)", "###", "##--##", "a####b", "../....", "https://example.invalid/####", "10000", "aaaa", "🙂🙂🙂🙂", "", "[]", "[###]", "[####)", "[##--##]", "[a####b]", "[https://example.invalid/####]"} {
for _, level := range Levels() {
if got, want := processor.Process_text(text, level, options), processor.Text(text, level); got != want {
t.Errorf("%q, %s changed ordinary processing: %q, want %q", text, level, got, want)
@@ -93,6 +97,9 @@ func TestSubstitutionOptionsAndProfileNames(t *testing.T) {
if got := custom.Process_text("////", "some", options); got != "4 path/separator" {
t.Fatal("custom name changed or processed twice", got)
}
if got := custom.Process_text("[////####]", "some", options); got != " 4 path/separator 4 number " {
t.Fatal("mixed summary reprocessed custom name", got)
}
french, _, err := Load([]string{"../../config/punctuation/fr.toml"})
if err != nil {
t.Fatal(err)
@@ -118,12 +125,19 @@ func TestBracketedRepeatedSymbolsRespectOptionsAndLevels(t *testing.T) {
{RepeatedSymbols: true, RepeatedSymbolsMin: 6},
{RepeatedSymbols: true, RepeatedSymbolsMin: 4},
} {
want := processor.Text("[#####]", level)
if options.RepeatedSymbols && options.RepeatedSymbolsMin == 4 && level != "none" {
want = processor.Text("[", level) + "5 number" + processor.Text("]", level)
}
if got := processor.Process_text("[#####]", level, options); got != want {
t.Errorf("level %s, options %+v: got %q, want %q", level, options, got, want)
for _, interior := range []string{"#####", "#####-----"} {
text := "[" + interior + "]"
want := processor.Text(text, level)
if options.RepeatedSymbols && options.RepeatedSymbolsMin == 4 && level != "none" {
summary := "5 number"
if interior == "#####-----" {
summary += " 5 dash"
}
want = processor.Text("[", level) + summary + processor.Text("]", level)
}
if got := processor.Process_text(text, level, options); got != want {
t.Errorf("%q, level %s, options %+v: got %q, want %q", text, level, options, got, want)
}
}
}
}