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