Files
cthulhu/internal/presentation/libreoffice_selection_test.go
2026-10-15 01:10:43 -04:00

46 lines
2.2 KiB
Go

// Copyright (c) 2026 Storm Dragon
// Authors: Storm Dragon, Angus Kola
// SPDX-License-Identifier: GPL-3.0-or-later
package presentation
import (
"testing"
"git.stormux.org/storm/cthulhu/internal/atspi"
)
func TestLibreOfficeSelectionPreservesGapsAndBoundsOutput(t *testing.T) {
for _, test := range []struct {
name string
selection atspi.LibreOfficeSelection
want string
}{
{"rectangle", atspi.LibreOfficeSelection{Kind: "cells", Count: 4, Complete: true,
Cells: []atspi.LibreOfficeCell{{Row: 0, Column: 0}, {Row: 0, Column: 1}, {Row: 1, Column: 0}, {Row: 1, Column: 1}}}, "Cells A1 to B2 selected."},
{"disjoint", atspi.LibreOfficeSelection{Kind: "cells", Count: 4, Complete: true,
Cells: []atspi.LibreOfficeCell{{Row: 0, Column: 0}, {Row: 0, Column: 1}, {Row: 0, Column: 3}, {Row: 1, Column: 3}}}, "Cells A1 to B1 selected. Cells D1 to D2 selected."},
{"row gaps", atspi.LibreOfficeSelection{Kind: "rows", Count: 3, Complete: true,
Cells: []atspi.LibreOfficeCell{{Row: 0, Column: 0}, {Row: 1, Column: 0}, {Row: 3, Column: 0}}}, "Rows 1 to 2 selected. Row 4 selected."},
{"column labels", atspi.LibreOfficeSelection{Kind: "columns", Count: 2, Complete: true,
Cells: []atspi.LibreOfficeCell{{Row: 0, Column: 25}, {Row: 0, Column: 26}}}, "Columns Z to AA selected."},
{"large", atspi.LibreOfficeSelection{Kind: "cells", Count: 1000000000,
First: atspi.LibreOfficeCell{Row: 0, Column: 0}, Last: atspi.LibreOfficeCell{Row: 999999, Column: 999}}, "1000000000 cells selected."},
{"capped", atspi.LibreOfficeSelection{Kind: "cells", Count: 2147483647, CountLimited: true}, "At least 2147483647 cells selected."},
{"all", atspi.LibreOfficeSelection{Kind: "all", Complete: true}, "All cells selected."},
} {
t.Run(test.name, func(t *testing.T) {
if got := LibreOfficeSelectionText(test.selection, "selected"); got != test.want {
t.Fatalf("got %q, want %q", got, test.want)
}
})
}
selection := atspi.LibreOfficeSelection{Kind: "cells", Count: 9, Complete: true}
for index := 0; index < 9; index++ {
selection.Cells = append(selection.Cells, atspi.LibreOfficeCell{Row: index, Column: index})
}
if got := LibreOfficeSelectionText(selection, "unselected"); got != "9 cells unselected." {
t.Fatalf("fragmented selection = %q", got)
}
}