]> git.lizzy.rs Git - micro.git/blobdiff - cmd/micro/util_test.go
Code optimisation (#1117)
[micro.git] / cmd / micro / util_test.go
index c3060ff5812b9286999febd0ef71c6ba8535c14c..51a24e024e79d93c7a63e537799f3ec7bc13fc66 100644 (file)
@@ -1,7 +1,6 @@
 package main
 
 import (
-       "reflect"
        "testing"
 )
 
@@ -67,47 +66,40 @@ func TestIsWordChar(t *testing.T) {
        }
 }
 
-func TestJoinAndSplitCommandArgs(t *testing.T) {
-       tests := []struct {
-               Query  []string
-               Wanted string
-       }{
-               {[]string{`test case`}, `"test case"`},
-               {[]string{`quote "test"`}, `"quote \"test\""`},
-               {[]string{`slash\\\ test`}, `"slash\\\\\\ test"`},
-               {[]string{`path 1`, `path\" 2`}, `"path 1" "path\\\" 2"`},
-               {[]string{`foo`}, `foo`},
-               {[]string{`foo\"bar`}, `"foo\\\"bar"`},
-               {[]string{``}, ``},
-               {[]string{`"`}, `"\""`},
-               {[]string{`a`, ``}, `a `},
-               {[]string{``, ``, ``, ``}, `   `},
-               {[]string{"\n"}, `"\n"`},
-               {[]string{"foo\tbar"}, `"foo\tbar"`},
+func TestStringWidth(t *testing.T) {
+       tabsize := 4
+       if w := StringWidth("1\t2", tabsize); w != 5 {
+               t.Error("StringWidth 1 Failed. Got", w)
        }
-
-       for i, test := range tests {
-               if result := JoinCommandArgs(test.Query...); test.Wanted != result {
-                       t.Errorf("JoinCommandArgs failed at Test %d\nGot: %q", i, result)
-               }
-
-               if result := SplitCommandArgs(test.Wanted); !reflect.DeepEqual(test.Query, result) {
-                       t.Errorf("SplitCommandArgs failed at Test %d\nGot: `%q`", i, result)
-               }
+       if w := StringWidth("\t", tabsize); w != 4 {
+               t.Error("StringWidth 2 Failed. Got", w)
        }
-
-       splitTests := []struct {
-               Query  string
-               Wanted []string
-       }{
-               {`"hallo""Welt"`, []string{`"hallo""Welt"`}},
-               {`\"`, []string{`\"`}},
-               {`"\"`, []string{`"\"`}},
+       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)
+       }
+}
 
-       for i, test := range splitTests {
-               if result := SplitCommandArgs(test.Query); !reflect.DeepEqual(test.Wanted, result) {
-                       t.Errorf("SplitCommandArgs failed at Split-Test %d\nGot: `%q`", i, result)
-               }
+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)
        }
 }