Reverse allowlist
This commit is contained in:
@@ -202,7 +202,7 @@ func TestBuildNativeEncodesConfiguredPackedHexLists(t *testing.T) {
|
||||
{
|
||||
"key": "racialtypes:human",
|
||||
"AvailableHeadsMale": {"list": [1, 10, 999]},
|
||||
"AvailableHeadsFemale": {"list": [{"range": [1, 3]}]},
|
||||
"AvailableHeadsFemale": {"all_except": {"min": "001", "max": "003", "values": []}},
|
||||
"AvailableSkinColors": {
|
||||
"list": [
|
||||
{"range": [0, 12]},
|
||||
@@ -285,6 +285,131 @@ func TestValidateProjectRejectsInvalidConfiguredPackedHexList(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestEncodeConfiguredPackedHexListSupportsAllExcept(t *testing.T) {
|
||||
encoding := project.TopDataValueEncodingConfig{
|
||||
Dataset: "racialtypes/core",
|
||||
Column: "AvailableHeadsMale",
|
||||
Mode: "packed_hex_list",
|
||||
Min: 0,
|
||||
Max: 999,
|
||||
HexWidth: 3,
|
||||
}
|
||||
|
||||
got, err := encodeConfiguredValueList(map[string]any{
|
||||
"all_except": map[string]any{
|
||||
"min": "001",
|
||||
"max": "010",
|
||||
"values": []any{"002", float64(5), map[string]any{"range": []any{"007", "008"}}},
|
||||
},
|
||||
}, encoding)
|
||||
if err != nil {
|
||||
t.Fatalf("encodeConfiguredValueList failed: %v", err)
|
||||
}
|
||||
want := "0x00100300400600900A"
|
||||
if got != want {
|
||||
t.Fatalf("expected %q, got %q", want, got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestEncodeConfiguredPackedHexListAllExceptUsesConfiguredBounds(t *testing.T) {
|
||||
encoding := project.TopDataValueEncodingConfig{
|
||||
Dataset: "racialtypes/core",
|
||||
Column: "AvailableSkinColors",
|
||||
Mode: "packed_hex_list",
|
||||
Min: 0,
|
||||
Max: 5,
|
||||
HexWidth: 2,
|
||||
}
|
||||
|
||||
got, err := encodeConfiguredValueList(map[string]any{
|
||||
"all_except": map[string]any{
|
||||
"values": []any{float64(1), "04"},
|
||||
},
|
||||
}, encoding)
|
||||
if err != nil {
|
||||
t.Fatalf("encodeConfiguredValueList failed: %v", err)
|
||||
}
|
||||
want := "0x00020305"
|
||||
if got != want {
|
||||
t.Fatalf("expected %q, got %q", want, got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestEncodeConfiguredPackedHexListAllExceptRejectsInvalidInput(t *testing.T) {
|
||||
encoding := project.TopDataValueEncodingConfig{
|
||||
Dataset: "racialtypes/core",
|
||||
Column: "AvailableHeadsMale",
|
||||
Mode: "packed_hex_list",
|
||||
Min: 0,
|
||||
Max: 999,
|
||||
HexWidth: 3,
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
obj map[string]any
|
||||
want string
|
||||
}{
|
||||
{
|
||||
name: "mixed list and all_except",
|
||||
obj: map[string]any{
|
||||
"list": []any{float64(1)},
|
||||
"all_except": map[string]any{"values": []any{float64(2)}},
|
||||
},
|
||||
want: "cannot contain both list and all_except",
|
||||
},
|
||||
{
|
||||
name: "unknown outer key",
|
||||
obj: map[string]any{
|
||||
"all_except": map[string]any{"values": []any{float64(2)}},
|
||||
"notes": "unused",
|
||||
},
|
||||
want: `contains unsupported key "notes"`,
|
||||
},
|
||||
{
|
||||
name: "unknown all_except key",
|
||||
obj: map[string]any{
|
||||
"all_except": map[string]any{
|
||||
"values": []any{float64(2)},
|
||||
"notes": "unused",
|
||||
},
|
||||
},
|
||||
want: `all_except contains unsupported key "notes"`,
|
||||
},
|
||||
{
|
||||
name: "excluded value outside effective range",
|
||||
obj: map[string]any{
|
||||
"all_except": map[string]any{
|
||||
"max": "010",
|
||||
"values": []any{"011"},
|
||||
},
|
||||
},
|
||||
want: "value 11 outside all_except range 0-10",
|
||||
},
|
||||
{
|
||||
name: "reversed effective range",
|
||||
obj: map[string]any{
|
||||
"all_except": map[string]any{
|
||||
"min": "010",
|
||||
"max": "009",
|
||||
"values": []any{},
|
||||
},
|
||||
},
|
||||
want: "all_except max 9 is less than min 10",
|
||||
},
|
||||
}
|
||||
for _, test := range tests {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
_, err := encodeConfiguredValueList(test.obj, encoding)
|
||||
if err == nil {
|
||||
t.Fatalf("expected error containing %q", test.want)
|
||||
}
|
||||
if !strings.Contains(err.Error(), test.want) {
|
||||
t.Fatalf("expected error containing %q, got %q", test.want, err.Error())
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestValidateProjectRejectsDuplicateEntryKeysAcrossModules(t *testing.T) {
|
||||
root := testProjectRoot(t)
|
||||
mkdirAll(t, filepath.Join(root, "topdata", "data", "baseitems", "modules"))
|
||||
|
||||
Reference in New Issue
Block a user