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