From fce9b28f6d0eae01719977962f9aff14f39a9d1a Mon Sep 17 00:00:00 2001 From: Charles Iliya Krempeaux Date: Wed, 4 Oct 2023 17:36:57 +0900 Subject: [PATCH] initial commits --- digit.go | 8 ++++++++ digit_test.go | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+) create mode 100644 digit.go create mode 100644 digit_test.go diff --git a/digit.go b/digit.go new file mode 100644 index 0000000..0e510d6 --- /dev/null +++ b/digit.go @@ -0,0 +1,8 @@ +package rfc2234 + +// IsDigit returns true if value of 'r' matches 'ALPHA' as defined in IETF RFC-2234: +// +// DIGIT = %30-%39 ; 0-9 +func IsDigit(r rune) bool { + return '0' <= r && r <= '9' +} diff --git a/digit_test.go b/digit_test.go new file mode 100644 index 0000000..939eaba --- /dev/null +++ b/digit_test.go @@ -0,0 +1,57 @@ +package rfc2234_test + +import ( + "testing" + + "sourcecode.social/reiver/go-rfc2234" +) + +func TestIsDigit(t *testing.T) { + + tests := []struct{ + Rune rune + Expected bool + }{ + } + + for r:=rune(0); r < '0'; r++ { + tests = append(tests, struct{ + Rune rune + Expected bool + }{ + Rune: r, + Expected: false, + }) + } + for r:='0'; r <= '9'; r++ { + tests = append(tests, struct{ + Rune rune + Expected bool + }{ + Rune: r, + Expected: true, + }) + } + for r:='9'+1; r <= rune(127); r++ { + tests = append(tests, struct{ + Rune rune + Expected bool + }{ + Rune: r, + Expected: false, + }) + } + + for testNumber, test := range tests { + actual := rfc2234.IsDigit(test.Rune) + expected := test.Expected + + if expected != actual { + t.Errorf("For test #%d, the actual value for rfc2234.IsDigit() 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 + } + } +}