github.com/go-spring/spring-base@v1.1.3/assert/string_test.go (about)

     1  /*
     2   * Copyright 2012-2019 the original author or authors.
     3   *
     4   * Licensed under the Apache License, Version 2.0 (the "License");
     5   * you may not use this file except in compliance with the License.
     6   * You may obtain a copy of the License at
     7   *
     8   *      https://www.apache.org/licenses/LICENSE-2.0
     9   *
    10   * Unless required by applicable law or agreed to in writing, software
    11   * distributed under the License is distributed on an "AS IS" BASIS,
    12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13   * See the License for the specific language governing permissions and
    14   * limitations under the License.
    15   */
    16  
    17  package assert_test
    18  
    19  import (
    20  	"testing"
    21  
    22  	"github.com/go-spring/spring-base/assert"
    23  )
    24  
    25  func TestString_EqualFold(t *testing.T) {
    26  	runCase(t, func(g *assert.MockT) {
    27  		assert.String(g, "hello, world!").EqualFold("Hello, World!")
    28  	})
    29  	runCase(t, func(g *assert.MockT) {
    30  		g.EXPECT().Error([]interface{}{"'hello, world!' doesn't equal fold to 'xxx'"})
    31  		assert.String(g, "hello, world!").EqualFold("xxx")
    32  	})
    33  	runCase(t, func(g *assert.MockT) {
    34  		g.EXPECT().Error([]interface{}{"'hello, world!' doesn't equal fold to 'xxx'; param (index=0)"})
    35  		assert.String(g, "hello, world!").EqualFold("xxx", "param (index=0)")
    36  	})
    37  }
    38  
    39  func TestString_HasPrefix(t *testing.T) {
    40  	runCase(t, func(g *assert.MockT) {
    41  		assert.String(g, "hello, world!").HasPrefix("hello")
    42  	})
    43  	runCase(t, func(g *assert.MockT) {
    44  		g.EXPECT().Error([]interface{}{"'hello, world!' doesn't have prefix 'xxx'"})
    45  		assert.String(g, "hello, world!").HasPrefix("xxx")
    46  	})
    47  	runCase(t, func(g *assert.MockT) {
    48  		g.EXPECT().Error([]interface{}{"'hello, world!' doesn't have prefix 'xxx'; param (index=0)"})
    49  		assert.String(g, "hello, world!").HasPrefix("xxx", "param (index=0)")
    50  	})
    51  }
    52  
    53  func TestString_HasSuffix(t *testing.T) {
    54  	runCase(t, func(g *assert.MockT) {
    55  		assert.String(g, "hello, world!").HasSuffix("world!")
    56  	})
    57  	runCase(t, func(g *assert.MockT) {
    58  		g.EXPECT().Error([]interface{}{"'hello, world!' doesn't have suffix 'xxx'"})
    59  		assert.String(g, "hello, world!").HasSuffix("xxx")
    60  	})
    61  	runCase(t, func(g *assert.MockT) {
    62  		g.EXPECT().Error([]interface{}{"'hello, world!' doesn't have suffix 'xxx'; param (index=0)"})
    63  		assert.String(g, "hello, world!").HasSuffix("xxx", "param (index=0)")
    64  	})
    65  }
    66  
    67  func TestString_Contains(t *testing.T) {
    68  	runCase(t, func(g *assert.MockT) {
    69  		assert.String(g, "hello, world!").Contains("hello")
    70  	})
    71  	runCase(t, func(g *assert.MockT) {
    72  		g.EXPECT().Error([]interface{}{"'hello, world!' doesn't contain substr 'xxx'"})
    73  		assert.String(g, "hello, world!").Contains("xxx")
    74  	})
    75  	runCase(t, func(g *assert.MockT) {
    76  		g.EXPECT().Error([]interface{}{"'hello, world!' doesn't contain substr 'xxx'; param (index=0)"})
    77  		assert.String(g, "hello, world!").Contains("xxx", "param (index=0)")
    78  	})
    79  }