File: ptr_test.go

package info (click to toggle)
golang-bugst-f 0.4.0-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 108 kB
  • sloc: makefile: 2
file content (30 lines) | stat: -rw-r--r-- 531 bytes parent folder | download
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
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))
	})
}