47 lines
758 B
Go
47 lines
758 B
Go
|
/*
|
||
|
* SPDX-FileCopyrightText: 2023 jordi fita mas <jfita@peritasoft.com>
|
||
|
* SPDX-License-Identifier: AGPL-3.0-only
|
||
|
*/
|
||
|
|
||
|
package hex
|
||
|
|
||
|
import (
|
||
|
"strings"
|
||
|
"testing"
|
||
|
)
|
||
|
|
||
|
type test struct {
|
||
|
in string
|
||
|
isHex bool
|
||
|
}
|
||
|
|
||
|
var tests = []test{
|
||
|
{"f4", true},
|
||
|
{"2b", true},
|
||
|
{"19", true},
|
||
|
{"aa", true},
|
||
|
{"ff", true},
|
||
|
{"00", true},
|
||
|
{"bc", true},
|
||
|
{"de", true},
|
||
|
{"ef", true},
|
||
|
{"fe", true},
|
||
|
{"1g", false},
|
||
|
{"gb", false},
|
||
|
{"zb", false},
|
||
|
{"2x", false},
|
||
|
}
|
||
|
|
||
|
func testValid(t *testing.T, in string, isHex bool) {
|
||
|
if ok := Valid(in[0], in[1]); ok != isHex {
|
||
|
t.Errorf("Valid(%s) got %v expected %v", in, ok, isHex)
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func TestHex(t *testing.T) {
|
||
|
for _, tt := range tests {
|
||
|
testValid(t, tt.in, tt.isHex)
|
||
|
testValid(t, strings.ToUpper(tt.in), tt.isHex)
|
||
|
}
|
||
|
}
|