Some checks failed
cache-seeder / prune (push) Has been skipped
cache-seeder / frontend (push) Failing after 3s
cache-seeder / python (push) Failing after 3s
cache-seeder / gobuild (push) Failing after 4s
cache-seeder / lint (bindata, lint-backend) (push) Failing after 3s
giteabot backport / giteabot (push) Has been skipped
giteabot / giteabot (push) Has been skipped
cache-prune / prune (push) Has been skipped
release-nightly-snapcraft / build-and-publish (ubuntu-24.04) (push) Has been cancelled
release-nightly-snapcraft / build-and-publish (ubuntu-24.04-arm) (push) Has been cancelled
release-nightly / nightly-binary (push) Has been cancelled
release-nightly / nightly-container (push) Has been cancelled
cron-renovate / cron-renovate (push) Has been skipped
35 lines
843 B
Go
35 lines
843 B
Go
// Copyright 2026 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package util
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestTrie(t *testing.T) {
|
|
trie := &TrieNode{}
|
|
trie.Insert("apple")
|
|
trie.Insert("apricot")
|
|
trie.Insert("banana")
|
|
trie.Insert("app")
|
|
|
|
// Test exact matches
|
|
assert.Equal(t, 5, trie.Match("apple", 0))
|
|
assert.Equal(t, 7, trie.Match("apricot", 0))
|
|
assert.Equal(t, 6, trie.Match("banana", 0))
|
|
assert.Equal(t, 3, trie.Match("app", 0))
|
|
|
|
// Test partial match (longest match priority)
|
|
assert.Equal(t, 5, trie.Match("apple-pie", 0))
|
|
|
|
// Test suffix/nested position match
|
|
assert.Equal(t, 5, trie.Match("sweet apple", 6))
|
|
|
|
// Test no match
|
|
assert.Equal(t, -1, trie.Match("orange", 0))
|
|
assert.Equal(t, -1, trie.Match("ap", 0)) // prefix exists but is not an end node
|
|
}
|