mirror of
https://github.com/tendermint/tendermint.git
synced 2026-07-30 20:12:52 +00:00
spec: merge spec repo into tendermint repo (#7804)
This commit is contained in:
+39
-25
@@ -25,34 +25,48 @@ func TestSplitAndTrimEmpty(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestStringInSlice(t *testing.T) {
|
||||
require.True(t, StringInSlice("a", []string{"a", "b", "c"}))
|
||||
require.False(t, StringInSlice("d", []string{"a", "b", "c"}))
|
||||
require.True(t, StringInSlice("", []string{""}))
|
||||
require.False(t, StringInSlice("", []string{}))
|
||||
}
|
||||
|
||||
func TestIsASCIIText(t *testing.T) {
|
||||
notASCIIText := []string{
|
||||
"", "\xC2", "\xC2\xA2", "\xFF", "\x80", "\xF0", "\n", "\t",
|
||||
}
|
||||
for _, v := range notASCIIText {
|
||||
require.False(t, IsASCIIText(v), "%q is not ascii-text", v)
|
||||
}
|
||||
asciiText := []string{
|
||||
" ", ".", "x", "$", "_", "abcdefg;", "-", "0x00", "0", "123",
|
||||
}
|
||||
for _, v := range asciiText {
|
||||
require.True(t, IsASCIIText(v), "%q is ascii-text", v)
|
||||
}
|
||||
func assertCorrectTrim(t *testing.T, input, expected string) {
|
||||
t.Helper()
|
||||
output, err := ASCIITrim(input)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, expected, output)
|
||||
}
|
||||
|
||||
func TestASCIITrim(t *testing.T) {
|
||||
require.Equal(t, ASCIITrim(" "), "")
|
||||
require.Equal(t, ASCIITrim(" a"), "a")
|
||||
require.Equal(t, ASCIITrim("a "), "a")
|
||||
require.Equal(t, ASCIITrim(" a "), "a")
|
||||
require.Panics(t, func() { ASCIITrim("\xC2\xA2") })
|
||||
t.Run("Validation", func(t *testing.T) {
|
||||
t.Run("NonASCII", func(t *testing.T) {
|
||||
notASCIIText := []string{
|
||||
"\xC2", "\xC2\xA2", "\xFF", "\x80", "\xF0", "\n", "\t",
|
||||
}
|
||||
for _, v := range notASCIIText {
|
||||
_, err := ASCIITrim(v)
|
||||
require.Error(t, err, "%q is not ascii-text", v)
|
||||
}
|
||||
})
|
||||
t.Run("EmptyString", func(t *testing.T) {
|
||||
out, err := ASCIITrim("")
|
||||
require.NoError(t, err)
|
||||
require.Zero(t, out)
|
||||
})
|
||||
t.Run("ASCIIText", func(t *testing.T) {
|
||||
asciiText := []string{
|
||||
" ", ".", "x", "$", "_", "abcdefg;", "-", "0x00", "0", "123",
|
||||
}
|
||||
for _, v := range asciiText {
|
||||
_, err := ASCIITrim(v)
|
||||
require.NoError(t, err, "%q is ascii-text", v)
|
||||
}
|
||||
})
|
||||
_, err := ASCIITrim("\xC2\xA2")
|
||||
require.Error(t, err)
|
||||
})
|
||||
t.Run("Trimming", func(t *testing.T) {
|
||||
assertCorrectTrim(t, " ", "")
|
||||
assertCorrectTrim(t, " a", "a")
|
||||
assertCorrectTrim(t, "a ", "a")
|
||||
assertCorrectTrim(t, " a ", "a")
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
func TestStringSliceEqual(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user