Skip to content
Myr

tokenizer_test.go

This file

Path

src/tokenizer_test.go

113 lines · 2.8 KiB · Go

Last changed by

Refactor the code so that fzf can be used as a library (#3769)Junegunn Choibefore adoptione8405f4

History of this file

Take it

The walk stopped after 200 commits: lines older than d75bb5c point at it.

Deploying to master from @ junegunn/fzf@2671259fdb3094a5eac528f291c1fdadbcf9eda9 🚀junegunnbefore adoptiond75bb5c

lines 1–73why, one step back
1package fzf
23import (4 "testing"5)67func TestParseRange(t *testing.T) {8 {9 i := ".."10 r, _ := ParseRange(&i)11 if r.begin != rangeEllipsis || r.end != rangeEllipsis {12 t.Errorf("%v", r)13 }14 }15 {16 i := "3.."17 r, _ := ParseRange(&i)18 if r.begin != 3 || r.end != rangeEllipsis {19 t.Errorf("%v", r)20 }21 }22 {23 i := "3..5"24 r, _ := ParseRange(&i)25 if r.begin != 3 || r.end != 5 {26 t.Errorf("%v", r)27 }28 }29 {30 i := "-3..-5"31 r, _ := ParseRange(&i)32 if r.begin != -3 || r.end != -5 {33 t.Errorf("%v", r)34 }35 }36 {37 i := "3"38 r, _ := ParseRange(&i)39 if r.begin != 3 || r.end != 3 {40 t.Errorf("%v", r)41 }42 }43}4445func TestTokenize(t *testing.T) {46 // AWK-style47 input := " abc: def: ghi "48 tokens := Tokenize(input, Delimiter{})49 if tokens[0].text.ToString() != "abc: " || tokens[0].prefixLength != 2 {50 t.Errorf("%s", tokens)51 }5253 // With delimiter54 tokens = Tokenize(input, delimiterRegexp(":"))55 if tokens[0].text.ToString() != " abc:" || tokens[0].prefixLength != 0 {56 t.Error(tokens[0].text.ToString(), tokens[0].prefixLength)57 }5859 // With delimiter regex60 tokens = Tokenize(input, delimiterRegexp("\\s+"))61 if tokens[0].text.ToString() != " " || tokens[0].prefixLength != 0 ||62 tokens[1].text.ToString() != "abc: " || tokens[1].prefixLength != 2 ||63 tokens[2].text.ToString() != "def: " || tokens[2].prefixLength != 8 ||64 tokens[3].text.ToString() != "ghi " || tokens[3].prefixLength != 14 {65 t.Errorf("%s", tokens)66 }67}6869func TestTransform(t *testing.T) {70 input := " abc: def: ghi: jkl"71 {72 tokens := Tokenize(input, Delimiter{})73 {

Refactor the code so that fzf can be used as a library (#3769)Junegunn Choibefore adoptione8405f4

line 74why, one step back
74 ranges, _ := splitNth("1,2,3")

Deploying to master from @ junegunn/fzf@2671259fdb3094a5eac528f291c1fdadbcf9eda9 🚀junegunnbefore adoptiond75bb5c

lines 75–80why, one step back
75 tx := Transform(tokens, ranges)
76 if joinTokens(tx) != "abc: def: ghi: " {77 t.Errorf("%s", tx)78 }79 }80 {

Refactor the code so that fzf can be used as a library (#3769)Junegunn Choibefore adoptione8405f4

line 81why, one step back
81 ranges, _ := splitNth("1..2,3,2..,1")

Deploying to master from @ junegunn/fzf@2671259fdb3094a5eac528f291c1fdadbcf9eda9 🚀junegunnbefore adoptiond75bb5c

lines 82–95why, one step back
82 tx := Transform(tokens, ranges)
83 if string(joinTokens(tx)) != "abc: def: ghi: def: ghi: jklabc: " ||84 len(tx) != 4 ||85 tx[0].text.ToString() != "abc: def: " || tx[0].prefixLength != 2 ||86 tx[1].text.ToString() != "ghi: " || tx[1].prefixLength != 14 ||87 tx[2].text.ToString() != "def: ghi: jkl" || tx[2].prefixLength != 8 ||88 tx[3].text.ToString() != "abc: " || tx[3].prefixLength != 2 {89 t.Errorf("%s", tx)90 }91 }92 }93 {94 tokens := Tokenize(input, delimiterRegexp(":"))95 {

Refactor the code so that fzf can be used as a library (#3769)Junegunn Choibefore adoptione8405f4

line 96why, one step back
96 ranges, _ := splitNth("1..2,3,2..,1")

Deploying to master from @ junegunn/fzf@2671259fdb3094a5eac528f291c1fdadbcf9eda9 🚀junegunnbefore adoptiond75bb5c

lines 97–110why, one step back
97 tx := Transform(tokens, ranges)
98 if joinTokens(tx) != " abc: def: ghi: def: ghi: jkl abc:" ||99 len(tx) != 4 ||100 tx[0].text.ToString() != " abc: def:" || tx[0].prefixLength != 0 ||101 tx[1].text.ToString() != " ghi:" || tx[1].prefixLength != 12 ||102 tx[2].text.ToString() != " def: ghi: jkl" || tx[2].prefixLength != 6 ||103 tx[3].text.ToString() != " abc:" || tx[3].prefixLength != 0 {104 t.Errorf("%s", tx)105 }106 }107 }108}109110func TestTransformIndexOutOfBounds(t *testing.T) {

Refactor the code so that fzf can be used as a library (#3769)Junegunn Choibefore adoptione8405f4

lines 111–112why, one step back
111 s, _ := splitNth("1")
112 Transform([]Token{}, s)

Deploying to master from @ junegunn/fzf@2671259fdb3094a5eac528f291c1fdadbcf9eda9 🚀junegunnbefore adoptiond75bb5c

line 113why, one step back
113}