initial commits
parent
857fb769a8
commit
17e5e6492c
|
@ -0,0 +1,13 @@
|
|||
package rfc2234
|
||||
|
||||
// IsGenDelim returns true if the value of 'r' matches 'sub-delims' as defined in IETF RFC-2234:
|
||||
//
|
||||
// gen-delims = ":" / "/" / "?" / "#" / "[" / "]" / "@"
|
||||
func IsGenDelim(r rune) bool {
|
||||
switch r {
|
||||
case ':' , '/' , '?' , '#' , '[' , ']' , '@':
|
||||
return true
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}
|
|
@ -0,0 +1,51 @@
|
|||
package rfc2234_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"sourcecode.social/reiver/go-rfc2234"
|
||||
)
|
||||
|
||||
func TestIsGenDelim(t *testing.T) {
|
||||
|
||||
tests := []struct{
|
||||
Rune rune
|
||||
Expected bool
|
||||
}{
|
||||
}
|
||||
|
||||
for r:=rune(0); r < rune(8192); r++ {
|
||||
test := struct{
|
||||
Rune rune
|
||||
Expected bool
|
||||
}{
|
||||
Rune: r,
|
||||
Expected: false,
|
||||
}
|
||||
|
||||
if ':' == r ||
|
||||
'/' == r ||
|
||||
'?' == r ||
|
||||
'#' == r ||
|
||||
'[' == r ||
|
||||
']' == r ||
|
||||
'@' == r {
|
||||
test.Expected = true
|
||||
}
|
||||
|
||||
tests = append(tests, test)
|
||||
}
|
||||
|
||||
for testNumber, test := range tests {
|
||||
actual := rfc2234.IsGenDelim(test.Rune)
|
||||
expected := test.Expected
|
||||
|
||||
if expected != actual {
|
||||
t.Errorf("For test #%d, the actual value for rfc2234.IsGenDelim() is not what was expected.", testNumber)
|
||||
t.Logf("EXPECTED: %t", expected)
|
||||
t.Logf("ACTUAL: %t", actual)
|
||||
t.Logf("RUNE: (%U) %q", test.Rune, string(test.Rune))
|
||||
continue
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue