initial commits

master
Charles Iliya Krempeaux 2023-10-06 09:28:51 -07:00
parent 7f33583e15
commit a421524de5
2 changed files with 77 additions and 0 deletions

25
unreserved.go 100644
View File

@ -0,0 +1,25 @@
package rfc3986
import (
"sourcecode.social/reiver/go-rfc2234"
)
// IsUnreserved returns true if the value of 'r' matches 'unreserved' as defined in IETF RFC-3986:
//
// unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~"
func IsUnreserved(r rune) bool {
if rfc2234.IsAlpha(r) {
return true
}
if rfc2234.IsDigit(r) {
return true
}
switch r {
case '-' , '.' , '_' , '~':
return true
}
return false
}

52
unreserved_test.go 100644
View File

@ -0,0 +1,52 @@
package rfc3986_test
import (
"testing"
"sourcecode.social/reiver/go-rfc2234"
"sourcecode.social/reiver/go-rfc3986"
)
func TestIsUnreserved(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 rfc2234.IsAlpha(r) ||
rfc2234.IsDigit(r) ||
'-' == r ||
'.' == r ||
'_' == r ||
'~' == r {
test.Expected = true
}
tests = append(tests, test)
}
for testNumber, test := range tests {
actual := rfc3986.IsUnreserved(test.Rune)
expected := test.Expected
if expected != actual {
t.Errorf("For test #%d, the actual value for rfc3986.Unreserved() 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
}
}
}