vis: adding a pure golang Vis()
The current Vis() and Unvis() are using the C implementation from MTREE(8). But that means that cgo is used, which is not always desired. Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
This commit is contained in:
parent
e42c679e89
commit
08b1000418
19 changed files with 580 additions and 61 deletions
45
unvis_go_test.go
Normal file
45
unvis_go_test.go
Normal file
|
@ -0,0 +1,45 @@
|
|||
package mtree
|
||||
|
||||
import "testing"
|
||||
|
||||
type runeCheck func(rune) bool
|
||||
|
||||
func TestUnvisHelpers(t *testing.T) {
|
||||
testset := []struct {
|
||||
R rune
|
||||
Check runeCheck
|
||||
Expect bool
|
||||
}{
|
||||
{'a', ishex, true},
|
||||
{'A', ishex, true},
|
||||
{'z', ishex, false},
|
||||
{'Z', ishex, false},
|
||||
{'G', ishex, false},
|
||||
{'1', ishex, true},
|
||||
{'0', ishex, true},
|
||||
{'9', ishex, true},
|
||||
{'0', isoctal, true},
|
||||
{'3', isoctal, true},
|
||||
{'7', isoctal, true},
|
||||
{'9', isoctal, false},
|
||||
{'a', isoctal, false},
|
||||
{'z', isoctal, false},
|
||||
{'3', isalnum, true},
|
||||
{'a', isalnum, true},
|
||||
{';', isalnum, false},
|
||||
{'!', isalnum, false},
|
||||
{' ', isalnum, false},
|
||||
{'3', isgraph, true},
|
||||
{'a', isgraph, true},
|
||||
{';', isgraph, true},
|
||||
{'!', isgraph, true},
|
||||
{' ', isgraph, false},
|
||||
}
|
||||
|
||||
for i, ts := range testset {
|
||||
got := ts.Check(ts.R)
|
||||
if got != ts.Expect {
|
||||
t.Errorf("%d: %q expected: %t; got %t", i, string(ts.R), ts.Expect, got)
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue