List/range support
This commit is contained in:
@@ -179,6 +179,112 @@ func TestValidateProjectRejectsInvalidModuleColumnExpansionFile(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestBuildNativeEncodesConfiguredPackedHexLists(t *testing.T) {
|
||||
root := testProjectRoot(t)
|
||||
mkdirAll(t, filepath.Join(root, "topdata", "data", "racialtypes", "core", "modules"))
|
||||
writeFile(t, filepath.Join(root, "topdata", "base_dialog.json"), "{}\n")
|
||||
writeFile(t, filepath.Join(root, "topdata", "data", "racialtypes", "core", "base.json"), `{
|
||||
"output": "racialtypes.2da",
|
||||
"columns": ["Label", "StartLanguages", "BonusLanguages", "AvailableHeadsMale", "AvailableHeadsFemale", "AvailableSkinColors"],
|
||||
"rows": [
|
||||
{
|
||||
"id": 6,
|
||||
"key": "racialtypes:human",
|
||||
"Label": "Human",
|
||||
"StartLanguages": "regional",
|
||||
"BonusLanguages": "all"
|
||||
}
|
||||
]
|
||||
}`+"\n")
|
||||
writeFile(t, filepath.Join(root, "topdata", "data", "racialtypes", "core", "lock.json"), `{"racialtypes:human":6}`+"\n")
|
||||
writeFile(t, filepath.Join(root, "topdata", "data", "racialtypes", "core", "modules", "10_human.json"), `{
|
||||
"overrides": [
|
||||
{
|
||||
"key": "racialtypes:human",
|
||||
"AvailableHeadsMale": {"list": [1, 10, 999]},
|
||||
"AvailableHeadsFemale": {"list": [{"range": [1, 3]}]},
|
||||
"AvailableSkinColors": {
|
||||
"list": [
|
||||
{"range": [0, 12]},
|
||||
24,
|
||||
74,
|
||||
{"range": [116, 119]},
|
||||
{"range": [128, 131]},
|
||||
156,
|
||||
157,
|
||||
168,
|
||||
170,
|
||||
174
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
}`+"\n")
|
||||
|
||||
proj := testProject(root)
|
||||
proj.Config.TopData.ValueEncodings = []project.TopDataValueEncodingConfig{
|
||||
{Dataset: "racialtypes/core", Column: "AvailableHeadsMale", Mode: "packed_hex_list", Min: 0, Max: 999, HexWidth: 3},
|
||||
{Dataset: "racialtypes/core", Column: "AvailableHeadsFemale", Mode: "packed_hex_list", Min: 0, Max: 999, HexWidth: 3},
|
||||
{Dataset: "racialtypes/core", Column: "AvailableSkinColors", Mode: "packed_hex_list", Min: 0, Max: 175, HexWidth: 2},
|
||||
}
|
||||
|
||||
result, err := BuildNativeWithOptions(proj, NativeBuildOptions{BuildWiki: false}, nil)
|
||||
if err != nil {
|
||||
t.Fatalf("BuildNativeWithOptions failed: %v", err)
|
||||
}
|
||||
raw, err := os.ReadFile(filepath.Join(result.Output2DADir, "racialtypes.2da"))
|
||||
if err != nil {
|
||||
t.Fatalf("read racialtypes.2da: %v", err)
|
||||
}
|
||||
got := string(raw)
|
||||
for _, want := range []string{
|
||||
"regional",
|
||||
"all",
|
||||
"0x00100A3E7",
|
||||
"0x001002003",
|
||||
"0x000102030405060708090A0B0C184A74757677808182839C9DA8AAAE",
|
||||
} {
|
||||
if !strings.Contains(got, want) {
|
||||
t.Fatalf("expected compiled racialtypes.2da to contain %q, got:\n%s", want, got)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestValidateProjectRejectsInvalidConfiguredPackedHexList(t *testing.T) {
|
||||
root := testProjectRoot(t)
|
||||
mkdirAll(t, filepath.Join(root, "topdata", "data", "racialtypes", "core", "modules"))
|
||||
writeFile(t, filepath.Join(root, "topdata", "base_dialog.json"), "{}\n")
|
||||
writeFile(t, filepath.Join(root, "topdata", "data", "racialtypes", "core", "base.json"), `{
|
||||
"output": "racialtypes.2da",
|
||||
"columns": ["Label", "AvailableSkinColors"],
|
||||
"rows": [
|
||||
{"id": 6, "key": "racialtypes:human", "Label": "Human"}
|
||||
]
|
||||
}`+"\n")
|
||||
writeFile(t, filepath.Join(root, "topdata", "data", "racialtypes", "core", "lock.json"), `{"racialtypes:human":6}`+"\n")
|
||||
writeFile(t, filepath.Join(root, "topdata", "data", "racialtypes", "core", "modules", "10_human.json"), `{
|
||||
"overrides": [
|
||||
{
|
||||
"key": "racialtypes:human",
|
||||
"AvailableSkinColors": {"list": [{"range": [12, 0]}]}
|
||||
}
|
||||
]
|
||||
}`+"\n")
|
||||
|
||||
proj := testProject(root)
|
||||
proj.Config.TopData.ValueEncodings = []project.TopDataValueEncodingConfig{
|
||||
{Dataset: "racialtypes/core", Column: "AvailableSkinColors", Mode: "packed_hex_list", Min: 0, Max: 175, HexWidth: 2},
|
||||
}
|
||||
|
||||
report := ValidateProject(proj)
|
||||
if !report.HasErrors() {
|
||||
t.Fatalf("expected invalid packed hex list to fail validation, got:\n%s", diagnosticsText(report.Diagnostics))
|
||||
}
|
||||
if !diagnosticsContain(report.Diagnostics, "range 12-0 ends before it starts") {
|
||||
t.Fatalf("expected reversed range diagnostic, got:\n%s", diagnosticsText(report.Diagnostics))
|
||||
}
|
||||
}
|
||||
|
||||
func TestValidateProjectRejectsDuplicateEntryKeysAcrossModules(t *testing.T) {
|
||||
root := testProjectRoot(t)
|
||||
mkdirAll(t, filepath.Join(root, "topdata", "data", "baseitems", "modules"))
|
||||
|
||||
Reference in New Issue
Block a user