assert

package
v0.13.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 9, 2024 License: MIT Imports: 11 Imported by: 0

README

assert

import "github.com/fufuok/utils/assert"

Index

func DeepEqual

func DeepEqual(expected, actual interface{}) bool

DeepEqual Ref: stretchr/testify

func Empty

func Empty(tb testing.TB, value interface{}, msgAndArgs ...interface{})

func Equal

func Equal(tb testing.TB, expected, actual interface{}, msgAndArgs ...interface{})

Equal checks if values are equal Ref: gofiber/utils

func False

func False(tb testing.TB, value bool, msgAndArgs ...interface{})

func IsEmpty

func IsEmpty(o interface{}) bool

IsEmpty gets whether the specified object is considered empty or not. Ref: stretchr/testify

func IsNil

func IsNil(o interface{}) bool

IsNil 判断对象(pointer, channel, func, interface, map, slice)是否为 nil nil 是一个 Type 类型的变量, Type 类型是基于 int 的类型 var 若变量本身是指针, 占用 8 字节, 指向类型内部结构体并置 0, 仅定义了变量本身, 此时为 nil

指针是非复合类型, 赋值 nil 时, 将 8 字节置 0, 即没有指向任何值的指针 0x0
map, channel: var 时仅定义了指针, 需要 make 初始化内部结构后才能使用, make 后非 nil

var 若变量非指针, 如 struct, int, 非 nil slice:

type slice struct, 占用 24 字节, 1 指针(array unsafe.Pointer) 2 个整型字段(len, cap int)
var 定义后即可使用, 置 0 并分配, 此时 array 指针为 0 即没有实际数据时为 nil

interface:

type iface struct(interface 类型), type eface struct(空接口), 占用 16 字节
判断 data 指针为 0 即为 nil, 初始化后即非 0

Ref: stretchr/testify

func Nil

func Nil(tb testing.TB, value interface{}, msgAndArgs ...interface{})

func NotEmpty

func NotEmpty(tb testing.TB, value interface{}, msgAndArgs ...interface{})

func NotEqual

func NotEqual(tb testing.TB, expected, actual interface{}, msgAndArgs ...interface{})

func NotNil

func NotNil(tb testing.TB, value interface{}, msgAndArgs ...interface{})

func Panics

func Panics(t *testing.T, title string, f func())

Panics 断言 panic

func True

func True(tb testing.TB, value bool, msgAndArgs ...interface{})

Generated by gomarkdoc

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Contains added in v0.12.0

func Contains(tb testing.TB, value string, msgAndArgs ...string)

func DeepEqual added in v0.9.10

func DeepEqual(expected, actual interface{}) bool

DeepEqual Ref: stretchr/testify

func Empty added in v0.9.10

func Empty(tb testing.TB, value interface{}, msgAndArgs ...interface{})

func Equal

func Equal(tb testing.TB, expected, actual interface{}, msgAndArgs ...interface{})

Equal checks if values are equal Ref: gofiber/utils

func False added in v0.9.9

func False(tb testing.TB, value bool, msgAndArgs ...interface{})

func IsEmpty added in v0.9.10

func IsEmpty(o interface{}) bool

IsEmpty gets whether the specified object is considered empty or not. Ref: stretchr/testify

func IsNil

func IsNil(o interface{}) bool

IsNil 判断对象(pointer, channel, func, interface, map, slice)是否为 nil nil 是一个 Type 类型的变量, Type 类型是基于 int 的类型 var 若变量本身是指针, 占用 8 字节, 指向类型内部结构体并置 0, 仅定义了变量本身, 此时为 nil

指针是非复合类型, 赋值 nil 时, 将 8 字节置 0, 即没有指向任何值的指针 0x0
map, channel: var 时仅定义了指针, 需要 make 初始化内部结构后才能使用, make 后非 nil

var 若变量非指针, 如 struct, int, 非 nil slice:

type slice struct, 占用 24 字节, 1 指针(array unsafe.Pointer) 2 个整型字段(len, cap int)
var 定义后即可使用, 置 0 并分配, 此时 array 指针为 0 即没有实际数据时为 nil

interface:

type iface struct(interface 类型), type eface struct(空接口), 占用 16 字节
判断 data 指针为 0 即为 nil, 初始化后即非 0

Ref: stretchr/testify

func Nil

func Nil(tb testing.TB, value interface{}, msgAndArgs ...interface{})

func NotEmpty added in v0.9.10

func NotEmpty(tb testing.TB, value interface{}, msgAndArgs ...interface{})

func NotEqual

func NotEqual(tb testing.TB, expected, actual interface{}, msgAndArgs ...interface{})

func NotNil

func NotNil(tb testing.TB, value interface{}, msgAndArgs ...interface{})

func Panics

func Panics(t *testing.T, title string, f func())

Panics 断言 panic

func True added in v0.9.9

func True(tb testing.TB, value bool, msgAndArgs ...interface{})

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL