initial commits

master
Charles Iliya Krempeaux 2023-12-09 09:30:21 -08:00
parent 8920d5ac3e
commit bf6d657b20
2 changed files with 171 additions and 0 deletions

View File

@ -0,0 +1,17 @@
package sp
func SkipTolerant(p []byte) []byte {
length := len(p)
if length <= 0 {
return nil
}
for i,b := range p {
if !ByteIsTolerant(b) {
return p[i:]
}
}
return nil
}

View File

@ -0,0 +1,154 @@
package sp_test
import (
"testing"
"bytes"
"sourcecode.social/reiver/go-rfc2616/sp"
)
func TestSkipTolerant(t *testing.T) {
tests := []struct{
Value []byte
Expected []byte
}{
{
Value: nil,
Expected: nil,
},
{
Value: []byte(nil),
Expected: nil,
},
{
Value: []byte{},
Expected: nil,
},
{
Value: []byte(""),
Expected: nil,
},
{
Value: []byte(" "),
Expected: nil,
},
{
Value: []byte(" "),
Expected: nil,
},
{
Value: []byte(" "),
Expected: nil,
},
{
Value: []byte(" "),
Expected: nil,
},
{
Value: []byte(" "),
Expected: nil,
},
{
Value: []byte(" "),
Expected: nil,
},
{
Value: []byte(" "),
Expected: nil,
},
{
Value: []byte(" "),
Expected: nil,
},
{
Value: []byte("\t"),
Expected: nil,
},
{
Value: []byte("\t\t"),
Expected: nil,
},
{
Value: []byte("\t\t\t"),
Expected: nil,
},
{
Value: []byte("\t\t\t\t"),
Expected: nil,
},
{
Value: []byte("\t\t\t\t\t"),
Expected: nil,
},
{
Value: []byte("\t\t\t\t\t\t"),
Expected: nil,
},
{
Value: []byte("\t\t\t\t\t\t\t"),
Expected: nil,
},
{
Value: []byte("\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t"),
Expected: nil,
},
{
Value: []byte("\t \t \t \t\t"),
Expected: nil,
},
{
Value: []byte(" apple "),
Expected: []byte("apple "),
},
{
Value: []byte("\tbanana"),
Expected: []byte("banana"),
},
{
Value: []byte("\t\t cherry\r\n"),
Expected: []byte("cherry\r\n"),
},
{
Value: []byte(" \t\t 😈 :-)\r\n"),
Expected: []byte("😈 :-)\r\n"),
},
}
for testNumber, test := range tests {
actual := sp.SkipTolerant(test.Value)
expected := test.Expected
if !bytes.Equal(expected, actual) {
t.Errorf("For test #%d, the actual result is not what was expected.", testNumber)
t.Logf("EXPECTED: %q (%#v)", expected, expected)
t.Logf("ACTUAL: %q (%#v)", actual, actual)
t.Logf("VALUE: %q (%#v)", test.Value, test.Value)
continue
}
}
}