github.com/blend/go-sdk@v1.20220411.3/collections/strings_test.go (about)

     1  /*
     2  
     3  Copyright (c) 2022 - Present. Blend Labs, Inc. All rights reserved
     4  Use of this source code is governed by a MIT license that can be found in the LICENSE file.
     5  
     6  */
     7  
     8  package collections
     9  
    10  import (
    11  	"fmt"
    12  	"strconv"
    13  	"testing"
    14  
    15  	"github.com/blend/go-sdk/assert"
    16  )
    17  
    18  func TestStringArray(t *testing.T) {
    19  	a := assert.New(t)
    20  
    21  	sa := Strings{"Foo", "bar", "baz"}
    22  
    23  	a.Equal("Foo", sa.First())
    24  	a.Equal("baz", sa.Last())
    25  
    26  	a.True(sa.Contains("Foo"))
    27  	a.False(sa.Contains("FOO"))
    28  	a.False(sa.Contains("will"))
    29  
    30  	a.True(sa.ContainsLower("foo"))
    31  	a.False(sa.ContainsLower("will"))
    32  
    33  	foo := sa.GetByLower("foo")
    34  	a.Equal("Foo", foo)
    35  	notFoo := sa.GetByLower("will")
    36  	a.Equal("", notFoo)
    37  }
    38  
    39  func TestStringArrayReverse(t *testing.T) {
    40  	a := assert.New(t)
    41  
    42  	var rev Strings
    43  	for arraySize := 0; arraySize < 13; arraySize++ {
    44  		var arr Strings
    45  		for x := 0; x < arraySize; x++ {
    46  			arr = append(arr, strconv.Itoa(x))
    47  		}
    48  		rev = arr.Reverse()
    49  		switch {
    50  		case arraySize == 0:
    51  			a.Empty(rev)
    52  		case arraySize == 1:
    53  			a.Len(rev, 1)
    54  			a.Equal(rev[0], arr[0])
    55  		case arraySize > 1:
    56  			for y := 0; y < arraySize-1; y++ {
    57  				a.Equal(rev[y], arr[arraySize-(y+1)], fmt.Sprintf("array size: %d", arraySize))
    58  			}
    59  		}
    60  	}
    61  }