-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtype_test.go
71 lines (65 loc) · 1.73 KB
/
type_test.go
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package stream_test
import (
"testing"
"github.com/sokool/stream"
)
func TestNewType(t *testing.T) {
type foo struct{}
if s, err := stream.NewType[foo](); s.String() != "Foo" || err != nil {
t.Fatal(err, s)
}
if s, err := stream.NewType(foo{}); s.String() != "Foo" || err != nil {
t.Fatal(err, s)
}
if s, err := stream.NewType(&foo{}); s.String() != "Foo" || err != nil {
t.Fatal(err, s)
}
if s, err := stream.NewType[*foo](); s.String() != "Foo" || err != nil {
t.Fatal(err, s)
}
if s, err := stream.NewType(any(foo{})); s.String() != "Foo" || err != nil {
t.Fatal(err, s)
}
if s, err := stream.NewType[string](); s.String() != "String" || err != nil {
t.Fatal(err, s)
}
if s, err := stream.NewType("hi"); s.String() != "Hi" || err != nil {
t.Fatal(err, s)
}
if s, err := stream.NewType(" nIcE fORMat "); s.String() != "NIcEfORMat" || err != nil {
t.Fatal(err, s)
}
if _, err := stream.NewType(""); err == nil {
t.Fatalf("error expected")
}
}
func TestType_NewID(t *testing.T) {
type lol struct{}
s, err := stream.NewType[lol]()
if err != nil {
t.Fatal(err)
}
if s.ID("hi").String() != "297f69d4.Lol" {
t.Fatal()
}
}
func TestType_Hash(t *testing.T) {
type scenario struct {
description string
typ stream.Type
}
cases := []scenario{
{"scenario string", stream.MustType("scenario")},
{"` S cen ar i o ` string", stream.MustType(" S cen ar i o ")},
{"scenario generic", stream.MustType[scenario]()},
{"scenario struct", stream.MustType(scenario{})},
}
hash := "864f8517-abf8-578f-a294-82b3c51a54f6"
for _, c := range cases {
t.Run(c.description, func(t *testing.T) {
if s := c.typ.Hash().String(); s != hash {
t.Fatalf("expected `%s`, got `%s`", hash, s)
}
})
}
}