"first_null_row" configuration option
This commit is contained in:
@@ -646,6 +646,120 @@ func TestSaveLockfilePreservesExistingOrderAndAppendsNewKeys(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestBuildNativeAllocatesConfiguredDatasetsIntoFirstNullBaseRows(t *testing.T) {
|
||||
root := testProjectRoot(t)
|
||||
mkdirAll(t, filepath.Join(root, "topdata", "data", "portraits", "modules"))
|
||||
writeFile(t, filepath.Join(root, "topdata", "base_dialog.json"), "{}\n")
|
||||
writeFile(t, filepath.Join(root, "topdata", "data", "portraits", "base.json"), `{
|
||||
"output": "portraits.2da",
|
||||
"columns": ["BaseResRef", "Sex"],
|
||||
"rows": [
|
||||
{"id": 0, "key": "portraits:none", "BaseResRef": "****", "Sex": 4},
|
||||
{"id": 1, "BaseResRef": "****", "Sex": "****"},
|
||||
{"id": 2, "BaseResRef": null, "Sex": null},
|
||||
{"id": 3, "key": "portraits:existing", "BaseResRef": "existing_", "Sex": 1}
|
||||
]
|
||||
}`+"\n")
|
||||
writeFile(t, filepath.Join(root, "topdata", "data", "portraits", "lock.json"), `{
|
||||
"portraits:none": 0,
|
||||
"portraits:existing": 3,
|
||||
"portraits:first": 4,
|
||||
"portraits:second": 5
|
||||
}`+"\n")
|
||||
writeFile(t, filepath.Join(root, "topdata", "data", "portraits", "modules", "custom.json"), `{
|
||||
"entries": {
|
||||
"portraits:first": {"BaseResRef": "first_", "Sex": 4},
|
||||
"portraits:second": {"BaseResRef": "second_", "Sex": 4}
|
||||
}
|
||||
}`+"\n")
|
||||
|
||||
proj := testProject(root)
|
||||
proj.Config.TopData.RowGeneration = []project.TopDataRowGenerationConfig{
|
||||
{Dataset: "portraits", Mode: "first_null_row"},
|
||||
}
|
||||
result, err := BuildNativeWithOptions(proj, NativeBuildOptions{BuildWiki: false}, nil)
|
||||
if err != nil {
|
||||
t.Fatalf("BuildNativeWithOptions failed: %v", err)
|
||||
}
|
||||
|
||||
lockRaw, err := os.ReadFile(filepath.Join(root, "topdata", "data", "portraits", "lock.json"))
|
||||
if err != nil {
|
||||
t.Fatalf("read lockfile: %v", err)
|
||||
}
|
||||
lockText := string(lockRaw)
|
||||
if !strings.Contains(lockText, `"portraits:first": 1`) || !strings.Contains(lockText, `"portraits:second": 2`) {
|
||||
t.Fatalf("expected new portrait locks to use first null base rows, got:\n%s", lockText)
|
||||
}
|
||||
outputRaw, err := os.ReadFile(filepath.Join(result.Output2DADir, "portraits.2da"))
|
||||
if err != nil {
|
||||
t.Fatalf("read portraits.2da: %v", err)
|
||||
}
|
||||
output := string(outputRaw)
|
||||
for _, want := range []string{
|
||||
"1\tfirst_\t4",
|
||||
"2\tsecond_\t4",
|
||||
} {
|
||||
if !strings.Contains(output, want) {
|
||||
t.Fatalf("expected generated portraits row %q, got:\n%s", want, output)
|
||||
}
|
||||
}
|
||||
if strings.Contains(output, "4\tfirst_") || strings.Contains(output, "5\tsecond_") {
|
||||
t.Fatalf("expected portraits not to allocate after the base boundary, got:\n%s", output)
|
||||
}
|
||||
}
|
||||
|
||||
func TestMergeExpansionDataAllocatesConfiguredDatasetsIntoFirstNullRows(t *testing.T) {
|
||||
root := t.TempDir()
|
||||
lockPath := filepath.Join(root, "portraits-lock.json")
|
||||
writeFile(t, lockPath, `{
|
||||
"portraits:existing": 0,
|
||||
"portraits:expanded": 5
|
||||
}`+"\n")
|
||||
|
||||
collected, err := mergeExpansionData([]nativeCollectedDataset{
|
||||
{
|
||||
Dataset: nativeDataset{
|
||||
Kind: nativeDatasetBase,
|
||||
Name: "appearance",
|
||||
OutputName: "appearance.2da",
|
||||
RowGeneration: "after_base",
|
||||
},
|
||||
Columns: []string{"LABEL", "PORTRAIT"},
|
||||
Rows: []map[string]any{{"id": 0, "key": "appearance:source", "PORTRAIT": map[string]any{"value": "po_expanded_", "data": map[string]any{"portraits": map[string]any{"key": "portraits:expanded", "BaseResRef": "expanded_", "Sex": 4}}}}},
|
||||
LockData: map[string]int{"appearance:source": 0},
|
||||
},
|
||||
{
|
||||
Dataset: nativeDataset{
|
||||
Kind: nativeDatasetBase,
|
||||
Name: "portraits",
|
||||
LockPath: lockPath,
|
||||
OutputName: "portraits.2da",
|
||||
RowGeneration: "first_null_row",
|
||||
},
|
||||
Columns: []string{"BaseResRef", "Sex"},
|
||||
Rows: []map[string]any{{"id": 0, "key": "portraits:existing", "BaseResRef": "existing_", "Sex": 4}},
|
||||
LockData: map[string]int{"portraits:existing": 0},
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("mergeExpansionData failed: %v", err)
|
||||
}
|
||||
|
||||
portraits := collected[1]
|
||||
if got := portraits.LockData["portraits:expanded"]; got != 1 {
|
||||
t.Fatalf("expected expansion lock to use first null row 1, got %d in %#v", got, portraits.LockData)
|
||||
}
|
||||
found := false
|
||||
for _, row := range portraits.Rows {
|
||||
if row["key"] == "portraits:expanded" && row["id"] == 1 {
|
||||
found = true
|
||||
}
|
||||
}
|
||||
if !found {
|
||||
t.Fatalf("expected expanded row at id 1, got %#v", portraits.Rows)
|
||||
}
|
||||
}
|
||||
|
||||
func TestResolvedTableRegistryRejectsDuplicateKeys(t *testing.T) {
|
||||
_, err := newResolvedTableRegistry([]nativeCollectedDataset{
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user