A little improvement for repeated character handling.

This commit is contained in:
Storm Dragon committed 2026-10-30 12:25:31 -04:00
1 parent 36736725ea
commit 2c893dccb9
4 files changed
+55 -14

No files matched your search

+24 -8
View File
@@ -28,6 +28,11 @@ func TestTextSubstitutionsAndBoundaries(t *testing.T) {
{"#### ####", "4 number 4 number"},
{"##### title #####", "5 number title 5 number"},
{"////", "4 slash"},
{"+++++-----", "5 plus 5 dash"},
{"+++++--", "5 plus dash dash "},
{"--+++++", " dash dash 5 plus"},
{"+++++-----++++", "5 plus 5 dash 4 plus"},
{"[####)", " 4 number "},
{"[#####]", " 5 number "},
{"(#####)", " 5 number "},
{"{#####}", " 5 number "},
@@ -42,7 +47,7 @@ func TestTextSubstitutionsAndBoundaries(t *testing.T) {
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)
@@ -100,6 +105,9 @@ func TestSubstitutionOptionsAndProfileNames(t *testing.T) {
if got := custom.Process_text("[////####]", "some", options); got != " 4 path/separator 4 number " {
t.Fatal("mixed summary reprocessed custom name", got)
}
if got := custom.Process_text("////####", "some", options); got != "4 path/separator 4 number" {
t.Fatal("unbracketed summary reprocessed custom name", got)
}
french, _, err := Load([]string{"../../config/punctuation/fr.toml"})
if err != nil {
t.Fatal(err)
@@ -112,7 +120,7 @@ func TestSubstitutionOptionsAndProfileNames(t *testing.T) {
}
}
func TestBracketedRepeatedSymbolsRespectOptionsAndLevels(t *testing.T) {
func TestRepeatedSymbolsRespectOptionsAndLevels(t *testing.T) {
processor, _, err := Load([]string{"../../config/punctuation/default.toml"})
if err != nil {
t.Fatal(err)
@@ -125,15 +133,23 @@ func TestBracketedRepeatedSymbolsRespectOptionsAndLevels(t *testing.T) {
{RepeatedSymbols: true, RepeatedSymbolsMin: 6},
{RepeatedSymbols: true, RepeatedSymbolsMin: 4},
} {
for _, interior := range []string{"#####", "#####-----"} {
text := "[" + interior + "]"
for _, text := range []string{"[#####]", "[#####-----]", "+++++-----", "+++++..", "../...."} {
want := processor.Text(text, level)
if options.RepeatedSymbols && options.RepeatedSymbolsMin == 4 && level != "none" {
summary := "5 number"
if interior == "#####-----" {
summary += " 5 dash"
switch text {
case "[#####]":
want = processor.Text("[", level) + "5 number" + processor.Text("]", level)
case "[#####-----]":
want = processor.Text("[", level) + "5 number 5 dash" + processor.Text("]", level)
case "+++++-----":
want = "5 plus 5 dash"
case "+++++..":
want = "5 plus " + processor.Text("..", level)
case "../....":
if level == "most" || level == "all" {
want = processor.Text("..", level) + " " + processor.Text("/", level) + " 4 dot"
}
}
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)