From ce553a7c22a5b7c6265c110da22dd394cbacbf10 Mon Sep 17 00:00:00 2001 From: Charles Iliya Krempeaux Date: Wed, 4 Oct 2023 18:01:51 +0900 Subject: [PATCH] initial commits --- gendelims.go | 13 ------- gendelims_test.go | 51 --------------------------- hexdig.go | 11 ++++++ hexdigit_test.go => hexdig_test.go | 26 +++----------- hexdigit.go | 8 ----- reserved.go | 12 ------- subdelims.go | 13 ------- subdelims_test.go | 55 ------------------------------ 8 files changed, 15 insertions(+), 174 deletions(-) delete mode 100644 gendelims.go delete mode 100644 gendelims_test.go create mode 100644 hexdig.go rename hexdigit_test.go => hexdig_test.go (71%) delete mode 100644 hexdigit.go delete mode 100644 reserved.go delete mode 100644 subdelims.go delete mode 100644 subdelims_test.go diff --git a/gendelims.go b/gendelims.go deleted file mode 100644 index 98598bb..0000000 --- a/gendelims.go +++ /dev/null @@ -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 - } -} diff --git a/gendelims_test.go b/gendelims_test.go deleted file mode 100644 index fa68a4f..0000000 --- a/gendelims_test.go +++ /dev/null @@ -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 - } - } -} diff --git a/hexdig.go b/hexdig.go new file mode 100644 index 0000000..4895db0 --- /dev/null +++ b/hexdig.go @@ -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') +} diff --git a/hexdigit_test.go b/hexdig_test.go similarity index 71% rename from hexdigit_test.go rename to hexdig_test.go index 5dad505..f70cd92 100644 --- a/hexdigit_test.go +++ b/hexdig_test.go @@ -6,7 +6,7 @@ import ( "sourcecode.social/reiver/go-rfc2234" ) -func TestIsHexDigit(t *testing.T) { +func TestIsHexDig(t *testing.T) { tests := []struct{ Rune rune @@ -50,25 +50,7 @@ func TestIsHexDigit(t *testing.T) { Expected: true, }) } - for r:='F'+1; r < 'a'; 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++ { + for r:='F'+1; r < rune(1024); r++ { tests = append(tests, struct{ Rune rune Expected bool @@ -79,11 +61,11 @@ func TestIsHexDigit(t *testing.T) { } for testNumber, test := range tests { - actual := rfc2234.IsHexDigit(test.Rune) + actual := rfc2234.IsHexDig(test.Rune) expected := test.Expected 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("ACTUAL: %t", actual) t.Logf("RUNE: (%U) %q", test.Rune, string(test.Rune)) diff --git a/hexdigit.go b/hexdigit.go deleted file mode 100644 index 78218f5..0000000 --- a/hexdigit.go +++ /dev/null @@ -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') -} diff --git a/reserved.go b/reserved.go deleted file mode 100644 index 75ebb10..0000000 --- a/reserved.go +++ /dev/null @@ -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) -} diff --git a/subdelims.go b/subdelims.go deleted file mode 100644 index 4ef98d0..0000000 --- a/subdelims.go +++ /dev/null @@ -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 - } -} diff --git a/subdelims_test.go b/subdelims_test.go deleted file mode 100644 index a2acb01..0000000 --- a/subdelims_test.go +++ /dev/null @@ -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 - } - } -}