snapshot of https://github.com/go-gitea/gitea.git (main, 2026-09-15; blobs > 131072B omitted)
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
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
This commit is contained in:
34
modules/util/trie_test.go
Normal file
34
modules/util/trie_test.go
Normal file
@@ -0,0 +1,34 @@
|
||||
// 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
|
||||
}
|
||||
Reference in New Issue
Block a user