mirror of
https://github.com/duke-git/lancet.git
synced 2026-02-13 09:12:28 +08:00
refactor: add internal/assert.go and rewrite all unit funcs string_test.go with assert
This commit is contained in:
148
internal/assert.go
Normal file
148
internal/assert.go
Normal file
@@ -0,0 +1,148 @@
|
|||||||
|
package internal
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"reflect"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
compareNotEqual int = iota - 2
|
||||||
|
compareLess
|
||||||
|
compareEqual
|
||||||
|
compareGreater
|
||||||
|
)
|
||||||
|
|
||||||
|
// Assert is a simple implementation of assertion, only for internal useage
|
||||||
|
type Assert struct {
|
||||||
|
T *testing.T
|
||||||
|
CaseName string
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewAssert return instance of Assert
|
||||||
|
func NewAssert(t *testing.T, caseName string) *Assert {
|
||||||
|
return &Assert{T: t, CaseName: caseName}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Equal check if expected is equal with actual
|
||||||
|
func (a *Assert) Equal(expected, actual interface{}) {
|
||||||
|
if compare(expected, actual) != compareEqual {
|
||||||
|
logFailedInfo(a.T, a.CaseName, expected, actual)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// NotEqual check if expected is not equal with actual
|
||||||
|
func (a *Assert) NotEqual(expected, actual interface{}) {
|
||||||
|
if compare(expected, actual) == compareEqual {
|
||||||
|
expectedInfo := fmt.Sprintf("not %v", expected)
|
||||||
|
logFailedInfo(a.T, a.CaseName, expectedInfo, actual)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Greater check if expected is greate than actual
|
||||||
|
func (a *Assert) Greater(expected, actual interface{}) {
|
||||||
|
if compare(expected, actual) != compareGreater {
|
||||||
|
expectedInfo := fmt.Sprintf("> %v", expected)
|
||||||
|
logFailedInfo(a.T, a.CaseName, expectedInfo, actual)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Less check if expected is less than actual
|
||||||
|
func (a *Assert) Less(expected, actual interface{}) {
|
||||||
|
if compare(expected, actual) != compareLess {
|
||||||
|
expectedInfo := fmt.Sprintf("< %v", expected)
|
||||||
|
logFailedInfo(a.T, a.CaseName, expectedInfo, actual)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// IsNil check if actual is nil
|
||||||
|
func (a *Assert) IsNil(actual interface{}) {
|
||||||
|
if actual != nil {
|
||||||
|
logFailedInfo(a.T, a.CaseName, nil, actual)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// IsNil check if actual is not nil
|
||||||
|
func (a *Assert) IsNotNil(actual interface{}) {
|
||||||
|
if actual == nil {
|
||||||
|
logFailedInfo(a.T, a.CaseName, "not nil", actual)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// compare x and y retun :
|
||||||
|
// x > y -> 1, x < y -> -1, x == y -> 0, x != y -> -2
|
||||||
|
func compare(x, y interface{}) int {
|
||||||
|
vx := reflect.ValueOf(x)
|
||||||
|
vy := reflect.ValueOf(y)
|
||||||
|
|
||||||
|
if vx.Type() != vy.Type() {
|
||||||
|
return compareNotEqual
|
||||||
|
}
|
||||||
|
|
||||||
|
switch vx.Kind() {
|
||||||
|
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
|
||||||
|
xInt := vx.Int()
|
||||||
|
yInt := vy.Int()
|
||||||
|
if xInt > yInt {
|
||||||
|
return compareGreater
|
||||||
|
}
|
||||||
|
if xInt == yInt {
|
||||||
|
return compareEqual
|
||||||
|
}
|
||||||
|
if xInt < yInt {
|
||||||
|
return compareLess
|
||||||
|
}
|
||||||
|
case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64:
|
||||||
|
xUint := vx.Uint()
|
||||||
|
yUint := vy.Uint()
|
||||||
|
if xUint > yUint {
|
||||||
|
return compareGreater
|
||||||
|
}
|
||||||
|
if xUint == yUint {
|
||||||
|
return compareEqual
|
||||||
|
}
|
||||||
|
if xUint < yUint {
|
||||||
|
return compareLess
|
||||||
|
}
|
||||||
|
case reflect.Float32, reflect.Float64:
|
||||||
|
xFloat := vx.Float()
|
||||||
|
yFloat := vy.Float()
|
||||||
|
if xFloat > yFloat {
|
||||||
|
return compareGreater
|
||||||
|
}
|
||||||
|
if xFloat == yFloat {
|
||||||
|
return compareEqual
|
||||||
|
}
|
||||||
|
if xFloat < yFloat {
|
||||||
|
return compareLess
|
||||||
|
}
|
||||||
|
case reflect.String:
|
||||||
|
xString := vx.String()
|
||||||
|
yString := vy.String()
|
||||||
|
if xString > yString {
|
||||||
|
return compareGreater
|
||||||
|
}
|
||||||
|
if xString == yString {
|
||||||
|
return compareEqual
|
||||||
|
}
|
||||||
|
if xString < yString {
|
||||||
|
return compareLess
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
if reflect.DeepEqual(x, y) {
|
||||||
|
return compareEqual
|
||||||
|
} else {
|
||||||
|
return compareNotEqual
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return compareNotEqual
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// logFailedInfo make test failed and log error info
|
||||||
|
func logFailedInfo(t *testing.T, caseName string, expected, actual interface{}) {
|
||||||
|
errInfo := fmt.Sprintf("Test case %v: expected: %v, actual: %v", caseName, expected, actual)
|
||||||
|
t.Error(errInfo)
|
||||||
|
t.FailNow()
|
||||||
|
}
|
||||||
28
internal/assert_test.go
Normal file
28
internal/assert_test.go
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
package internal
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestAssert(t *testing.T) {
|
||||||
|
assert := NewAssert(t, "TestAssert")
|
||||||
|
assert.Equal(0, 0)
|
||||||
|
assert.NotEqual(1, 0)
|
||||||
|
assert.Greater(1, 0)
|
||||||
|
assert.Less(0, 1)
|
||||||
|
|
||||||
|
assert.Greater(1.1, 0.1)
|
||||||
|
assert.Less(0.1, 1.1)
|
||||||
|
|
||||||
|
assert.Equal("abc", "abc")
|
||||||
|
assert.NotEqual("abc", "abd")
|
||||||
|
assert.Less("abc", "abd")
|
||||||
|
assert.Greater("abd", "abc")
|
||||||
|
|
||||||
|
assert.Equal([]int{1, 2, 3}, []int{1, 2, 3})
|
||||||
|
assert.NotEqual([]int{1, 2, 3}, []int{1, 2})
|
||||||
|
|
||||||
|
assert.IsNil(nil)
|
||||||
|
assert.IsNotNil("abc")
|
||||||
|
|
||||||
|
}
|
||||||
@@ -7,231 +7,163 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func TestCamelCase(t *testing.T) {
|
func TestCamelCase(t *testing.T) {
|
||||||
camelCase(t, "foo_bar", "fooBar")
|
assert := internal.NewAssert(t, "TestCamelCase")
|
||||||
camelCase(t, "Foo-Bar", "fooBar")
|
|
||||||
camelCase(t, "Foo&bar", "fooBar")
|
|
||||||
camelCase(t, "foo bar", "fooBar")
|
|
||||||
}
|
|
||||||
|
|
||||||
func camelCase(t *testing.T, test string, expected string) {
|
assert.Equal("fooBar", CamelCase("foo_bar"))
|
||||||
res := CamelCase(test)
|
assert.Equal("fooBar", CamelCase("Foo-Bar"))
|
||||||
if res != expected {
|
assert.Equal("fooBar", CamelCase("Foo&bar"))
|
||||||
internal.LogFailedTestInfo(t, "CamelCase", test, expected, res)
|
assert.Equal("fooBar", CamelCase("foo bar"))
|
||||||
t.FailNow()
|
|
||||||
}
|
assert.NotEqual("FooBar", CamelCase("foo_bar"))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestCapitalize(t *testing.T) {
|
func TestCapitalize(t *testing.T) {
|
||||||
capitalize(t, "foo", "Foo")
|
assert := internal.NewAssert(t, "TestCapitalize")
|
||||||
capitalize(t, "fOO", "Foo")
|
|
||||||
capitalize(t, "FOo", "Foo")
|
|
||||||
}
|
|
||||||
|
|
||||||
func capitalize(t *testing.T, test string, expected string) {
|
assert.Equal("Foo", Capitalize("foo"))
|
||||||
res := Capitalize(test)
|
assert.Equal("Foo", Capitalize("Foo"))
|
||||||
if res != expected {
|
assert.Equal("Foo", Capitalize("Foo"))
|
||||||
internal.LogFailedTestInfo(t, "Capitalize", test, expected, res)
|
|
||||||
t.FailNow()
|
assert.NotEqual("foo", Capitalize("Foo"))
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestKebabCase(t *testing.T) {
|
func TestKebabCase(t *testing.T) {
|
||||||
kebabCase(t, "Foo Bar-", "foo-bar")
|
assert := internal.NewAssert(t, "TestKebabCase")
|
||||||
kebabCase(t, "foo_Bar", "foo-bar")
|
|
||||||
kebabCase(t, "fooBar", "foo-bar")
|
|
||||||
kebabCase(t, "__FOO_BAR__", "f-o-o-b-a-r")
|
|
||||||
}
|
|
||||||
|
|
||||||
func kebabCase(t *testing.T, test string, expected string) {
|
assert.Equal("foo-bar", KebabCase("Foo Bar-"))
|
||||||
res := KebabCase(test)
|
assert.Equal("foo-bar", KebabCase("foo_Bar"))
|
||||||
if res != expected {
|
assert.Equal("foo-bar", KebabCase("fooBar"))
|
||||||
internal.LogFailedTestInfo(t, "KebabCase", test, expected, res)
|
assert.Equal("f-o-o-b-a-r", KebabCase("__FOO_BAR__"))
|
||||||
t.FailNow()
|
|
||||||
}
|
assert.NotEqual("foo_bar", KebabCase("fooBar"))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSnakeCase(t *testing.T) {
|
func TestSnakeCase(t *testing.T) {
|
||||||
snakeCase(t, "Foo Bar-", "foo_bar")
|
assert := internal.NewAssert(t, "TestSnakeCase")
|
||||||
snakeCase(t, "foo_Bar", "foo_bar")
|
|
||||||
snakeCase(t, "fooBar", "foo_bar")
|
|
||||||
snakeCase(t, "__FOO_BAR__", "f_o_o_b_a_r")
|
|
||||||
snakeCase(t, "aBbc-s$@a&%_B.B^C", "a_bbc_s_a_b_b_c")
|
|
||||||
}
|
|
||||||
|
|
||||||
func snakeCase(t *testing.T, test string, expected string) {
|
assert.Equal("foo_bar", SnakeCase("Foo Bar-"))
|
||||||
res := SnakeCase(test)
|
assert.Equal("foo_bar", SnakeCase("foo_Bar"))
|
||||||
if res != expected {
|
assert.Equal("foo_bar", SnakeCase("fooBar"))
|
||||||
internal.LogFailedTestInfo(t, "SnakeCase", test, expected, res)
|
assert.Equal("f_o_o_b_a_r", SnakeCase("__FOO_BAR__"))
|
||||||
t.FailNow()
|
assert.Equal("a_bbc_s_a_b_b_c", SnakeCase("aBbc-s$@a&%_B.B^C"))
|
||||||
}
|
|
||||||
|
assert.NotEqual("foo-bar", SnakeCase("foo_Bar"))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestLowerFirst(t *testing.T) {
|
func TestLowerFirst(t *testing.T) {
|
||||||
lowerFirst(t, "foo", "foo")
|
assert := internal.NewAssert(t, "TestLowerFirst")
|
||||||
lowerFirst(t, "BAR", "bAR")
|
|
||||||
lowerFirst(t, "FOo", "fOo")
|
|
||||||
lowerFirst(t, "FOo大", "fOo大")
|
|
||||||
}
|
|
||||||
|
|
||||||
func lowerFirst(t *testing.T, test string, expected string) {
|
assert.Equal("foo", LowerFirst("foo"))
|
||||||
res := LowerFirst(test)
|
assert.Equal("bAR", LowerFirst("BAR"))
|
||||||
if res != expected {
|
assert.Equal("fOo", LowerFirst("FOo"))
|
||||||
internal.LogFailedTestInfo(t, "LowerFirst", test, expected, res)
|
assert.Equal("fOo大", LowerFirst("FOo大"))
|
||||||
t.FailNow()
|
|
||||||
}
|
assert.NotEqual("Bar", LowerFirst("BAR"))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestPadEnd(t *testing.T) {
|
func TestPadEnd(t *testing.T) {
|
||||||
padEnd(t, "a", 1, "b", "a")
|
assert := internal.NewAssert(t, "TestPadEnd")
|
||||||
padEnd(t, "a", 2, "b", "ab")
|
|
||||||
padEnd(t, "abcd", 6, "mno", "abcdmn")
|
|
||||||
padEnd(t, "abcd", 6, "m", "abcdmm")
|
|
||||||
padEnd(t, "abc", 6, "ab", "abcaba")
|
|
||||||
}
|
|
||||||
|
|
||||||
func padEnd(t *testing.T, source string, size int, fillString string, expected string) {
|
assert.Equal("a", PadEnd("a", 1, "b"))
|
||||||
res := PadEnd(source, size, fillString)
|
assert.Equal("ab", PadEnd("a", 2, "b"))
|
||||||
if res != expected {
|
assert.Equal("abcdmn", PadEnd("abcd", 6, "mno"))
|
||||||
internal.LogFailedTestInfo(t, "PadEnd", source, expected, res)
|
assert.Equal("abcdmm", PadEnd("abcd", 6, "m"))
|
||||||
t.FailNow()
|
assert.Equal("abcaba", PadEnd("abc", 6, "ab"))
|
||||||
}
|
|
||||||
|
assert.NotEqual("ba", PadEnd("a", 2, "b"))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestPadStart(t *testing.T) {
|
func TestPadStart(t *testing.T) {
|
||||||
padStart(t, "a", 1, "b", "a")
|
assert := internal.NewAssert(t, "TestPadStart")
|
||||||
padStart(t, "a", 2, "b", "ba")
|
|
||||||
padStart(t, "abcd", 6, "mno", "mnabcd")
|
|
||||||
padStart(t, "abcd", 6, "m", "mmabcd")
|
|
||||||
padStart(t, "abc", 6, "ab", "abaabc")
|
|
||||||
}
|
|
||||||
|
|
||||||
func padStart(t *testing.T, source string, size int, fillString string, expected string) {
|
assert.Equal("a", PadStart("a", 1, "b"))
|
||||||
res := PadStart(source, size, fillString)
|
assert.Equal("ba", PadStart("a", 2, "b"))
|
||||||
if res != expected {
|
assert.Equal("mnabcd", PadStart("abcd", 6, "mno"))
|
||||||
internal.LogFailedTestInfo(t, "PadEnd", source, expected, res)
|
assert.Equal("mmabcd", PadStart("abcd", 6, "m"))
|
||||||
t.FailNow()
|
assert.Equal("abaabc", PadStart("abc", 6, "ab"))
|
||||||
}
|
|
||||||
|
assert.NotEqual("ab", PadStart("a", 2, "b"))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestBefore(t *testing.T) {
|
func TestBefore(t *testing.T) {
|
||||||
before(t, "lancet", "", "lancet")
|
assert := internal.NewAssert(t, "TestBefore")
|
||||||
before(t, "github.com/test/lancet", "/", "github.com")
|
|
||||||
before(t, "github.com/test/lancet", "test", "github.com/")
|
|
||||||
}
|
|
||||||
|
|
||||||
func before(t *testing.T, source, char, expected string) {
|
assert.Equal("lancet", Before("lancet", ""))
|
||||||
res := Before(source, char)
|
assert.Equal("github.com", Before("github.com/test/lancet", "/"))
|
||||||
if res != expected {
|
assert.Equal("github.com/", Before("github.com/test/lancet", "test"))
|
||||||
internal.LogFailedTestInfo(t, "Before", source, expected, res)
|
|
||||||
t.FailNow()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestBeforeLast(t *testing.T) {
|
func TestBeforeLast(t *testing.T) {
|
||||||
beforeLast(t, "lancet", "", "lancet")
|
assert := internal.NewAssert(t, "TestBeforeLast")
|
||||||
beforeLast(t, "github.com/test/lancet", "/", "github.com/test")
|
|
||||||
beforeLast(t, "github.com/test/test/lancet", "test", "github.com/test/")
|
|
||||||
}
|
|
||||||
|
|
||||||
func beforeLast(t *testing.T, source, char, expected string) {
|
assert.Equal("lancet", BeforeLast("lancet", ""))
|
||||||
res := BeforeLast(source, char)
|
assert.Equal("github.com/test", BeforeLast("github.com/test/lancet", "/"))
|
||||||
if res != expected {
|
assert.Equal("github.com/test/", BeforeLast("github.com/test/test/lancet", "test"))
|
||||||
internal.LogFailedTestInfo(t, "BeforeLast", source, expected, res)
|
|
||||||
t.FailNow()
|
assert.NotEqual("github.com/", BeforeLast("github.com/test/test/lancet", "test"))
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestAfter(t *testing.T) {
|
func TestAfter(t *testing.T) {
|
||||||
after(t, "lancet", "", "lancet")
|
assert := internal.NewAssert(t, "TestAfter")
|
||||||
after(t, "github.com/test/lancet", "/", "test/lancet")
|
|
||||||
after(t, "github.com/test/lancet", "test", "/lancet")
|
|
||||||
}
|
|
||||||
|
|
||||||
func after(t *testing.T, source, char, expected string) {
|
assert.Equal("lancet", After("lancet", ""))
|
||||||
res := After(source, char)
|
assert.Equal("test/lancet", After("github.com/test/lancet", "/"))
|
||||||
if res != expected {
|
assert.Equal("/lancet", After("github.com/test/lancet", "test"))
|
||||||
internal.LogFailedTestInfo(t, "After", source, expected, res)
|
|
||||||
t.FailNow()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestAfterLast(t *testing.T) {
|
func TestAfterLast(t *testing.T) {
|
||||||
afterLast(t, "lancet", "", "lancet")
|
assert := internal.NewAssert(t, "TestAfterLast")
|
||||||
afterLast(t, "github.com/test/lancet", "/", "lancet")
|
|
||||||
afterLast(t, "github.com/test/test/lancet", "test", "/lancet")
|
|
||||||
}
|
|
||||||
|
|
||||||
func afterLast(t *testing.T, source, char, expected string) {
|
assert.Equal("lancet", AfterLast("lancet", ""))
|
||||||
res := AfterLast(source, char)
|
assert.Equal("lancet", AfterLast("github.com/test/lancet", "/"))
|
||||||
if res != expected {
|
assert.Equal("/lancet", AfterLast("github.com/test/lancet", "test"))
|
||||||
internal.LogFailedTestInfo(t, "AfterLast", source, expected, res)
|
assert.Equal("/lancet", AfterLast("github.com/test/test/lancet", "test"))
|
||||||
t.FailNow()
|
|
||||||
}
|
assert.NotEqual("/test/lancet", AfterLast("github.com/test/test/lancet", "test"))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestIsString(t *testing.T) {
|
func TestIsString(t *testing.T) {
|
||||||
isString(t, "lancet", true)
|
assert := internal.NewAssert(t, "TestIsString")
|
||||||
isString(t, 1, false)
|
|
||||||
isString(t, true, false)
|
|
||||||
isString(t, []string{}, false)
|
|
||||||
}
|
|
||||||
|
|
||||||
func isString(t *testing.T, test interface{}, expected bool) {
|
assert.Equal(true, IsString("lancet"))
|
||||||
res := IsString(test)
|
assert.Equal(true, IsString(""))
|
||||||
if res != expected {
|
assert.Equal(false, IsString(1))
|
||||||
internal.LogFailedTestInfo(t, "IsString", test, expected, res)
|
assert.Equal(false, IsString(true))
|
||||||
t.FailNow()
|
assert.Equal(false, IsString([]string{}))
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestReverseStr(t *testing.T) {
|
func TestReverseStr(t *testing.T) {
|
||||||
reverseStr(t, "abc", "cba")
|
assert := internal.NewAssert(t, "TestReverseStr")
|
||||||
reverseStr(t, "12345", "54321")
|
|
||||||
}
|
|
||||||
|
|
||||||
func reverseStr(t *testing.T, test string, expected string) {
|
assert.Equal("cba", ReverseStr("abc"))
|
||||||
res := ReverseStr(test)
|
assert.Equal("54321", ReverseStr("12345"))
|
||||||
if res != expected {
|
|
||||||
internal.LogFailedTestInfo(t, "ReverseStr", test, expected, res)
|
|
||||||
t.FailNow()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestWrap(t *testing.T) {
|
func TestWrap(t *testing.T) {
|
||||||
wrap(t, "ab", "", "ab")
|
assert := internal.NewAssert(t, "TestWrap")
|
||||||
wrap(t, "", "*", "")
|
|
||||||
wrap(t, "ab", "*", "*ab*")
|
|
||||||
wrap(t, "ab", "\"", "\"ab\"")
|
|
||||||
wrap(t, "ab", "'", "'ab'")
|
|
||||||
}
|
|
||||||
|
|
||||||
func wrap(t *testing.T, test string, wrapWith string, expected string) {
|
assert.Equal("ab", Wrap("ab", ""))
|
||||||
res := Wrap(test, wrapWith)
|
assert.Equal("", Wrap("", "*"))
|
||||||
if res != expected {
|
assert.Equal("*ab*", Wrap("ab", "*"))
|
||||||
internal.LogFailedTestInfo(t, "Wrap", test, expected, res)
|
assert.Equal("\"ab\"", Wrap("ab", "\""))
|
||||||
t.FailNow()
|
assert.Equal("'ab'", Wrap("ab", "'"))
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestUnwrap(t *testing.T) {
|
func TestUnwrap(t *testing.T) {
|
||||||
unwrap(t, "", "*", "")
|
assert := internal.NewAssert(t, "TestUnwrap")
|
||||||
unwrap(t, "ab", "", "ab")
|
|
||||||
unwrap(t, "ab", "*", "ab")
|
assert.Equal("", Unwrap("", "*"))
|
||||||
unwrap(t, "**ab**", "*", "*ab*")
|
assert.Equal("ab", Unwrap("ab", ""))
|
||||||
unwrap(t, "**ab**", "**", "ab")
|
assert.Equal("ab", Unwrap("ab", "*"))
|
||||||
unwrap(t, "\"ab\"", "\"", "ab")
|
assert.Equal("*ab*", Unwrap("**ab**", "*"))
|
||||||
unwrap(t, "*ab", "*", "*ab")
|
assert.Equal("ab", Unwrap("**ab**", "**"))
|
||||||
unwrap(t, "ab*", "*", "ab*")
|
assert.Equal("ab", Unwrap("\"ab\"", "\""))
|
||||||
unwrap(t, "***", "*", "*")
|
assert.Equal("*ab", Unwrap("*ab", "*"))
|
||||||
unwrap(t, "**", "*", "")
|
assert.Equal("ab*", Unwrap("ab*", "*"))
|
||||||
unwrap(t, "***", "**", "***")
|
assert.Equal("*", Unwrap("***", "*"))
|
||||||
unwrap(t, "**", "**", "**")
|
|
||||||
}
|
assert.Equal("", Unwrap("**", "*"))
|
||||||
|
assert.Equal("***", Unwrap("***", "**"))
|
||||||
|
assert.Equal("**", Unwrap("**", "**"))
|
||||||
|
|
||||||
func unwrap(t *testing.T, test string, wrapToken string, expected string) {
|
|
||||||
res := Unwrap(test, wrapToken)
|
|
||||||
if res != expected {
|
|
||||||
internal.LogFailedTestInfo(t, "Unwrap", test+"->"+wrapToken, expected, res)
|
|
||||||
t.FailNow()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user