2022-06-10 05:39:53 +00:00
|
|
|
// Copyright 2022 The Gitea Authors. All rights reserved.
|
2022-11-27 18:20:29 +00:00
|
|
|
// SPDX-License-Identifier: MIT
|
2022-06-10 05:39:53 +00:00
|
|
|
|
|
|
|
package regexplru
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
2024-07-30 19:41:27 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
2022-06-10 05:39:53 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestRegexpLru(t *testing.T) {
|
|
|
|
r, err := GetCompiled("a")
|
2024-07-30 19:41:27 +00:00
|
|
|
require.NoError(t, err)
|
2022-06-10 05:39:53 +00:00
|
|
|
assert.True(t, r.MatchString("a"))
|
|
|
|
|
|
|
|
r, err = GetCompiled("a")
|
2024-07-30 19:41:27 +00:00
|
|
|
require.NoError(t, err)
|
2022-06-10 05:39:53 +00:00
|
|
|
assert.True(t, r.MatchString("a"))
|
|
|
|
|
|
|
|
assert.EqualValues(t, 1, lruCache.Len())
|
|
|
|
|
|
|
|
_, err = GetCompiled("(")
|
2024-07-30 19:41:27 +00:00
|
|
|
require.Error(t, err)
|
2022-06-10 05:39:53 +00:00
|
|
|
assert.EqualValues(t, 2, lruCache.Len())
|
|
|
|
}
|