]> git.lizzy.rs Git - micro.git/blobdiff - cmd/micro/util_test.go
Code optimisation (#1117)
[micro.git] / cmd / micro / util_test.go
index 29fc009f067761034dc97d0f04c1e17972879c46..51a24e024e79d93c7a63e537799f3ec7bc13fc66 100644 (file)
@@ -1,6 +1,8 @@
 package main
 
-import "testing"
+import (
+       "testing"
+)
 
 func TestNumOccurences(t *testing.T) {
        var tests = []struct {
@@ -13,7 +15,7 @@ func TestNumOccurences(t *testing.T) {
                {"∆ƒ\tø ® \t\t", '\t', 3},
        }
        for _, test := range tests {
-               if got := NumOccurences(test.inputStr, test.inputChar); got != test.want {
+               if got := NumOccurrences(test.inputStr, test.inputChar); got != test.want {
                        t.Errorf("NumOccurences(%s, %c) = %d", test.inputStr, test.inputChar, got)
                }
        }
@@ -47,15 +49,15 @@ func TestIsWordChar(t *testing.T) {
        if IsWordChar("_") == false {
                t.Errorf("IsWordChar(_) = false")
        }
+       if IsWordChar("ß") == false {
+               t.Errorf("IsWordChar(ß) = false")
+       }
        if IsWordChar("~") == true {
                t.Errorf("IsWordChar(~) = true")
        }
        if IsWordChar(" ") == true {
                t.Errorf("IsWordChar( ) = true")
        }
-       if IsWordChar("ß") == true {
-               t.Errorf("IsWordChar(ß) = true")
-       }
        if IsWordChar(")") == true {
                t.Errorf("IsWordChar()) = true")
        }
@@ -63,3 +65,41 @@ func TestIsWordChar(t *testing.T) {
                t.Errorf("IsWordChar(\n)) = true")
        }
 }
+
+func TestStringWidth(t *testing.T) {
+       tabsize := 4
+       if w := StringWidth("1\t2", tabsize); w != 5 {
+               t.Error("StringWidth 1 Failed. Got", w)
+       }
+       if w := StringWidth("\t", tabsize); w != 4 {
+               t.Error("StringWidth 2 Failed. Got", w)
+       }
+       if w := StringWidth("1\t", tabsize); w != 4 {
+               t.Error("StringWidth 3 Failed. Got", w)
+       }
+       if w := StringWidth("\t\t", tabsize); w != 8 {
+               t.Error("StringWidth 4 Failed. Got", w)
+       }
+       if w := StringWidth("12\t2\t", tabsize); w != 8 {
+               t.Error("StringWidth 5 Failed. Got", w)
+       }
+}
+
+func TestWidthOfLargeRunes(t *testing.T) {
+       tabsize := 4
+       if w := WidthOfLargeRunes("1\t2", tabsize); w != 2 {
+               t.Error("WidthOfLargeRunes 1 Failed. Got", w)
+       }
+       if w := WidthOfLargeRunes("\t", tabsize); w != 3 {
+               t.Error("WidthOfLargeRunes 2 Failed. Got", w)
+       }
+       if w := WidthOfLargeRunes("1\t", tabsize); w != 2 {
+               t.Error("WidthOfLargeRunes 3 Failed. Got", w)
+       }
+       if w := WidthOfLargeRunes("\t\t", tabsize); w != 6 {
+               t.Error("WidthOfLargeRunes 4 Failed. Got", w)
+       }
+       if w := WidthOfLargeRunes("12\t2\t", tabsize); w != 3 {
+               t.Error("WidthOfLargeRunes 5 Failed. Got", w)
+       }
+}