github.com/ipld/go-ipld-prime@v0.21.0/node/mixins/delim_test.go (about)

     1  package mixins
     2  
     3  import (
     4  	"fmt"
     5  	"reflect"
     6  	"testing"
     7  
     8  	"github.com/google/go-cmp/cmp"
     9  
    10  	qt "github.com/frankban/quicktest"
    11  )
    12  
    13  func TestSplitExact(t *testing.T) {
    14  	type expect struct {
    15  		value []string
    16  		err   error
    17  	}
    18  	type tcase struct {
    19  		s      string
    20  		sep    string
    21  		count  int
    22  		expect expect
    23  	}
    24  	for _, ent := range []tcase{
    25  		{"", "", 0, expect{[]string{}, nil}},
    26  		{"", ":", 1, expect{[]string{""}, nil}},
    27  		{"x", ":", 1, expect{[]string{"x"}, nil}},
    28  		{"x:y", ":", 2, expect{[]string{"x", "y"}, nil}},
    29  		{"x:y:", ":", 2, expect{nil, fmt.Errorf("expected 1 instances of the delimiter, found 2")}},
    30  		{":x:y", ":", 2, expect{nil, fmt.Errorf("expected 1 instances of the delimiter, found 2")}},
    31  		{"x:y:", ":", 3, expect{[]string{"x", "y", ""}, nil}},
    32  	} {
    33  		value, err := SplitExact(ent.s, ent.sep, ent.count)
    34  		ent2 := tcase{ent.s, ent.sep, ent.count, expect{value, err}}
    35  		qt.Check(t, ent2, qt.CmpEquals(cmp.Exporter(func(reflect.Type) bool { return true })), ent)
    36  	}
    37  }