MCPcopy
hub / github.com/segmentio/ksuid / TestParse

Function TestParse

ksuid_test.go:64–98  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

62}
63
64func TestParse(t *testing.T) {
65 _, err := Parse("123")
66 if err != errStrSize {
67 t.Fatal("Expected Parsing a 3-char string to return an error")
68 }
69
70 parsed, err := Parse(strings.Repeat("0", stringEncodedLength))
71 if err != nil {
72 t.Fatal("Unexpected error", err)
73 }
74
75 if Compare(parsed, Nil) != 0 {
76 t.Fatal("Parsing all-zeroes string should equal Nil value",
77 "expected:", Nil,
78 "actual:", parsed)
79 }
80
81 maxBytes := make([]byte, byteLength)
82 for i := 0; i < byteLength; i++ {
83 maxBytes[i] = 255
84 }
85 maxBytesKSUID, err := FromBytes(maxBytes)
86 if err != nil {
87 t.Fatal("Unexpected error", err)
88 }
89
90 maxParseKSUID, err := Parse(maxStringEncoded)
91 if err != nil {
92 t.Fatal("Unexpected error", err)
93 }
94
95 if Compare(maxBytesKSUID, maxParseKSUID) != 0 {
96 t.Fatal("String decoder broke for max string")
97 }
98}
99
100func TestIssue25(t *testing.T) {
101 // https://github.com/segmentio/ksuid/issues/25

Callers

nothing calls this directly

Calls 3

ParseFunction · 0.85
CompareFunction · 0.85
FromBytesFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…