add-space-after-colon #211

Merged
lash merged 20 commits from add-space-after-colon into master 2024-12-19 11:35:14 +01:00
Showing only changes of commit ecfdab47a8 - Show all commits

View File

@ -5,6 +5,7 @@ import (
"fmt" "fmt"
"log" "log"
"path" "path"
"strings"
"testing" "testing"
"git.defalsify.org/vise.git/lang" "git.defalsify.org/vise.git/lang"
@ -67,12 +68,20 @@ func TestNewHandlers(t *testing.T) {
_, store := InitializeTestStore(t) _, store := InitializeTestStore(t)
fm, err := NewFlagManager(flagsPath) fm, err := NewFlagManager(flagsPath)
accountService := testservice.TestAccountService{}
if err != nil { if err != nil {
t.Logf(err.Error()) log.Fatal(err)
} }
accountService := testservice.TestAccountService{}
// Mock function for replaceSeparator
mockReplaceSeparator := func(input string) string {
return strings.ReplaceAll(input, ":", ": ")
}
// Test case for valid UserDataStore
t.Run("Valid UserDataStore", func(t *testing.T) { t.Run("Valid UserDataStore", func(t *testing.T) {
handlers, err := NewHandlers(fm.parser, store, nil, &accountService) handlers, err := NewHandlers(fm.parser, store, nil, &accountService, mockReplaceSeparator)
if err != nil { if err != nil {
t.Fatalf("expected no error, got %v", err) t.Fatalf("expected no error, got %v", err)
} }
@ -82,19 +91,30 @@ func TestNewHandlers(t *testing.T) {
if handlers.userdataStore == nil { if handlers.userdataStore == nil {
t.Fatal("expected userdataStore to be set in handlers") t.Fatal("expected userdataStore to be set in handlers")
} }
if handlers.ReplaceSeparator == nil {
t.Fatal("expected ReplaceSeparator to be set in handlers")
}
// Test ReplaceSeparator functionality
input := "1:Menu item"
expectedOutput := "1: Menu item"
if handlers.ReplaceSeparator(input) != expectedOutput {
t.Fatalf("ReplaceSeparator function did not return expected output: got %v, want %v", handlers.ReplaceSeparator(input), expectedOutput)
}
}) })
// Test case for nil userdataStore // Test case for nil UserDataStore
t.Run("Nil UserDataStore", func(t *testing.T) { t.Run("Nil UserDataStore", func(t *testing.T) {
handlers, err := NewHandlers(fm.parser, nil, nil, &accountService) handlers, err := NewHandlers(fm.parser, nil, nil, &accountService, mockReplaceSeparator)
if err == nil { if err == nil {
t.Fatal("expected an error, got none") t.Fatal("expected an error, got none")
} }
if handlers != nil { if handlers != nil {
t.Fatal("expected handlers to be nil") t.Fatal("expected handlers to be nil")
} }
if err.Error() != "cannot create handler with nil userdata store" { expectedError := "cannot create handler with nil userdata store"
t.Fatalf("expected specific error, got %v", err) if err.Error() != expectedError {
t.Fatalf("expected error '%s', got '%v'", expectedError, err)
} }
}) })
} }
@ -1982,30 +2002,36 @@ func TestCheckVouchers(t *testing.T) {
func TestGetVoucherList(t *testing.T) { func TestGetVoucherList(t *testing.T) {
sessionId := "session123" sessionId := "session123"
menuSeparator := ":"
ctx := context.WithValue(context.Background(), "SessionId", sessionId) ctx := context.WithValue(context.Background(), "SessionId", sessionId)
ctx = context.WithValue(ctx, "MenuSeparator", menuSeparator)
spdb := InitializeTestSubPrefixDb(t, ctx) spdb := InitializeTestSubPrefixDb(t, ctx)
h := &Handlers{ // Mock replaceSeparator function
prefixDb: spdb, replaceSeparator := func(input string) string {
return strings.ReplaceAll(input, ":", ": ")
} }
expectedSym := []byte("1:SRF\n2:MILO") // Initialize Handlers
h := &Handlers{
prefixDb: spdb,
ReplaceSeparator: replaceSeparator,
}
mockSyms := []byte("1:SRF\n2:MILO")
// Put voucher sym data from the store // Put voucher sym data from the store
err := spdb.Put(ctx, common.ToBytes(common.DATA_VOUCHER_SYMBOLS), expectedSym) err := spdb.Put(ctx, common.ToBytes(common.DATA_VOUCHER_SYMBOLS), mockSyms)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
expectedSyms := []byte("1: SRF\n2: MILO")
res, err := h.GetVoucherList(ctx, "", []byte("")) res, err := h.GetVoucherList(ctx, "", []byte(""))
assert.NoError(t, err) assert.NoError(t, err)
assert.Equal(t, res.Content, string(expectedSym)) assert.Equal(t, res.Content, string(expectedSyms))
} }
func TestViewVoucher(t *testing.T) { func TestViewVoucher(t *testing.T) {