File: short-uuid_test.go

package info (click to toggle)
kitty 0.42.1-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 28,564 kB
  • sloc: ansic: 82,787; python: 55,191; objc: 5,122; sh: 1,295; xml: 364; makefile: 143; javascript: 78
file content (39 lines) | stat: -rw-r--r-- 911 bytes parent folder | download | duplicates (2)
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
// License: GPLv3 Copyright: 2022, Kovid Goyal, <kovid at kovidgoyal.net>

package utils

import (
	"math/big"
	"testing"
)

func TestShortUUID(t *testing.T) {
	a, err := HumanRandomId(128)
	if err != nil {
		t.Fatal(err)
	}
	b, err := HumanRandomId(128)
	if err != nil {
		t.Fatal(err)
	}
	if a == b {
		t.Fatalf("Two short uuid4's are unexpectedly equal")
	}
	if HumanUUID.pad_to_length != 22 {
		t.Fatalf("pad length for human UUID is %d not %d", HumanUUID.pad_to_length, 22)
	}
	u, err := HumanUUID.Uuid4()
	if err != nil {
		t.Fatal(err)
	}
	if len(u) != 22 {
		t.Fatalf("uuid4 %s has unexpected length: %d", u, len(u))
	}

	bi := big.NewInt(int64(1234567890123456789))
	q := num_to_string(bi, HumanUUID.alphabet, &HumanUUID.alphabet_len, HumanUUID.pad_to_length)
	const expected = "bzT6LtUjw4422222222222"
	if q != expected {
		t.Fatalf("unexpected short human serialization: %s != %s", q, expected)
	}
}