mirror of
https://github.com/navidrome/navidrome.git
synced 2026-05-03 06:51:16 +00:00
Vendor the spellfix1 extension source and compile it directly into the binary via cgo, avoiding runtime shared library dependencies across platforms. The extension is registered via sqlite3_auto_extension so every new SQLite connection has spellfix1 available. Signed-off-by: Deluan <deluan@navidrome.org>
58 lines
1.3 KiB
Go
58 lines
1.3 KiB
Go
//go:build sqlite_spellfix
|
|
|
|
package spellfix_test
|
|
|
|
import (
|
|
"database/sql"
|
|
"testing"
|
|
|
|
_ "github.com/mattn/go-sqlite3"
|
|
_ "github.com/navidrome/navidrome/db/spellfix"
|
|
. "github.com/onsi/ginkgo/v2"
|
|
. "github.com/onsi/gomega"
|
|
)
|
|
|
|
func TestSpellfix(t *testing.T) {
|
|
RegisterFailHandler(Fail)
|
|
RunSpecs(t, "Spellfix Suite")
|
|
}
|
|
|
|
var _ = Describe("spellfix1", func() {
|
|
var db *sql.DB
|
|
|
|
BeforeEach(func() {
|
|
var err error
|
|
db, err = sql.Open("sqlite3", ":memory:")
|
|
Expect(err).ToNot(HaveOccurred())
|
|
})
|
|
|
|
AfterEach(func() {
|
|
_ = db.Close()
|
|
})
|
|
|
|
It("creates a spellfix1 virtual table", func() {
|
|
_, err := db.Exec("CREATE VIRTUAL TABLE demo USING spellfix1")
|
|
Expect(err).ToNot(HaveOccurred())
|
|
})
|
|
|
|
It("returns fuzzy matches", func() {
|
|
_, err := db.Exec("CREATE VIRTUAL TABLE demo USING spellfix1")
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
_, err = db.Exec("INSERT INTO demo(word) VALUES ('hello'), ('world'), ('help')")
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
rows, err := db.Query("SELECT word FROM demo WHERE word MATCH 'helo' AND top=3")
|
|
Expect(err).ToNot(HaveOccurred())
|
|
defer rows.Close()
|
|
|
|
var words []string
|
|
for rows.Next() {
|
|
var word string
|
|
Expect(rows.Scan(&word)).To(Succeed())
|
|
words = append(words, word)
|
|
}
|
|
Expect(words).To(ContainElement("hello"))
|
|
})
|
|
})
|