mirror of
https://github.com/taigrr/teaqlite.git
synced 2026-04-02 04:59:03 -07:00
feat(tests): add comprehensive test suite, update deps and Go 1.26.1
- Add 20+ tests for utility functions, SharedData, and Model - Tests cover: LoadTables, LoadTableData, UpdateCell, pagination, table inference, focus/blur, empty database, invalid indices - Update Go to 1.26.1, upgrade all dependencies - Replace custom Min/Max with Go builtin min/max - Format all files with goimports - Add staticcheck to CI workflow
This commit is contained in:
@@ -5,10 +5,10 @@ import (
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
tea "github.com/charmbracelet/bubbletea"
|
||||
"github.com/charmbracelet/bubbles/help"
|
||||
"github.com/charmbracelet/bubbles/key"
|
||||
"github.com/charmbracelet/bubbles/textinput"
|
||||
tea "github.com/charmbracelet/bubbletea"
|
||||
)
|
||||
|
||||
type TableListModel struct {
|
||||
@@ -254,22 +254,22 @@ func (m *TableListModel) filterTables() {
|
||||
name string
|
||||
score int
|
||||
}
|
||||
|
||||
|
||||
var matches []tableMatch
|
||||
searchLower := strings.ToLower(searchValue)
|
||||
|
||||
|
||||
for _, table := range m.Shared.Tables {
|
||||
score := m.fuzzyScore(strings.ToLower(table), searchLower)
|
||||
if score > 0 {
|
||||
matches = append(matches, tableMatch{name: table, score: score})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Sort by score (highest first)
|
||||
sort.Slice(matches, func(i, j int) bool {
|
||||
return matches[i].score > matches[j].score
|
||||
})
|
||||
|
||||
|
||||
// Extract sorted table names
|
||||
m.Shared.FilteredTables = make([]string, len(matches))
|
||||
for i, match := range matches {
|
||||
@@ -289,65 +289,65 @@ func (m *TableListModel) fuzzyScore(text, pattern string) int {
|
||||
if pattern == "" {
|
||||
return 1
|
||||
}
|
||||
|
||||
|
||||
textLen := len(text)
|
||||
patternLen := len(pattern)
|
||||
|
||||
|
||||
if patternLen > textLen {
|
||||
return 0
|
||||
}
|
||||
|
||||
|
||||
// Exact match gets highest score
|
||||
if text == pattern {
|
||||
return 1000
|
||||
}
|
||||
|
||||
|
||||
// Prefix match gets high score
|
||||
if strings.HasPrefix(text, pattern) {
|
||||
return 900
|
||||
}
|
||||
|
||||
|
||||
// Contains match gets medium score
|
||||
if strings.Contains(text, pattern) {
|
||||
return 800
|
||||
}
|
||||
|
||||
|
||||
// Fuzzy character sequence matching
|
||||
score := 0
|
||||
textIdx := 0
|
||||
patternIdx := 0
|
||||
consecutiveMatches := 0
|
||||
|
||||
|
||||
for textIdx < textLen && patternIdx < patternLen {
|
||||
if text[textIdx] == pattern[patternIdx] {
|
||||
score += 10
|
||||
consecutiveMatches++
|
||||
|
||||
|
||||
// Bonus for consecutive matches
|
||||
if consecutiveMatches > 1 {
|
||||
score += consecutiveMatches * 5
|
||||
}
|
||||
|
||||
|
||||
// Bonus for matches at word boundaries
|
||||
if textIdx == 0 || text[textIdx-1] == '_' || text[textIdx-1] == '-' {
|
||||
score += 20
|
||||
}
|
||||
|
||||
|
||||
patternIdx++
|
||||
} else {
|
||||
consecutiveMatches = 0
|
||||
}
|
||||
textIdx++
|
||||
}
|
||||
|
||||
|
||||
// Must match all pattern characters
|
||||
if patternIdx < patternLen {
|
||||
return 0
|
||||
}
|
||||
|
||||
|
||||
// Bonus for shorter text (more precise match)
|
||||
score += (100 - textLen)
|
||||
|
||||
|
||||
return score
|
||||
}
|
||||
|
||||
@@ -356,7 +356,7 @@ func (m *TableListModel) getVisibleCount() int {
|
||||
if m.searching {
|
||||
reservedLines += 2
|
||||
}
|
||||
return Max(1, m.Shared.Height-reservedLines)
|
||||
return max(1, m.Shared.Height-reservedLines)
|
||||
}
|
||||
|
||||
func (m *TableListModel) adjustPage() {
|
||||
@@ -389,7 +389,7 @@ func (m *TableListModel) View() string {
|
||||
} else {
|
||||
visibleCount := m.getVisibleCount()
|
||||
startIdx := m.currentPage * visibleCount
|
||||
endIdx := Min(startIdx+visibleCount, len(m.Shared.FilteredTables))
|
||||
endIdx := min(startIdx+visibleCount, len(m.Shared.FilteredTables))
|
||||
|
||||
for i := startIdx; i < endIdx; i++ {
|
||||
table := m.Shared.FilteredTables[i]
|
||||
@@ -419,4 +419,4 @@ func (m *TableListModel) View() string {
|
||||
}
|
||||
|
||||
return content.String()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user