Skip to content

Commit 9264278

Browse files
committed
Clean up comments and tests
1 parent 715d26f commit 9264278

5 files changed

Lines changed: 26 additions & 38 deletions

File tree

src/algo/algo.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ func bonusAt(input *util.Chars, idx int) int16 {
304304

305305
func normalizeRune(r rune) rune {
306306
// Every key of the map folds to ASCII, so a rune the bitmap rejects cannot
307-
// be in it. TestNormalizedKeysAreFlagged pins that.
307+
// be in it. TestNormalizedKeysAreFlagged verifies that.
308308
if !util.MayFoldToAscii(r) {
309309
return r
310310
}

src/algo/fastpath_equiv_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package algo
22

33
// Equivalence tests for the single- and two-character fast paths against the
4-
// general FuzzyMatchV2 algorithm, which serves as the oracle.
4+
// general FuzzyMatchV2 algorithm, which serves as the reference.
55
//
66
// Two complementary strategies:
77
// - Exhaustive: every string up to a fixed length over an alphabet that

src/algo/runeprefilter_test.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ func foldForTest(r rune, normalize bool) rune {
2929
}
3030

3131
// The prefilter is only safe on items whose runes cannot become ASCII. This
32-
// pins util.MayFoldToAscii as a superset of the runes that actually can, over
33-
// the whole Unicode range and both normalization modes. If normalize.go or the
34-
// Go unicode tables change, this fails.
32+
// verifies util.MayFoldToAscii as a superset of the runes that actually can,
33+
// over the whole Unicode range and both normalization modes. If normalize.go
34+
// or the Go unicode tables change, this fails.
3535
func TestMayFoldToAsciiIsSuperset(t *testing.T) {
3636
missed := 0
3737
for r := rune(utf8.RuneSelf); r <= unicode.MaxRune; r++ {
@@ -51,8 +51,8 @@ func TestMayFoldToAsciiIsSuperset(t *testing.T) {
5151
}
5252
}
5353

54-
// Scripts that must stay unflagged, otherwise the prefilter never engages for
55-
// them and Step C buys nothing.
54+
// Scripts that must stay unflagged, otherwise the prefilter never runs for
55+
// them and Step C has no effect.
5656
func TestMayFoldToAsciiExcludesMajorScripts(t *testing.T) {
5757
for _, s := range []struct {
5858
name string
@@ -62,9 +62,9 @@ func TestMayFoldToAsciiExcludesMajorScripts(t *testing.T) {
6262
{"Arabic", 0x0600, 0x06FF}, {"Thai", 0x0E00, 0x0E7F}, {"Devanagari", 0x0900, 0x097F},
6363
{"CJK", 0x4E00, 0x9FFF}, {"Hangul", 0xAC00, 0xD7A3}, {"kana", 0x3040, 0x30FF},
6464
{"box drawing", 0x2500, 0x257F}, {"emoji", 0x1F300, 0x1FAFF},
65-
// These sit between the Latin blocks and were swallowed by an earlier,
66-
// wider grouping of foldableRanges. General Punctuation is the costly
67-
// one: curly quotes, en and em dashes and the ellipsis live there.
65+
// These sit between the Latin blocks and were included in an earlier,
66+
// wider grouping of foldableRanges. General Punctuation matters most:
67+
// curly quotes, en and em dashes and the ellipsis are in it.
6868
{"Greek Extended", 0x1F00, 0x1FFF}, {"General Punctuation", 0x2000, 0x206F},
6969
{"Currency Symbols", 0x20A0, 0x20CF}, {"CJK Symbols", 0x3000, 0x303F},
7070
} {
@@ -257,7 +257,7 @@ func TestNormalizeRuneUnchangedByGuard(t *testing.T) {
257257

258258
// Step G lets non-ASCII pattern runes use the scan, but only when no other
259259
// rune can transform into them. Being uncased is not sufficient: U+00DF has no
260-
// simple uppercase yet U+1E9E lowercases onto it. This pins the guard against
260+
// simple uppercase yet U+1E9E lowercases onto it. This checks the guard against
261261
// the full preimage relation over all of Unicode.
262262
func TestRunePrefilterableGuardIsSound(t *testing.T) {
263263
preimage := map[rune][]rune{}
@@ -306,7 +306,7 @@ func TestRunePrefilterableGuardIsSound(t *testing.T) {
306306
}
307307
}
308308

309-
// The Step G path must actually engage and reject, otherwise the equivalence
309+
// The Step G path must actually run and reject, otherwise the equivalence
310310
// test above proves nothing about non-ASCII patterns.
311311
func TestNonAsciiPatternPrefilterEngages(t *testing.T) {
312312
rng := rand.New(rand.NewSource(6))
@@ -413,7 +413,7 @@ func FuzzRunePrefilter(f *testing.F) {
413413
}
414414
chars := util.ToChars([]byte(input))
415415
if chars.IsBytes() {
416-
return // byte mode is the existing fuzzers' territory
416+
return // byte mode is covered by the existing fuzzers
417417
}
418418
for _, cs := range []bool{false, true} {
419419
for _, norm := range []bool{false, true} {

src/util/chars.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ type Chars struct {
3636
// Rune ranges that case folding or normalization can turn into ASCII, derived
3737
// from algo's normalization table and unicode.ToLower, then merged. They are a
3838
// superset of the exact set, which TestMayFoldToAsciiIsSuperset in the algo
39-
// package pins. Grouped tightly on purpose: a wider merge would swallow Greek
40-
// Extended, General Punctuation and the currency and letterlike blocks, and
41-
// every line holding a curly quote or an em dash would then lose the
39+
// package verifies. Grouped tightly on purpose: a wider merge would include
40+
// Greek Extended, General Punctuation and the currency and letterlike blocks,
41+
// and every line holding a curly quote or an em dash would then lose the
4242
// prefilter. Cyrillic, Greek, Hebrew, Arabic, Thai, Devanagari, CJK, Hangul,
4343
// kana, emoji, punctuation and box drawing are all outside.
4444
const (

src/util/chars_test.go

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -194,31 +194,19 @@ func TestCharsLinesWrapWord(t *testing.T) {
194194
t.Errorf("Expected first line 'abcdefghij', got %q", string(lines2[0]))
195195
}
196196

197-
// Tab as word boundary
198-
chars3 := ToChars([]byte("hello\tworld"))
199-
lines3, _ := chars3.Lines(false, 100, 7, 0, 8, true)
200-
// "hello\t" should break at tab (width of tab at pos 5 with tabstop 8 = 3, total width = 8 > 7)
201-
// Actually RunesWidth: 'h'=1,'e'=1,'l'=1,'l'=1,'o'=1,'\t'=3 = 8 > 7, overflowIdx=5
202-
// Then word-wrap scans back and finds no space/tab before idx 5 (tab IS at idx 5 but we check line[k-1])
203-
// Wait - let me think: overflowIdx=5, we check k=5 -> line[4]='o', k=4 -> line[3]='l'... no space/tab found
204-
// Falls back to character wrap: "hello" | "\tworld"
205-
if len(lines3) < 2 {
206-
t.Errorf("Expected at least 2 lines for tab test, got %d: %v", len(lines3), lines3)
207-
}
208-
209197
// wrapWord=false still character-wraps
210-
chars4 := ToChars([]byte("hello world"))
211-
lines4, _ := chars4.Lines(false, 100, 8, 0, 8, false)
212-
if len(lines4) != 2 {
213-
t.Errorf("Expected 2 lines with wrapWord=false, got %d: %v", len(lines4), lines4)
198+
chars3 := ToChars([]byte("hello world"))
199+
lines3, _ := chars3.Lines(false, 100, 8, 0, 8, false)
200+
if len(lines3) != 2 {
201+
t.Errorf("Expected 2 lines with wrapWord=false, got %d: %v", len(lines3), lines3)
214202
}
215-
if string(lines4[0]) != "hello wo" {
216-
t.Errorf("Expected first line 'hello wo', got %q", string(lines4[0]))
203+
if string(lines3[0]) != "hello wo" {
204+
t.Errorf("Expected first line 'hello wo', got %q", string(lines3[0]))
217205
}
218206
}
219207

220-
// Chars is one per input line, so its size is load-bearing. It has no spare
221-
// padding, which is why new state goes in the flags byte rather than a field.
208+
// Chars is one per input line, so its size matters. It has no spare padding,
209+
// which is why new state goes in the flags byte rather than a field.
222210
// Derive the expectation from the slice header so the invariant holds on
223211
// 32-bit builds too, where the header is 12 bytes and Chars is 20.
224212
func TestCharsSize(t *testing.T) {
@@ -260,8 +248,8 @@ func TestMayFoldFlag(t *testing.T) {
260248

261249
// Runes and ToRunes alias the text in rune mode, so a consumer that mutates
262250
// what they return changes the text without updating the cached fold bit. This
263-
// pins the aliasing so the read-only contract on those methods is not silently
264-
// dropped later.
251+
// verifies the aliasing so the read-only contract on those methods is not
252+
// silently dropped later.
265253
func TestRuneSlicesAliasTheText(t *testing.T) {
266254
chars := ToChars([]byte("한글abc"))
267255
runes := chars.Runes()

0 commit comments

Comments
 (0)