Skip to content

Commit

Permalink
test: Test_escapeStreamer_isAllowed
Browse files Browse the repository at this point in the history
  • Loading branch information
wolfogre committed Feb 8, 2023
1 parent 2c6cc0b commit 68b7e90
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions modules/charset/escape_stream_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// Copyright 2023 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT

package charset

import (
"fmt"
"testing"

"code.gitea.io/gitea/modules/translation"

"github.com/stretchr/testify/assert"
)

func Test_escapeStreamer_isAllowed(t *testing.T) {
tests := []struct {
allowed []rune
r rune
want bool
}{
{
allowed: nil,
r: 'a',
want: false,
},
{
allowed: []rune{'a', 'b', 'c'},
r: 'x',
want: false,
},
{
allowed: []rune{'a', 'b', 'c'},
r: 'a',
want: true,
},
{
allowed: []rune{'c', 'b', 'a'},
r: 'a',
want: true,
},
}
for _, tt := range tests {
t.Run(fmt.Sprintf("%v %v", tt.r, tt.allowed), func(t *testing.T) {
e := NewEscapeStreamer(translation.NewLocale("en"), nil, tt.allowed...).(*escapeStreamer)
assert.Equalf(t, tt.want, e.isAllowed(tt.r), "isAllowed(%v)", tt.r)
})
}
}

0 comments on commit 68b7e90

Please sign in to comment.