aboutsummaryrefslogtreecommitdiffstats
path: root/entity/id_interleaved_test.go
diff options
context:
space:
mode:
authorMichael Muré <batolettre@gmail.com>2020-11-30 01:55:30 +0100
committerMichael Muré <batolettre@gmail.com>2021-02-14 12:17:49 +0100
commitdb7074301b6af895b1a47ecd12a5028ac809abfc (patch)
tree72c9f1889aefb8c66bf4bbc027d92c6cd572bc9e /entity/id_interleaved_test.go
parentfcf43915e1736fe0b56f8f06386f68d9b56da7a8 (diff)
downloadgit-bug-db7074301b6af895b1a47ecd12a5028ac809abfc.tar.gz
entity: generalize the combined Ids, use 64 length
Diffstat (limited to 'entity/id_interleaved_test.go')
-rw-r--r--entity/id_interleaved_test.go36
1 files changed, 36 insertions, 0 deletions
diff --git a/entity/id_interleaved_test.go b/entity/id_interleaved_test.go
new file mode 100644
index 00000000..ef9218c9
--- /dev/null
+++ b/entity/id_interleaved_test.go
@@ -0,0 +1,36 @@
+package entity
+
+import (
+ "testing"
+
+ "github.com/stretchr/testify/require"
+)
+
+func TestInterleaved(t *testing.T) {
+ primary := Id("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWX______________")
+ secondary := Id("YZ0123456789+/________________________________________________")
+ expectedId := Id("aYbZc0def1ghij2klmn3opqr4stuv5wxyz6ABCD7EFGH8IJKL9MNOP+QRST/UVWX")
+
+ interleaved := CombineIds(primary, secondary)
+ require.Equal(t, expectedId, interleaved)
+
+ // full length
+ splitPrimary, splitSecondary := SeparateIds(interleaved.String())
+ require.Equal(t, string(primary[:50]), splitPrimary)
+ require.Equal(t, string(secondary[:14]), splitSecondary)
+
+ // partial
+ splitPrimary, splitSecondary = SeparateIds(string(expectedId[:7]))
+ require.Equal(t, string(primary[:4]), splitPrimary)
+ require.Equal(t, string(secondary[:3]), splitSecondary)
+
+ // partial
+ splitPrimary, splitSecondary = SeparateIds(string(expectedId[:10]))
+ require.Equal(t, string(primary[:6]), splitPrimary)
+ require.Equal(t, string(secondary[:4]), splitSecondary)
+
+ // partial
+ splitPrimary, splitSecondary = SeparateIds(string(expectedId[:16]))
+ require.Equal(t, string(primary[:11]), splitPrimary)
+ require.Equal(t, string(secondary[:5]), splitSecondary)
+}