forked from gobuffalo/plush
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathintern_test.go
More file actions
55 lines (39 loc) · 945 Bytes
/
Copy pathintern_test.go
File metadata and controls
55 lines (39 loc) · 945 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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package plush_test
import (
"testing"
"github.com/gobuffalo/plush/v5"
"github.com/stretchr/testify/require"
)
func TestInternTable(t *testing.T) {
r := require.New(t)
it := plush.NewInternTable()
r.NotNil(it)
// Intern a new string
id1 := it.Intern("alpha")
r.Equal(0, id1)
// Intern another string
id2 := it.Intern("beta")
r.Equal(1, id2)
// Re-intern the first string
id1Again := it.Intern("alpha")
r.Equal(id1, id1Again)
// Lookup existing string
lookupID, found := it.Lookup("beta")
r.True(found)
r.NotEqual(id1, lookupID)
r.Equal(id2, lookupID)
// Lookup non-existent string
_, found = it.Lookup("gamma")
r.False(found)
// SymbolName for known ID
name := it.SymbolName(id1)
r.Equal("alpha", name)
// SymbolName for unknown ID
unknown := it.SymbolName(999)
r.Equal("<unknown>", unknown)
}
func TestNewInternTable(t *testing.T) {
r := require.New(t)
rs := plush.NewInternTable()
r.NotNil(rs)
}