-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsearch_test.go
More file actions
137 lines (117 loc) · 4.22 KB
/
Copy pathsearch_test.go
File metadata and controls
137 lines (117 loc) · 4.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
package main
import (
"strings"
"testing"
)
// test single argument requests to unicodeSearch function for glyph --> Unicode code point search
func TestGlyphSearchCodePointsSingle(t *testing.T) {
cases := []struct {
unihex string
expected string
}{
{"006A", "U+006A 'j'"}, // ASCII
{"20AC", "U+20AC '€'"}, // Currency
{"03B2", "U+03B2 'β'"}, // Greek and Coptic
{"0444", "U+0444 'ф'"}, // Cyrillic
{"2580", "U+2580 '▀'"}, // Block elements
}
for _, c := range cases {
response, err := glyphSearch(c.unihex)
if err != nil {
t.Errorf("[FAIL] Expected no error on glyph search and received %v", err)
}
if len(response) == 0 {
t.Errorf("[FAIL] unicodeSearch did not return a value (len = 0)")
} else if !strings.Contains(response, c.expected) {
t.Errorf("[FAIL] Unicode code point '%s' yielded response %v, not expected response %s", c.unihex, response[0], c.expected)
}
}
}
// test single argument requests to unicodeSearch function for glyph --> Unicode code point search with appended newline
// character. This is intended to address newline values that may come in through stdin piped text from another
// application. Example is: `$ echo "006A" | uni -g` where newline is appended to the hexadecimal by the echo application
func TestGlyphSearchCodePointsSingleWithNewline(t *testing.T) {
cases := []struct {
unihex string
expected string
}{
{"006A\n", "U+006A 'j'"}, // ASCII
{"20AC\n", "U+20AC '€'"}, // Currency
{"03B2\n", "U+03B2 'β'"}, // Greek and Coptic
{"0444\n", "U+0444 'ф'"}, // Cyrillic
{"2580\n", "U+2580 '▀'"}, // Block elements
}
for _, c := range cases {
response, err := glyphSearch(c.unihex)
if err != nil {
t.Errorf("[FAIL] Expected no error on glyph search and received %v", err)
}
if len(response) == 0 {
t.Errorf("[FAIL] unicodeSearch did not return a value (len = 0)")
} else if !strings.Contains(response, c.expected) {
t.Errorf("[FAIL] Unicode code point '%s' yielded response %v, not expected response %s", c.unihex, response[0], c.expected)
}
}
}
func TestGlyphSearchInvalidHexadecimal(t *testing.T) {
response, err := glyphSearch("zzzzz")
if err == nil {
t.Errorf("[FAIL] Expected error with invalid hexadecimal format and instead received response %s", response)
}
}
func TestGlyphSearchInvalidOutOfRange(t *testing.T) {
response, err := glyphSearch("0010")
if err == nil {
t.Errorf("[FAIL] Expected error with out of range hexadecimal format and instead received response %s", response)
}
}
// test single argument requests to unicodeSearch function for glyph --> Unicode code point search
func TestUnicodeSearchCodePointsSingle(t *testing.T) {
cases := []struct {
glyph string
expected string
}{
{"j", "U+006A 'j'"}, // ASCII
{"€", "U+20AC '€'"}, // Currency
{"β", "U+03B2 'β'"}, // Greek and Coptic
{"ф", "U+0444 'ф'"}, // Cyrillic
{"▀", "U+2580 '▀'"}, // Block elements
}
for _, c := range cases {
testglyph := []string{c.glyph}
response := unicodeSearch(testglyph)
if len(response) == 0 {
t.Errorf("[FAIL] unicodeSearch did not return a value (len = 0)")
} else if !strings.Contains(response[0], c.expected) {
t.Errorf("[FAIL] Glyph '%s' yielded response %s, not expected response %s", c.glyph, response[0], c.expected)
}
}
}
// test multiple argument requests to the unicodeSearch function for glyph --> Unicode code point search
func TestUnicodeSearchCodePointsMultiple(t *testing.T) {
cases := []struct {
glyph string
expected string
}{
{"j", "U+006A 'j'"}, // ASCII
{"€", "U+20AC '€'"}, // Currency
{"β", "U+03B2 'β'"}, // Greek and Coptic
{"ф", "U+0444 'ф'"}, // Cyrillic
{"▀", "U+2580 '▀'"}, // Block elements
}
var testglyphs []string
for _, c := range cases {
testglyphs = append(testglyphs, c.glyph)
}
response := unicodeSearch(testglyphs)
if len(response) == 0 {
t.Errorf("[FAIL] unicodeSearch did not return a value (len = 0)")
} else if !(len(response) == 5) {
t.Errorf("[FAIL] Expected five Unicode points in response. Received %d", len(response))
}
for i := range response {
if !strings.Contains(response[i], cases[i].expected) {
t.Errorf("[FAIL] Expected response %s but received response %s", cases[i].expected, response[i])
}
}
}