Files

89 lines
2.5 KiB
Go

// Cthulhu screen reader.
// Copyright (c) 2026 Storm Dragon
// Authors: Storm Dragon, Angus Kola
//
// This program is free software: you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by the Free
// Software Foundation, either version 3 of the License, or (at your option)
// any later version.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
// more details.
//
// You should have received a copy of the GNU General Public License along with
// this program. If not, see <https://www.gnu.org/licenses/gpl-3.0.html>.
package parity
import (
"errors"
"strings"
"testing"
)
func TestLoadValidLedger(t *testing.T) {
ledger := strings.Join([]string{
strings.Join(columns, ","),
"core-startup,src/cthulhu/cthulhu.py,core,start the screen reader,Storm Dragon,internal/app,pending,,,,,,initial inventory",
"web-navigation,src/cthulhu/scripts/web/script.py,web,structural navigation,Storm Dragon,internal/script,pending,,,,,,initial inventory",
}, "\n")
records, err := Load(strings.NewReader(ledger))
if err != nil {
t.Fatalf("Load: %v", err)
}
if len(records) != 2 {
t.Fatalf("record count = %d, want 2", len(records))
}
}
func TestLoadRejectsInvalidRecords(t *testing.T) {
tests := []struct {
name string
ledger string
wantErr error
}{
{
name: "missing header",
ledger: "id\n",
wantErr: ErrSchema,
},
{
name: "invalid status",
ledger: strings.Join([]string{
strings.Join(columns, ","),
"one,source.py,core,behavior,owner,destination,unknown,,,,,,note",
}, "\n"),
wantErr: ErrSchema,
},
{
name: "duplicate id",
ledger: strings.Join([]string{
strings.Join(columns, ","),
"one,source.py,core,behavior,owner,destination,pending,,,,,,note",
"one,source.py,core,behavior,owner,destination,pending,,,,,,note",
}, "\n"),
wantErr: ErrSchema,
},
{
name: "missing destination",
ledger: strings.Join([]string{
strings.Join(columns, ","),
"one,source.py,core,behavior,owner,,pending,,,,,,note",
}, "\n"),
wantErr: ErrSchema,
},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
_, err := Load(strings.NewReader(test.ledger))
if !errors.Is(err, test.wantErr) {
t.Fatalf("Load error = %v, want %v", err, test.wantErr)
}
})
}
}