mirror of
https://github.com/hanzoai/mail.git
synced 2026-09-23 23:53:02 +00:00
Fork of github.com/mjl-/mox at 5656ca6d1b
(upstream v0.0.15 plus 55 commits).
Rename the module path in go.mod and the import paths in 268 Go files. Also
update the five scripts that "go install" the module (genwebsite.sh,
docker-release.sh, apidiff.sh, test-upgrade.sh, Dockerfile.release), which
would otherwise build upstream rather than this fork.
Add NOTICE recording the upstream project, author, license, and fork point,
and stating which license covers which files: MIT for the mox source and our
changes, MPL-2.0 for publicsuffix/public_suffix_list.txt alone, and the
vendored dependencies' own licenses under licenses/. Embed NOTICE so
"mail licenses" prints the lineage from the running binary. LICENSE.MIT,
LICENSE.MPLv2.0 and the licenses/ tree are preserved verbatim; no code is
relicensed.
The mox command name, config keys, data directory layout and website content
are unchanged. LLM.md records the fork point, the rename, what was left alone,
and the steps to stand the server up.
Co-authored-by: Hanzo Dev <[email protected]>
140 lines
2.4 KiB
Go
140 lines
2.4 KiB
Go
package junk
|
|
|
|
import (
|
|
"fmt"
|
|
"testing"
|
|
|
|
"github.com/hanzoai/mail/mlog"
|
|
)
|
|
|
|
func TestBloom(t *testing.T) {
|
|
if err := BloomValid(3, 10); err == nil {
|
|
t.Fatalf("missing error for invalid bloom filter size")
|
|
}
|
|
|
|
log := mlog.New("junk", nil)
|
|
_, err := NewBloom(log, make([]byte, 3), 10)
|
|
if err == nil {
|
|
t.Fatalf("missing error for invalid bloom filter size")
|
|
}
|
|
|
|
b, err := NewBloom(log, make([]byte, 256), 5)
|
|
if err != nil {
|
|
t.Fatalf("newbloom: %s", err)
|
|
}
|
|
|
|
absent := func(v string) {
|
|
t.Helper()
|
|
if b.Has(v) {
|
|
t.Fatalf("should be absent: %q", v)
|
|
}
|
|
}
|
|
|
|
present := func(v string) {
|
|
t.Helper()
|
|
if !b.Has(v) {
|
|
t.Fatalf("should be present: %q", v)
|
|
}
|
|
}
|
|
|
|
absent("test")
|
|
if b.Modified() {
|
|
t.Fatalf("bloom filter already modified?")
|
|
}
|
|
b.Add("test")
|
|
present("test")
|
|
present("test")
|
|
words := []string{}
|
|
for i := 'a'; i <= 'z'; i++ {
|
|
words = append(words, fmt.Sprintf("%c", i))
|
|
}
|
|
for _, w := range words {
|
|
absent(w)
|
|
b.Add(w)
|
|
present(w)
|
|
}
|
|
for _, w := range words {
|
|
present(w)
|
|
}
|
|
if !b.Modified() {
|
|
t.Fatalf("bloom filter was not modified?")
|
|
}
|
|
|
|
//log.Infof("ones: %d, m %d", b.Ones(), len(b.Bytes())*8)
|
|
}
|
|
|
|
func TestBits(t *testing.T) {
|
|
b := &bits{width: 1, buf: []byte{0xff, 0xff}}
|
|
for range 16 {
|
|
if b.nextPos() != 1 {
|
|
t.Fatalf("pos not 1")
|
|
}
|
|
}
|
|
b = &bits{width: 2, buf: []byte{0xff, 0xff}}
|
|
for range 8 {
|
|
if b.nextPos() != 0b11 {
|
|
t.Fatalf("pos not 0b11")
|
|
}
|
|
}
|
|
|
|
b = &bits{width: 1, buf: []byte{0b10101010, 0b10101010}}
|
|
for i := range 16 {
|
|
if b.nextPos() != ((i + 1) % 2) {
|
|
t.Fatalf("bad pos")
|
|
}
|
|
}
|
|
b = &bits{width: 2, buf: []byte{0b10101010, 0b10101010}}
|
|
for range 8 {
|
|
if b.nextPos() != 0b10 {
|
|
t.Fatalf("pos not 0b10")
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestSet(t *testing.T) {
|
|
b := &Bloom{
|
|
data: []byte{
|
|
0b10101010,
|
|
0b00000000,
|
|
0b11111111,
|
|
0b01010101,
|
|
},
|
|
}
|
|
for i := range 8 {
|
|
v := b.has(i)
|
|
if v != (i%2 == 0) {
|
|
t.Fatalf("bad has")
|
|
}
|
|
}
|
|
for i := 8; i < 16; i++ {
|
|
if b.has(i) {
|
|
t.Fatalf("bad has")
|
|
}
|
|
}
|
|
for i := 16; i < 24; i++ {
|
|
if !b.has(i) {
|
|
t.Fatalf("bad has")
|
|
}
|
|
}
|
|
for i := 24; i < 32; i++ {
|
|
v := b.has(i)
|
|
if v != (i%2 != 0) {
|
|
t.Fatalf("bad has")
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestOnes(t *testing.T) {
|
|
ones := func(b *Bloom, x int) {
|
|
t.Helper()
|
|
n := b.Ones()
|
|
if n != x {
|
|
t.Fatalf("ones: got %d, expected %d", n, x)
|
|
}
|
|
}
|
|
ones(&Bloom{data: []byte{0b10101010}}, 4)
|
|
ones(&Bloom{data: []byte{0b01010101}}, 4)
|
|
ones(&Bloom{data: []byte{0b11111111}}, 8)
|
|
ones(&Bloom{data: []byte{0b00000000}}, 0)
|
|
}
|