-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathptr_test.go
More file actions
38 lines (30 loc) · 769 Bytes
/
ptr_test.go
File metadata and controls
38 lines (30 loc) · 769 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
//
// This file is part of go-algorithms.
//
// Copyright (c) 2024-2026 go-algorithms (go.bug.st/f) authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//
package f_test
import (
"testing"
"github.com/stretchr/testify/assert"
f "go.bug.st/f"
)
func TestPtr(t *testing.T) {
t.Run("int", func(t *testing.T) {
assert.Equal(t, 12, *f.Ptr(12))
})
t.Run("string", func(t *testing.T) {
assert.Equal(t, "hello", *f.Ptr("hello"))
})
}
func TestUnwrapOrDefault(t *testing.T) {
t.Run("not nil", func(t *testing.T) {
given := 12
assert.Equal(t, 12, f.UnwrapOrDefault(&given))
})
t.Run("nil", func(t *testing.T) {
assert.Equal(t, "", f.UnwrapOrDefault[string](nil))
})
}