From 619f942fae801862f1bda8d471f5ec049ae28243 Mon Sep 17 00:00:00 2001 From: Charles Iliya Krempeaux Date: Wed, 4 Oct 2023 17:36:46 +0900 Subject: [PATCH] initial commits --- alpha.go | 18 +++++++++++++ alpha_test.go | 75 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 93 insertions(+) create mode 100644 alpha.go create mode 100644 alpha_test.go diff --git a/alpha.go b/alpha.go new file mode 100644 index 0000000..f730577 --- /dev/null +++ b/alpha.go @@ -0,0 +1,18 @@ +package rfc2234 + +// IsAlpha returns true if the value of 'r' matches 'ALPHA' as defined in IETF RFC-2234: +// +// ALPHA = %x41-5A / %x61-7A ; A-Z / a-z +func IsAlpha(r rune) bool { + if 'z' < r { + return false + } + if r < 'A' { + return false + } + if 'Z' < r && r < 'a'{ + return false + } + + return true +} diff --git a/alpha_test.go b/alpha_test.go new file mode 100644 index 0000000..693098f --- /dev/null +++ b/alpha_test.go @@ -0,0 +1,75 @@ +package rfc2234_test + +import ( + "testing" + + "sourcecode.social/reiver/go-rfc2234" +) + +func TestIsAlpha(t *testing.T) { + + tests := []struct{ + Rune rune + Expected bool + }{ + } + + for r:=rune(0); r < 'A'; r++ { + tests = append(tests, struct{ + Rune rune + Expected bool + }{ + Rune: r, + Expected: false, + }) + } + for r:='A'; r <= 'Z'; r++ { + tests = append(tests, struct{ + Rune rune + Expected bool + }{ + Rune: r, + Expected: true, + }) + } + for r:='Z'+1; r < 'a'; r++ { + tests = append(tests, struct{ + Rune rune + Expected bool + }{ + Rune: r, + Expected: false, + }) + } + for r:='a'; r <= 'z'; r++ { + tests = append(tests, struct{ + Rune rune + Expected bool + }{ + Rune: r, + Expected: true, + }) + } + for r:='z'+1; r <= rune(127); r++ { + tests = append(tests, struct{ + Rune rune + Expected bool + }{ + Rune: r, + Expected: false, + }) + } + + for testNumber, test := range tests { + actual := rfc2234.IsAlpha(test.Rune) + expected := test.Expected + + if expected != actual { + t.Errorf("For test #%d, the actual value for rfc2234.IsAlpha() 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 + } + } +}