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