GoToSocial/vendor/codeberg.org/gruf/go-bitutil/flag_test.tpl
tobi 5004e0a9da
[bugfix] Fix remote media pruning failing if media already gone (#548)
* fix error check of prune to allow missing files

* update go-store library, add test for pruning item with db entry but no file

Signed-off-by: kim <grufwub@gmail.com>

* remove now-unneccessary error check

Signed-off-by: kim <grufwub@gmail.com>

Co-authored-by: kim <grufwub@gmail.com>
2022-05-08 18:49:45 +01:00

98 lines
2.2 KiB
Smarty

package bitutil_test
import (
"strings"
"testing"
"codeberg.org/gruf/go-bytes"
)
{{ range $idx, $size := . }}
func TestFlags{{ $size.Size }}Get(t *testing.T) {
var mask, flags bitutil.Flags{{ $size.Size }}
{{ range $idx := $size.Bits }}
mask = bitutil.Flags{{ $size.Size }}(1) << {{ $idx }}
flags = 0
flags |= mask
if !flags.Get({{ $idx }}) {
t.Error("failed .Get() set Flags{{ $size.Size }} bit at index {{ $idx }}")
}
flags = ^bitutil.Flags{{ $size.Size }}(0)
flags &= ^mask
if flags.Get({{ $idx }}) {
t.Error("failed .Get() unset Flags{{ $size.Size }} bit at index {{ $idx }}")
}
flags = 0
flags |= mask
if !flags.Get{{ $idx }}() {
t.Error("failed .Get{{ $idx }}() set Flags{{ $size.Size }} bit at index {{ $idx }}")
}
flags = ^bitutil.Flags{{ $size.Size }}(0)
flags &= ^mask
if flags.Get{{ $idx }}() {
t.Error("failed .Get{{ $idx }}() unset Flags{{ $size.Size }} bit at index {{ $idx }}")
}
{{ end }}
}
func TestFlags{{ $size.Size }}Set(t *testing.T) {
var mask, flags bitutil.Flags{{ $size.Size }}
{{ range $idx := $size.Bits }}
mask = bitutil.Flags{{ $size.Size }}(1) << {{ $idx }}
flags = 0
flags = flags.Set({{ $idx }})
if flags & mask == 0 {
t.Error("failed .Set() Flags{{ $size.Size }} bit at index {{ $idx }}")
}
flags = 0
flags = flags.Set{{ $idx }}()
if flags & mask == 0 {
t.Error("failed .Set{{ $idx }}() Flags{{ $size.Size }} bit at index {{ $idx }}")
}
{{ end }}
}
func TestFlags{{ $size.Size }}Unset(t *testing.T) {
var mask, flags bitutil.Flags{{ $size.Size }}
{{ range $idx := $size.Bits }}
mask = bitutil.Flags{{ $size.Size }}(1) << {{ $idx }}
flags = ^bitutil.Flags{{ $size.Size }}(0)
flags = flags.Unset({{ $idx }})
if flags & mask != 0 {
t.Error("failed .Unset() Flags{{ $size.Size }} bit at index {{ $idx }}")
}
flags = ^bitutil.Flags{{ $size.Size }}(0)
flags = flags.Unset{{ $idx }}()
if flags & mask != 0 {
t.Error("failed .Unset{{ $idx }}() Flags{{ $size.Size }} bit at index {{ $idx }}")
}
{{ end }}
}
{{ end }}