1
0
Fork 0
mirror of https://github.com/vbatts/go-mtree.git synced 2025-10-04 04:31:00 +00:00

govis: switch to testify tests

testify makes most bog-standard test checks much easier to read and
maintain, and is quite widely used. It wasn't really well known back
when govis was first written, but the migration is fairly
straight-forward for most tests.

Signed-off-by: Aleksa Sarai <cyphar@cyphar.com>
This commit is contained in:
Aleksa Sarai 2025-09-20 06:08:34 +10:00
parent b0c7528ac6
commit d02f298ad4
No known key found for this signature in database
GPG key ID: 2897FAD2B7E9446F
4 changed files with 233 additions and 180 deletions

View file

@ -17,6 +17,11 @@
package govis
import (
"strconv"
"strings"
)
// VisFlag manipulates how the characters are encoded/decoded
type VisFlag uint
@ -37,3 +42,40 @@ const (
VisWhite VisFlag = (VisSpace | VisTab | VisNewline)
)
// String pretty-prints VisFlag.
func (vflags VisFlag) String() string {
flagNames := []struct {
name string
bits VisFlag
}{
{"VisOctal", VisOctal},
{"VisCStyle", VisCStyle},
{"VisSpace", VisSpace},
{"VisTab", VisTab},
{"VisNewline", VisNewline},
{"VisSafe", VisSafe},
{"VisNoSlash", VisNoSlash},
{"VisHTTPStyle", VisHTTPStyle},
{"VisGlob", VisGlob},
}
var (
flagSet = make([]string, 0, len(flagNames))
seenBits VisFlag
)
for _, flag := range flagNames {
if vflags&flag.bits == flag.bits {
seenBits |= flag.bits
flagSet = append(flagSet, flag.name)
}
}
// If there were any remaining flags specified we don't know the name of,
// just add them in an 0x... format.
if remaining := vflags &^ seenBits; remaining != 0 {
flagSet = append(flagSet, "0x"+strconv.FormatUint(uint64(remaining), 16))
}
if len(flagSet) == 0 {
return "0"
}
return strings.Join(flagSet, "|")
}