Skip to content
Myr

Clean up comments and tests

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Junegunn Choi · committed by Junegunn Choi · parent 715d26f · Browse files · 5 files+26 added−38 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

5 files+26 added−38 removed

  • other:+26 added−38 removed

5 files+26 added−38 removed

modified:src/algo/algo.go+1 added-1 removed
302 unmodified lines
303}304305func normalizeRune(r rune) rune {306 // Every key of the map folds to ASCII, so a rune the bitmap rejects cannot307 // be in it. TestNormalizedKeysAreFlagged pins that.307 // be in it. TestNormalizedKeysAreFlagged verifies that.308 if !util.MayFoldToAscii(r) {309 return r310 }311
1030 unmodified lines
modified:src/algo/fastpath_equiv_test.go+1 added-1 removed
1package algo23// Equivalence tests for the single- and two-character fast paths against the4// general FuzzyMatchV2 algorithm, which serves as the oracle.4// general FuzzyMatchV2 algorithm, which serves as the reference.5//6// Two complementary strategies:7// - Exhaustive: every string up to a fixed length over an alphabet that8// covers all ASCII character classes, so every local scoring branch is
149 unmodified lines
modified:src/algo/runeprefilter_test.go+11 added-11 removed
27 unmodified lines
28 return r29}3031// The prefilter is only safe on items whose runes cannot become ASCII. This32// pins util.MayFoldToAscii as a superset of the runes that actually can, over33// the whole Unicode range and both normalization modes. If normalize.go or the34// 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.go34// or the Go unicode tables change, this fails.35func TestMayFoldToAsciiIsSuperset(t *testing.T) {36 missed := 037 for r := rune(utf8.RuneSelf); r <= unicode.MaxRune; r++ {38 if r >= 0xD800 && r <= 0xDFFF {
11 unmodified lines
50 t.Fatalf("%d runes fold to ASCII without being flagged", missed)51 }52}5354// Scripts that must stay unflagged, otherwise the prefilter never engages for55// them and Step C buys nothing.54// Scripts that must stay unflagged, otherwise the prefilter never runs for55// them and Step C has no effect.56func TestMayFoldToAsciiExcludesMajorScripts(t *testing.T) {57 for _, s := range []struct {58 name string59 lo, hi rune
1 unmodified line
61 {"Cyrillic", 0x0400, 0x04FF}, {"Greek", 0x0370, 0x03FF}, {"Hebrew", 0x0590, 0x05FF},62 {"Arabic", 0x0600, 0x06FF}, {"Thai", 0x0E00, 0x0E7F}, {"Devanagari", 0x0900, 0x097F},63 {"CJK", 0x4E00, 0x9FFF}, {"Hangul", 0xAC00, 0xD7A3}, {"kana", 0x3040, 0x30FF},64 {"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 costly67 // 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.68 {"Greek Extended", 0x1F00, 0x1FFF}, {"General Punctuation", 0x2000, 0x206F},69 {"Currency Symbols", 0x20A0, 0x20CF}, {"CJK Symbols", 0x3000, 0x303F},70 } {71 for r := s.lo; r <= s.hi; r++ {
184 unmodified lines
256}257258// Step G lets non-ASCII pattern runes use the scan, but only when no other259// rune can transform into them. Being uncased is not sufficient: U+00DF has no260// simple uppercase yet U+1E9E lowercases onto it. This pins the guard against260// simple uppercase yet U+1E9E lowercases onto it. This checks the guard against261// the full preimage relation over all of Unicode.262func TestRunePrefilterableGuardIsSound(t *testing.T) {263 preimage := map[rune][]rune{}264 for r := rune(0); r <= unicode.MaxRune; r++ {
40 unmodified lines
305 }306 }307}308309// The Step G path must actually engage and reject, otherwise the equivalence309// The Step G path must actually run and reject, otherwise the equivalence310// test above proves nothing about non-ASCII patterns.311func TestNonAsciiPatternPrefilterEngages(t *testing.T) {312 rng := rand.New(rand.NewSource(6))313 parts := []string{"漢字", "한글", "src", "conf", "/", "мир", "🎉"}
98 unmodified lines
412 return413 }414 chars := util.ToChars([]byte(input))415 if chars.IsBytes() {416 return // byte mode is the existing fuzzers' territory416 return // byte mode is covered by the existing fuzzers417 }418 for _, cs := range []bool{false, true} {419 for _, norm := range []bool{false, true} {420 p := preparePattern(pat, cs, norm)
59 unmodified lines
modified:src/util/chars_test.go+10 added-22 removed
192 unmodified lines
193 if string(lines2[0]) != "abcdefghij" {194 t.Errorf("Expected first line 'abcdefghij', got %q", string(lines2[0]))195 }196197 // Tab as word boundary198 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=5202 // 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 found204 // 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 }208197 // wrapWord=false still character-wraps210 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)202 }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]))205 }206}207220// Chars is one per input line, so its size is load-bearing. It has no spare221// 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.210// Derive the expectation from the slice header so the invariant holds on211// 32-bit builds too, where the header is 12 bytes and Chars is 20.212func TestCharsSize(t *testing.T) {213 var slice []byte
33 unmodified lines
247}248249// Runes and ToRunes alias the text in rune mode, so a consumer that mutates250// what they return changes the text without updating the cached fold bit. This263// pins the aliasing so the read-only contract on those methods is not silently264// dropped later.251// verifies the aliasing so the read-only contract on those methods is not252// silently dropped later.253func TestRuneSlicesAliasTheText(t *testing.T) {254 chars := ToChars([]byte("한글abc"))255 runes := chars.Runes()256 if runes == nil {
17 unmodified lines
modified:src/util/chars.go+3 added-3 removed
34 unmodified lines
3536// Rune ranges that case folding or normalization can turn into ASCII, derived37// from algo's normalization table and unicode.ToLower, then merged. They are a38// superset of the exact set, which TestMayFoldToAsciiIsSuperset in the algo39// package pins. Grouped tightly on purpose: a wider merge would swallow Greek40// Extended, General Punctuation and the currency and letterlike blocks, and41// every line holding a curly quote or an em dash would then lose the39// package verifies. Grouped tightly on purpose: a wider merge would include40// 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 the42// prefilter. Cyrillic, Greek, Hebrew, Arabic, Thai, Devanagari, CJK, Hangul,43// kana, emoji, punctuation and box drawing are all outside.44const (45 foldLo = 0x00C0
436 unmodified lines