go.charczuk.com@v0.0.0-20240327042549-bc490516bd1a/sdk/assert/its_empty.go (about) 1 /* 2 3 Copyright (c) 2023 - Present. Will Charczuk. All rights reserved. 4 Use of this source code is governed by a MIT license that can be found in the LICENSE file at the root of the repository. 5 6 */ 7 8 package assert 9 10 import "testing" 11 12 // ItsEmpty is an assertion helper. 13 // 14 // It will test that the given value is empty, printing 15 // the value if the value has a string form. 16 func ItsEmpty(t *testing.T, v any, message ...any) { 17 t.Helper() 18 if Len(v) != 0 { 19 Fatalf(t, "expected value to be empty, was %v", []any{v}, message) 20 } 21 } 22 23 // ItsNotEmpty is an assertion helper. 24 // 25 // It will test that the given value is not empty. 26 func ItsNotEmpty(t *testing.T, v any, message ...any) { 27 t.Helper() 28 if Len(v) == 0 { 29 Fatalf(t, "expected value to not be empty", nil, message) 30 } 31 } 32 33 // ItsLen is an assertion helper. 34 // 35 // It will test that the given value has a given length. 36 func ItsLen(t *testing.T, v interface{}, expected int, message ...any) { 37 t.Helper() 38 if vl := Len(v); vl != expected { 39 Fatalf(t, "expected value to have length %d, was %d", []any{expected, vl}, message) 40 } 41 }