-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchunk_internal_test.go
More file actions
70 lines (60 loc) · 1.66 KB
/
chunk_internal_test.go
File metadata and controls
70 lines (60 loc) · 1.66 KB
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
package sqlitecloud
import (
"fmt"
"strings"
"testing"
)
type testStringEnum string
type testIntEnum int
func TestProtocolBufferFromValueSupportsStringAlias(t *testing.T) {
val := testStringEnum("active")
buffers, err := protocolBufferFromValue(val)
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
if len(buffers) != 1 {
t.Fatalf("expected 1 buffer, got %d", len(buffers))
}
got := string(buffers[0])
want := fmt.Sprintf("%c%d %s\x00", CMD_ZEROSTRING, len("active")+1, "active")
if got != want {
t.Fatalf("unexpected encoded value: want %q got %q", want, got)
}
}
func TestProtocolBufferFromValueSupportsIntAliasPointer(t *testing.T) {
raw := testIntEnum(7)
buffers, err := protocolBufferFromValue(&raw)
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
if len(buffers) != 1 {
t.Fatalf("expected 1 buffer, got %d", len(buffers))
}
got := string(buffers[0])
want := fmt.Sprintf("%c%d ", CMD_INT, 7)
if got != want {
t.Fatalf("unexpected encoded value: want %q got %q", want, got)
}
}
func TestProtocolBufferFromValueSupportsFloat32(t *testing.T) {
buffers, err := protocolBufferFromValue(float32(2.5))
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
if len(buffers) != 1 {
t.Fatalf("expected 1 buffer, got %d", len(buffers))
}
got := string(buffers[0])
if !strings.HasPrefix(got, fmt.Sprintf("%c", CMD_FLOAT)) {
t.Fatalf("expected float buffer prefix, got %q", got)
}
}
func TestProtocolBufferFromValueUnsupportedTypeReturnsError(t *testing.T) {
type unsupported struct {
Name string
}
_, err := protocolBufferFromValue(unsupported{Name: "x"})
if err == nil {
t.Fatalf("expected error for unsupported type")
}
}