mirror of
https://github.com/vbatts/go-mtree.git
synced 2025-07-25 15:50:27 +00:00
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
20
vis_test.go
20
vis_test.go
|
@ -2,7 +2,7 @@ package mtree
|
|||
|
||||
import "testing"
|
||||
|
||||
func TestVis(t *testing.T) {
|
||||
func TestVisBasic(t *testing.T) {
|
||||
testset := []struct {
|
||||
Src, Dest string
|
||||
}{
|
||||
|
@ -17,33 +17,23 @@ func TestVis(t *testing.T) {
|
|||
}
|
||||
|
||||
for i := range testset {
|
||||
got, err := Vis(testset[i].Src)
|
||||
got, err := Vis(testset[i].Src, DefaultVisFlags)
|
||||
if err != nil {
|
||||
t.Errorf("working with %q: %s", testset[i].Src, err)
|
||||
}
|
||||
if got != testset[i].Dest {
|
||||
t.Errorf("expected %#v; got %#v", testset[i].Dest, got)
|
||||
t.Errorf("%q: expected %#v; got %#v", testset[i].Src, testset[i].Dest, got)
|
||||
continue
|
||||
}
|
||||
|
||||
got, err = Unvis(got)
|
||||
if err != nil {
|
||||
t.Errorf("working with %q: %s", testset[i].Src, err)
|
||||
t.Errorf("working with %q: %s: %q", testset[i].Src, err, got)
|
||||
continue
|
||||
}
|
||||
if got != testset[i].Src {
|
||||
t.Errorf("expected %#v; got %#v", testset[i].Src, got)
|
||||
t.Errorf("%q: expected %#v; got %#v", testset[i].Dest, testset[i].Src, got)
|
||||
continue
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// The resulting string of Vis output could potentially be four times longer than
|
||||
// the original. Vis must handle this possibility.
|
||||
func TestVisLength(t *testing.T) {
|
||||
testString := "All work and no play makes Jack a dull boy\n"
|
||||
for i := 0; i < 20; i++ {
|
||||
Vis(testString)
|
||||
testString = testString + testString
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue