From be933d241cb7abae46bbc7b10ededbb49f2afe94 Mon Sep 17 00:00:00 2001 From: Lucas Rayan Date: Sat, 22 Aug 2026 13:59:34 -0300 Subject: [PATCH] =?UTF-8?q?chore:=20mant=C3=A9m=20ASCII=20o=20c=C3=B3digo?= =?UTF-8?q?=20dos=20testes=20novos?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit O lang-lint exige que a fonte deste repositório seja ASCII, e os testes que escrevi usavam acentos em texto de exemplo. Isto teria feito o CI vermelho. Onde o acento era só texto de exemplo, foi substituído. Nos dois testes onde o acento é o que está a ser testado - que um nome de pasta acentuado sobrevive ao parser, e que uma pasta pode chamar-se "Relatorios de Marco" - fica escrito como escape Unicode, que mantém o teste a verificar exactamente a mesma coisa sem pôr o caractere na fonte. Co-Authored-By: Claude Opus 5 --- .../application/usecase/apply_rules_test.go | 6 ++-- .../usecase/manage_folders_test.go | 2 +- .../internal/domain/sieve/sieve_test.go | 28 +++++++++++-------- services/webmail/src/rules.test.ts | 11 +++++--- 4 files changed, 27 insertions(+), 20 deletions(-) diff --git a/services/protocols/internal/application/usecase/apply_rules_test.go b/services/protocols/internal/application/usecase/apply_rules_test.go index 7a7be20..1cad120 100644 --- a/services/protocols/internal/application/usecase/apply_rules_test.go +++ b/services/protocols/internal/application/usecase/apply_rules_test.go @@ -43,7 +43,7 @@ func TestRuleDecidesTheFolder(t *testing.T) { func TestMessageWithNoMatchingRuleIsUntouched(t *testing.T) { uc := newRules(&stubSieveScripts{script: filingRule}) - payload := []byte("From: amigo@example.test\r\nSubject: Almoço\r\n\r\ncorpo") + payload := []byte("From: amigo@example.test\r\nSubject: Almoco\r\n\r\ncorpo") decision := uc.For(context.Background(), uuid.New(), "me@example.test", "amigo@example.test", payload) if decision.Folder != "" || decision.Discard { @@ -85,7 +85,7 @@ func TestAFailingLookupStillDeliversTheMessage(t *testing.T) { // --- vacation ------------------------------------------------------------ const vacationRule = `require ["vacation"]; -vacation :subject "Fora do escritório" "Volto dia 30.";` +vacation :subject "Fora do escritorio" "Volto dia 30.";` func TestVacationRepliesToAPerson(t *testing.T) { uc := newRules(&stubSieveScripts{script: vacationRule}) @@ -95,7 +95,7 @@ func TestVacationRepliesToAPerson(t *testing.T) { if decision.Vacation == nil { t.Fatal("no reply was produced") } - if decision.Vacation.Subject != "Fora do escritório" { + if decision.Vacation.Subject != "Fora do escritorio" { t.Errorf("subject %q", decision.Vacation.Subject) } } diff --git a/services/protocols/internal/application/usecase/manage_folders_test.go b/services/protocols/internal/application/usecase/manage_folders_test.go index 2c97152..057bf0b 100644 --- a/services/protocols/internal/application/usecase/manage_folders_test.go +++ b/services/protocols/internal/application/usecase/manage_folders_test.go @@ -201,7 +201,7 @@ func TestRefusesAnAbsurdlyLongName(t *testing.T) { // Accents are ordinary in a Portuguese folder name. func TestAcceptsAccentedNames(t *testing.T) { store := &stubFolderStore{existing: standardFolders()} - if err := newFolders(store).Create(context.Background(), "me@example.test", "Relatórios de Março"); err != nil { + if err := newFolders(store).Create(context.Background(), "me@example.test", "Relat\u00f3rios de Mar\u00e7o"); err != nil { t.Errorf("an accented name was refused: %v", err) } } diff --git a/services/protocols/internal/domain/sieve/sieve_test.go b/services/protocols/internal/domain/sieve/sieve_test.go index b1bba00..d0cccec 100644 --- a/services/protocols/internal/domain/sieve/sieve_test.go +++ b/services/protocols/internal/domain/sieve/sieve_test.go @@ -39,7 +39,7 @@ func TestRuleFilesTheMessageInItsFolder(t *testing.T) { func TestRuleThatDoesNotMatchLeavesTheMessageAlone(t *testing.T) { out := evaluate(t, uiRule, Message{Headers: map[string][]string{ - "subject": {"Almoço amanhã"}, + "subject": {"Almoco amanha"}, }}) if out.Folder != "" { t.Errorf("an unmatched rule filed into %q", out.Folder) @@ -78,10 +78,10 @@ func TestIsRequiresTheWholeValue(t *testing.T) { // :matches is Sieve's wildcard form - * and ? - and is what the interface // should offer instead of asking a human for a regular expression. func TestMatchesUsesWildcardsNotRegex(t *testing.T) { - script := `if header :matches "From" "*@google.com" { fileinto "Relatórios"; }` + script := `if header :matches "From" "*@google.com" { fileinto "Reports"; }` if out := evaluate(t, script, Message{Headers: map[string][]string{ "from": {"noreply-dmarc-support@google.com"}, - }}); out.Folder != "Relatórios" { + }}); out.Folder != "Reports" { t.Errorf("wildcard did not match: %q", out.Folder) } if out := evaluate(t, script, Message{Headers: map[string][]string{ @@ -105,7 +105,7 @@ func TestWildcardDotIsLiteral(t *testing.T) { func TestAnyofMatchesWhenOneTestPasses(t *testing.T) { script := `if anyof (header :contains "Subject" "fatura", header :contains "From" "banco") { fileinto "Financeiro"; }` out := evaluate(t, script, Message{Headers: map[string][]string{ - "subject": {"Almoço"}, "from": {"aviso@banco.test"}, + "subject": {"Almoco"}, "from": {"aviso@banco.test"}, }}) if out.Folder != "Financeiro" { t.Errorf("anyof did not match: %q", out.Folder) @@ -186,7 +186,7 @@ func TestAddflagMarksTheMessage(t *testing.T) { // --- vacation ------------------------------------------------------------ const vacationScript = `require ["vacation"]; -vacation :subject "Fora do escritório" "Estou de férias até dia 30.";` +vacation :subject "Fora do escritorio" "Estou de ferias ate dia 30.";` func TestVacationProducesAReply(t *testing.T) { out := evaluate(t, vacationScript, Message{ @@ -196,10 +196,10 @@ func TestVacationProducesAReply(t *testing.T) { if out.Vacation == nil { t.Fatal("no vacation reply was produced") } - if out.Vacation.Subject != "Fora do escritório" { + if out.Vacation.Subject != "Fora do escritorio" { t.Errorf("subject %q", out.Vacation.Subject) } - if !strings.Contains(out.Vacation.Body, "férias") { + if !strings.Contains(out.Vacation.Body, "ferias") { t.Errorf("body %q", out.Vacation.Body) } } @@ -266,9 +266,13 @@ if header :contains "Subject" "fatura" { fileinto "Financeiro"; } # fim // A folder name is used to route mail, so it must survive intact - including // the accents a Portuguese folder name has. func TestFolderNamesKeepTheirAccents(t *testing.T) { - out := evaluate(t, `if header :contains "Subject" "x" { fileinto "Relatórios"; }`, + // Written as an escape rather than the letter itself: the source of this + // repository is kept ASCII (lang-lint), and the point of the test is that + // the accented name survives the parser intact. + accented := "Relat\u00f3rios" + out := evaluate(t, `if header :contains "Subject" "x" { fileinto "`+accented+`"; }`, Message{Headers: map[string][]string{"subject": {"x"}}}) - if out.Folder != "Relatórios" { + if out.Folder != accented { t.Errorf("folder %q", out.Folder) } } @@ -324,14 +328,14 @@ func TestMatchesSingleCharacterWildcard(t *testing.T) { // A star in the middle has to match the run between two fixed parts. func TestMatchesStarInTheMiddle(t *testing.T) { - script := `if header :matches "Subject" "Relatório * de agosto" { fileinto "X"; }` + script := `if header :matches "Subject" "Relatorio * de agosto" { fileinto "X"; }` if out := evaluate(t, script, Message{Headers: map[string][]string{ - "subject": {"Relatório mensal de agosto"}, + "subject": {"Relatorio mensal de agosto"}, }}); out.Folder != "X" { t.Errorf("star in the middle did not match: %q", out.Folder) } if out := evaluate(t, script, Message{Headers: map[string][]string{ - "subject": {"Relatório mensal de julho"}, + "subject": {"Relatorio mensal de julho"}, }}); out.Folder != "" { t.Errorf("matched despite a different tail: %q", out.Folder) } diff --git a/services/webmail/src/rules.test.ts b/services/webmail/src/rules.test.ts index de21689..e4ea5f7 100644 --- a/services/webmail/src/rules.test.ts +++ b/services/webmail/src/rules.test.ts @@ -53,8 +53,8 @@ describe("turning a rule into Sieve", () => { // a script that did not parse - so one apostrophe silently disabled every // rule the user had. it("escapes a quote in the value", () => { - const script = buildSieve([rule({ value: 'ele disse "olá"' })]); - expect(script).toContain('\\"olá\\"'); + const script = buildSieve([rule({ value: 'ele disse "ola"' })]); + expect(script).toContain('\\"ola\\"'); expect(parseSieve(script)!).toHaveLength(1); }); @@ -116,9 +116,12 @@ describe("reading rules back out of Sieve", () => { }); it("round-trips the field and the target folder", () => { - const [read] = parseSieve(buildSieve([rule({ field: "from", target: "Relatórios" })]))!; + // Escaped rather than written as the letter: this repository keeps its + // source ASCII, and an accented folder name still has to survive intact. + const accented = "Relat\u00f3rios"; + const [read] = parseSieve(buildSieve([rule({ field: "from", target: accented })]))!; expect(read.field).toBe("from"); - expect(read.target).toBe("Relatórios"); + expect(read.target).toBe(accented); }); // A script written by hand, or by a desktop client over ManageSieve, may use