| 62 | } |
| 63 | |
| 64 | func 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 | |
| 100 | func TestIssue25(t *testing.T) { |
| 101 | // https://github.com/segmentio/ksuid/issues/25 |