github.com/grailbio/bigslice@v0.0.0-20230519005545-30c4c12152ad/slicetype/slicetype_test.go (about)

     1  // Copyright 2018 GRAIL, Inc. All rights reserved.
     2  // Use of this source code is governed by the Apache 2.0
     3  // license that can be found in the LICENSE file.
     4  
     5  package slicetype
     6  
     7  import (
     8  	"reflect"
     9  	"testing"
    10  )
    11  
    12  var (
    13  	typeOfString = reflect.TypeOf("")
    14  	typeOfInt    = reflect.TypeOf(0)
    15  )
    16  
    17  func TestType(t *testing.T) {
    18  	types := []reflect.Type{typeOfString, typeOfInt, typeOfString}
    19  	typ := New(types...)
    20  	if got, want := Columns(typ), types; !reflect.DeepEqual(got, want) {
    21  		t.Errorf("got %v, want %v", got, want)
    22  	}
    23  	if !Assignable(typ, typ) {
    24  		t.Error("types should be assignable to themselves")
    25  	}
    26  }
    27  
    28  func TestSignature(t *testing.T) {
    29  	arg := New(typeOfString, typeOfInt)
    30  	ret := New()
    31  	if got, want := Signature(arg, ret), "func(string, int)"; got != want {
    32  		t.Errorf("got %v, want %v", got, want)
    33  	}
    34  	ret = New(typeOfInt)
    35  	if got, want := Signature(arg, ret), "func(string, int) int"; got != want {
    36  		t.Errorf("got %v, want %v", got, want)
    37  	}
    38  	ret = New(typeOfInt, typeOfString)
    39  	if got, want := Signature(arg, ret), "func(string, int) (int, string)"; got != want {
    40  		t.Errorf("got %v, want %v", got, want)
    41  	}
    42  }