Files

47 lines
2.7 KiB
Go

// Fenrir console screen reader.
// Copyright (c) 2026 Storm Dragon
// SPDX-License-Identifier: GPL-3.0-or-later
//
// 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 reader
import (
"reflect"
"testing"
"git.stormux.org/storm/fenrir/internal/presentation"
)
func TestScrollInsideFixedStatusAndInputRows(t *testing.T) {
for _, testCase := range []struct {
name string
before, after []string
want []presentation.Message
}{
{"send message", []string{"channel", "old", "keep one", "keep two", "last", "status", "> message"}, []string{"channel", "keep one", "keep two", "last", "new message", "status", "> "}, []presentation.Message{{Text: "new message"}, {Text: ">"}}},
{"incoming message", []string{"channel", "old", "keep one", "keep two", "last", "status", "> draft"}, []string{"channel", "keep one", "keep two", "last", "new message", "status", "> draft"}, []presentation.Message{{Text: "new message"}}},
{"shared prefix", []string{"channel", "old", "keep one", "keep two", "chat: earlier", "status"}, []string{"channel", "keep one", "keep two", "chat: earlier", "chat: new", "status"}, []presentation.Message{{Text: "chat: new"}}},
{"batched lines", []string{"header", "old one", "old two", "keep one", "keep two", "status"}, []string{"header", "keep one", "keep two", "new one", "new two", "new status"}, []presentation.Message{{Text: "new one"}, {Text: "new two"}, {Text: "new status"}}},
{"unrelated redraw", []string{"header", "old one", "old two", "old three", "status"}, []string{"header", "new one", "new two", "new three", "status"}, []presentation.Message{{Text: "new one"}, {Text: "new two"}, {Text: "new three"}}},
{"isolated coincident row", []string{"header", "old", "same", "last", "status"}, []string{"header", "same", "different", "fresh", "status"}, []presentation.Message{{Text: "same"}, {Text: "different"}, {Text: "fresh"}}},
} {
t.Run(testCase.name, func(t *testing.T) {
if got := changes(fixture(testCase.before...), fixture(testCase.after...), true); !reflect.DeepEqual(got, testCase.want) {
t.Fatalf("got %v, want %v", got, testCase.want)
}
})
}
}