From ff035e40fa68abbacd52d297f8af75975bc1c9ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=81=97=E3=81=9A=E3=81=88?= <66309775+kuredoro@users.noreply.github.com> Date: Fri, 8 Jan 2021 11:57:36 +0300 Subject: [PATCH] Covered test case for GenMaskForFloat when target is integer. Fixed typo in variable name. --- lexer.go | 12 +++++++----- lexer_test.go | 1 + 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/lexer.go b/lexer.go index c95aa98..19e5b67 100644 --- a/lexer.go +++ b/lexer.go @@ -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) { diff --git a/lexer_test.go b/lexer_test.go index 3e0a3af..15c2c63 100644 --- a/lexer_test.go +++ b/lexer_test.go @@ -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}},