From 857fb769a89d3a2ca190a2ffb996cdb500f229df Mon Sep 17 00:00:00 2001 From: Charles Iliya Krempeaux Date: Wed, 4 Oct 2023 17:37:38 +0900 Subject: [PATCH] initial commits --- subdelims.go | 13 +++++++++++ subdelims_test.go | 55 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+) create mode 100644 subdelims.go create mode 100644 subdelims_test.go diff --git a/subdelims.go b/subdelims.go new file mode 100644 index 0000000..4ef98d0 --- /dev/null +++ b/subdelims.go @@ -0,0 +1,13 @@ +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 new file mode 100644 index 0000000..a2acb01 --- /dev/null +++ b/subdelims_test.go @@ -0,0 +1,55 @@ +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 + } + } +}