From 904bbffee7e4fc4d20aca6dd4e40a9f1a9d9f371 Mon Sep 17 00:00:00 2001 From: Charles Iliya Krempeaux Date: Fri, 6 Oct 2023 09:21:18 -0700 Subject: [PATCH] initial commits --- bit.go | 8 ++++++++ bit_test.go | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+) create mode 100644 bit.go create mode 100644 bit_test.go diff --git a/bit.go b/bit.go new file mode 100644 index 0000000..6ff0402 --- /dev/null +++ b/bit.go @@ -0,0 +1,8 @@ +package rfc2234 + +// IsBit returns true if the value of 'r' matches 'BIT' as defined in IETF RFC-2234: +// +// BIT = "0" / "1" +func IsBit(r rune) bool { + return ('0' == r || '1' == r) +} diff --git a/bit_test.go b/bit_test.go new file mode 100644 index 0000000..7337d9c --- /dev/null +++ b/bit_test.go @@ -0,0 +1,57 @@ +package rfc2234_test + +import ( + "testing" + + "sourcecode.social/reiver/go-rfc2234" +) + +func TestIsBit(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 <= '1'; r++ { + tests = append(tests, struct{ + Rune rune + Expected bool + }{ + Rune: r, + Expected: true, + }) + } + for r:='1'+1; r <= rune(1024); r++ { + tests = append(tests, struct{ + Rune rune + Expected bool + }{ + Rune: r, + Expected: false, + }) + } + + for testNumber, test := range tests { + actual := rfc2234.IsBit(test.Rune) + expected := test.Expected + + if expected != actual { + t.Errorf("For test #%d, the actual value for rfc2234.IsBit() 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 + } + } +}