Skip to content

Commit

Permalink
Covered test case for GenMaskForFloat when target is integer. Fixed t…
Browse files Browse the repository at this point in the history
…ypo in variable name.
  • Loading branch information
kuredoro committed Jan 8, 2021
1 parent 043e246 commit ff035e4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
12 changes: 7 additions & 5 deletions lexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,20 +247,22 @@ func (l *Lexer) GenMaskForFloat(target, source string) (mask []bool) {

mask = l.GenMaskForInt(targetWhole, sourceWhole)

if targetWhole == target {
return
}

// dot is never colored
mask = append(mask, false)

tragetFracStart := strings.IndexRune(target, '.') + 1
if tragetFracStart == 0 {
tragetFracStart = len(target)
}
// This one is never 0, because of the if up there that returns
targetFracStart := strings.IndexRune(target, '.') + 1

sourceFracStart := strings.IndexRune(source, '.') + 1
if sourceFracStart == 0 {
sourceFracStart = len(source)
}

targetFrac := target[tragetFracStart:]
targetFrac := target[targetFracStart:]
sourceFrac := source[sourceFracStart:]

if len(targetFrac) > len(sourceFrac) {
Expand Down
1 change: 1 addition & 0 deletions lexer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,7 @@ func TestGenMaskForFloat(t *testing.T) {
{"1.24", "2", []bool{true, false, true, true}},
{"1.24", "2", []bool{true, false, true, true}},
{"2.", "2", []bool{false, false}},
{"2", "2.", []bool{false}},
{"2.", "2.2", []bool{false, false}},
{"2.2", "2.", []bool{false, false, true}},
{".5", "2.5", []bool{false, false}},
Expand Down

0 comments on commit ff035e4

Please sign in to comment.