]> git.lizzy.rs Git - micro.git/blob - cmd/micro/util_test.go
now is go gettable and updated make file
[micro.git] / cmd / micro / util_test.go
1 package main
2
3 import "testing"
4
5 func TestNumOccurences(t *testing.T) {
6         var tests = []struct {
7                 inputStr  string
8                 inputChar byte
9                 want      int
10         }{
11                 {"aaaa", 'a', 4},
12                 {"\trfd\ta", '\t', 2},
13                 {"∆ƒ\tø ® \t\t", '\t', 3},
14         }
15         for _, test := range tests {
16                 if got := NumOccurences(test.inputStr, test.inputChar); got != test.want {
17                         t.Errorf("NumOccurences(%s, %c) = %d", test.inputStr, test.inputChar, got)
18                 }
19         }
20 }
21
22 func TestSpaces(t *testing.T) {
23         var tests = []struct {
24                 input int
25                 want  string
26         }{
27                 {4, "    "},
28                 {0, ""},
29         }
30         for _, test := range tests {
31                 if got := Spaces(test.input); got != test.want {
32                         t.Errorf("Spaces(%d) = \"%s\"", test.input, got)
33                 }
34         }
35 }
36
37 func TestIsWordChar(t *testing.T) {
38         if IsWordChar("t") == false {
39                 t.Errorf("IsWordChar(t) = false")
40         }
41         if IsWordChar("T") == false {
42                 t.Errorf("IsWordChar(T) = false")
43         }
44         if IsWordChar("5") == false {
45                 t.Errorf("IsWordChar(5) = false")
46         }
47         if IsWordChar("_") == false {
48                 t.Errorf("IsWordChar(_) = false")
49         }
50         if IsWordChar("~") == true {
51                 t.Errorf("IsWordChar(~) = true")
52         }
53         if IsWordChar(" ") == true {
54                 t.Errorf("IsWordChar( ) = true")
55         }
56         if IsWordChar("ß") == true {
57                 t.Errorf("IsWordChar(ß) = true")
58         }
59         if IsWordChar(")") == true {
60                 t.Errorf("IsWordChar()) = true")
61         }
62         if IsWordChar("\n") == true {
63                 t.Errorf("IsWordChar(\n)) = true")
64         }
65 }