initial commits
parent
687e7fd1f6
commit
ce553a7c22
13
gendelims.go
13
gendelims.go
|
@ -1,13 +0,0 @@
|
||||||
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
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,51 +0,0 @@
|
||||||
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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -0,0 +1,11 @@
|
||||||
|
package rfc2234
|
||||||
|
|
||||||
|
// IsHexDigit returns true if value of 'r' matches 'ALPHA' as defined in IETF RFC-2234:
|
||||||
|
//
|
||||||
|
// HEXDIG = DIGIT / "A" / "B" / "C" / "D" / "E" / "F"
|
||||||
|
//
|
||||||
|
// DIGIT = %x30-39
|
||||||
|
// ; 0-9
|
||||||
|
func IsHexDig(r rune) bool {
|
||||||
|
return ('0' <= r && r <= '9') || ('A' <= r && r <= 'F')
|
||||||
|
}
|
|
@ -6,7 +6,7 @@ import (
|
||||||
"sourcecode.social/reiver/go-rfc2234"
|
"sourcecode.social/reiver/go-rfc2234"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestIsHexDigit(t *testing.T) {
|
func TestIsHexDig(t *testing.T) {
|
||||||
|
|
||||||
tests := []struct{
|
tests := []struct{
|
||||||
Rune rune
|
Rune rune
|
||||||
|
@ -50,25 +50,7 @@ func TestIsHexDigit(t *testing.T) {
|
||||||
Expected: true,
|
Expected: true,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
for r:='F'+1; r < 'a'; r++ {
|
for r:='F'+1; r < rune(1024); r++ {
|
||||||
tests = append(tests, struct{
|
|
||||||
Rune rune
|
|
||||||
Expected bool
|
|
||||||
}{
|
|
||||||
Rune: r,
|
|
||||||
Expected: false,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
for r:='a'; r <= 'f'; r++ {
|
|
||||||
tests = append(tests, struct{
|
|
||||||
Rune rune
|
|
||||||
Expected bool
|
|
||||||
}{
|
|
||||||
Rune: r,
|
|
||||||
Expected: true,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
for r:='f'+1; r < rune(1024); r++ {
|
|
||||||
tests = append(tests, struct{
|
tests = append(tests, struct{
|
||||||
Rune rune
|
Rune rune
|
||||||
Expected bool
|
Expected bool
|
||||||
|
@ -79,11 +61,11 @@ func TestIsHexDigit(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
for testNumber, test := range tests {
|
for testNumber, test := range tests {
|
||||||
actual := rfc2234.IsHexDigit(test.Rune)
|
actual := rfc2234.IsHexDig(test.Rune)
|
||||||
expected := test.Expected
|
expected := test.Expected
|
||||||
|
|
||||||
if expected != actual {
|
if expected != actual {
|
||||||
t.Errorf("For test #%d, the actual value for rfc2234.IsHexDigit() is not what was expected.", testNumber)
|
t.Errorf("For test #%d, the actual value for rfc2234.IsHexDig() is not what was expected.", testNumber)
|
||||||
t.Logf("EXPECTED: %t", expected)
|
t.Logf("EXPECTED: %t", expected)
|
||||||
t.Logf("ACTUAL: %t", actual)
|
t.Logf("ACTUAL: %t", actual)
|
||||||
t.Logf("RUNE: (%U) %q", test.Rune, string(test.Rune))
|
t.Logf("RUNE: (%U) %q", test.Rune, string(test.Rune))
|
|
@ -1,8 +0,0 @@
|
||||||
package rfc2234
|
|
||||||
|
|
||||||
// IsHexDigit returns true if value of 'r' matches 'ALPHA' as defined in IETF RFC-2234:
|
|
||||||
//
|
|
||||||
// HEXDIGIT = %30-%39 / %41-%46 / %61-%66 ; 0-9 / A-F / a-f
|
|
||||||
func IsHexDigit(r rune) bool {
|
|
||||||
return ('0' <= r && r <= '9') || ('A' <= r && r <= 'F') || ('a' <= r && r <= 'f')
|
|
||||||
}
|
|
12
reserved.go
12
reserved.go
|
@ -1,12 +0,0 @@
|
||||||
package rfc2234
|
|
||||||
|
|
||||||
// IsReserved returns true if value of 'r' matches 'reserved' as defined in IETF RFC-2234:
|
|
||||||
//
|
|
||||||
// reserved = gen-delims / sub-delims
|
|
||||||
//
|
|
||||||
// gen-delims = ":" / "/" / "?" / "#" / "[" / "]" / "@"
|
|
||||||
//
|
|
||||||
// sub-delims = "!" / "$" / "&" / "'" / "(" / ")" / "*" / "+" / "," / ";" / "="
|
|
||||||
func IsReserved(r rune) bool {
|
|
||||||
return IsGenDelim(r) || IsSubDelim(r)
|
|
||||||
}
|
|
13
subdelims.go
13
subdelims.go
|
@ -1,13 +0,0 @@
|
||||||
package rfc2234
|
|
||||||
|
|
||||||
// IsSubDelim returns true if the value of 'r' matches 'sub-delims' as defined in IETF RFC-2234:
|
|
||||||
//
|
|
||||||
// sub-delims = "!" / "$" / "&" / "'" / "(" / ")" / "*" / "+" / "," / ";" / "="
|
|
||||||
func IsSubDelim(r rune) bool {
|
|
||||||
switch r {
|
|
||||||
case '!' , '$' , '&' ,'\'' , '(' , ')' , '*' , '+' , ',' , ';' , '=':
|
|
||||||
return true
|
|
||||||
default:
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,55 +0,0 @@
|
||||||
package rfc2234_test
|
|
||||||
|
|
||||||
import (
|
|
||||||
"testing"
|
|
||||||
|
|
||||||
"sourcecode.social/reiver/go-rfc2234"
|
|
||||||
)
|
|
||||||
|
|
||||||
func TestIsSubDelim(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 ||
|
|
||||||
'+' == r ||
|
|
||||||
',' == r ||
|
|
||||||
';' == r ||
|
|
||||||
'=' == r {
|
|
||||||
test.Expected = true
|
|
||||||
}
|
|
||||||
|
|
||||||
tests = append(tests, test)
|
|
||||||
}
|
|
||||||
|
|
||||||
for testNumber, test := range tests {
|
|
||||||
actual := rfc2234.IsSubDelim(test.Rune)
|
|
||||||
expected := test.Expected
|
|
||||||
|
|
||||||
if expected != actual {
|
|
||||||
t.Errorf("For test #%d, the actual value for rfc2234.IsSubDelim() 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