Files
cthulhu/internal/atspi/document_rows_test.go

55 lines
1.6 KiB
Go

// Copyright (c) 2026 Storm Dragon
// Authors: Storm Dragon, Angus Kola
// SPDX-License-Identifier: GPL-3.0-or-later
package atspi
import (
"context"
"testing"
)
func TestDocumentRowsKeepNestedTablesAndRowsSeparate(t *testing.T) {
node := func(path, role string, children ...ObjectID) TreeNode {
n := testNode(path, path, children...)
n.Snapshot.Role = role
return n
}
cell := func(path, label string, row, column int, children ...ObjectID) TreeNode {
n := node(path, "table cell", children...)
n.Snapshot.Name = label
n.Snapshot.TablePositionKnown = true
n.Snapshot.TableRowIndex, n.Snapshot.TableColumnIndex = row, column
return n
}
tree, err := NewAccessibleTree(testID("/doc"), []TreeNode{
node("/doc", "document web", testID("/sheet")),
node("/sheet", "document spreadsheet", testID("/outer")),
node("/outer", "table", testID("/b"), testID("/a"), testID("/c")),
cell("/b", "Two", 0, 1),
cell("/a", "One", 0, 0, testID("/inner")),
cell("/c", "Next", 1, 0),
node("/inner", "table", testID("/i")),
cell("/i", "Nested", 0, 0),
})
if err != nil {
t.Fatal(err)
}
root, err := tree.Root()
if err != nil {
t.Fatal(err)
}
document, err := tree.Document(context.Background(), root)
if err != nil {
t.Fatal(err)
}
wants := map[string]string{"/a": "One, Two", "/b": "One, Two", "/c": "Next", "/i": "Nested"}
for _, item := range document.Nodes {
if want, ok := wants[item.Snapshot.Path]; ok {
if item.Snapshot.TableRowText != want || !item.Snapshot.Spreadsheet {
t.Fatalf("row %s: %+v", item.Snapshot.Path, item.Snapshot)
}
}
}
}