diff options
author | Thomas Voss <mail@thomasvoss.com> | 2024-08-10 20:16:48 +0200 |
---|---|---|
committer | Thomas Voss <mail@thomasvoss.com> | 2024-08-10 20:16:48 +0200 |
commit | 2e0d8c3889590253b091de5d1c12b1a4dadf1c8f (patch) | |
tree | f2854f3d4c0be012486721246f80ec55186b9403 | |
parent | d5c3c5f0f05e2f88dae1992c3269c01a0b924b49 (diff) |
Do some renaming
-rw-r--r-- | cmd/mfmt/main.go | 18 | ||||
-rw-r--r-- | cmd/mfmt/util_test.go | 6 | ||||
-rw-r--r-- | mintage/parser.go (renamed from mintages/parser.go) | 22 | ||||
-rw-r--r-- | mintage/parser_test.go (renamed from mintages/parser_test.go) | 2 |
4 files changed, 24 insertions, 24 deletions
diff --git a/cmd/mfmt/main.go b/cmd/mfmt/main.go index b8e0722..5ff2a0a 100644 --- a/cmd/mfmt/main.go +++ b/cmd/mfmt/main.go @@ -8,11 +8,11 @@ import ( "strings" "unsafe" - "git.thomasvoss.com/euro-cash.eu/mintages" + "git.thomasvoss.com/euro-cash.eu/mintage" ) -const cols = unsafe.Sizeof(mintages.Row{}.Cols) / - unsafe.Sizeof(mintages.Row{}.Cols[0]) +const cols = unsafe.Sizeof(mintage.Row{}.Cols) / + unsafe.Sizeof(mintage.Row{}.Cols[0]) var rv int @@ -37,7 +37,7 @@ func main() { } func mfmt(path string, in io.Reader, out io.Writer) error { - data, err := mintages.Parse(in, path) + data, err := mintage.Parse(in, path) if err != nil { return err } @@ -75,7 +75,7 @@ func mfmt(path string, in io.Reader, out io.Writer) error { return nil } -func formatSection(out io.Writer, rows []mintages.Row) { +func formatSection(out io.Writer, rows []mintage.Row) { var ( year string longestMM int @@ -133,9 +133,9 @@ func formatSection(out io.Writer, rows []mintages.Row) { } func formatInt(n int) string { - if n <= mintages.Invalid { + if n <= mintage.Invalid { panic(fmt.Sprintf("invalid input %d", n)) - } else if n == mintages.Unknown { + } else if n == mintage.Unknown { return "?" } @@ -158,9 +158,9 @@ func formatInt(n int) string { func intlen(v int) int { switch { - case v <= mintages.Invalid: + case v <= mintage.Invalid: panic("mintage count is negative and not -1") - case v == 0, v == mintages.Unknown: + case v == 0, v == mintage.Unknown: return 1 default: n := 0 diff --git a/cmd/mfmt/util_test.go b/cmd/mfmt/util_test.go index e008e0b..af97146 100644 --- a/cmd/mfmt/util_test.go +++ b/cmd/mfmt/util_test.go @@ -6,7 +6,7 @@ package main import ( "testing" - "git.thomasvoss.com/euro-cash.eu/mintages" + "git.thomasvoss.com/euro-cash.eu/mintage" ) func TestFormatInt(t *testing.T) { @@ -18,7 +18,7 @@ func TestFormatInt(t *testing.T) { {123, "123"}, {81758, "81.758"}, {752759237528, "752.759.237.528"}, - {mintages.Unknown, "?"}, + {mintage.Unknown, "?"}, } { s := formatInt(x.n) if s != x.s { @@ -33,7 +33,7 @@ func TestIntLen(t *testing.T) { {123, len("123")}, {81758, len("81758")}, {752759237528, len("752759237528")}, - {mintages.Unknown, len("?")}, + {mintage.Unknown, len("?")}, } { n := intlen(x.x) if n != x.y { diff --git a/mintages/parser.go b/mintage/parser.go index 9f0c66f..242a3bb 100644 --- a/mintages/parser.go +++ b/mintage/parser.go @@ -1,4 +1,4 @@ -package mintages +package mintage import ( "bufio" @@ -31,14 +31,14 @@ type Row struct { Cols [8]int } -type Data struct { +type Set struct { StartYear int Circ, BU, Proof []Row } -func Parse(reader io.Reader, file string) (Data, error) { +func Parse(reader io.Reader, file string) (Set, error) { var ( - data Data // Our data struct + data Set // Our data struct slice *[]Row // Where to append mintages year int // The current year we are at ) @@ -58,7 +58,7 @@ func Parse(reader io.Reader, file string) (Data, error) { continue case tokens[0] == "BEGIN": if len(tokens)-1 != 1 { - return Data{}, SyntaxError{ + return Set{}, SyntaxError{ expected: "single argument to ‘BEGIN’", got: fmt.Sprintf("%d arguments", len(tokens)-1), file: file, @@ -77,7 +77,7 @@ func Parse(reader io.Reader, file string) (Data, error) { slice = &data.Proof default: if !isNumeric(arg, false) { - return Data{}, SyntaxError{ + return Set{}, SyntaxError{ expected: "‘CIRC’, ‘BU’, ‘PROOF’, or a year", got: arg, file: file, @@ -98,7 +98,7 @@ func Parse(reader io.Reader, file string) (Data, error) { } tokens = tokens[1:] if !isNumeric(tokens[0], true) && tokens[0] != "?" { - return Data{}, SyntaxError{ + return Set{}, SyntaxError{ expected: "mintage row after label", got: tokens[0], file: file, @@ -109,14 +109,14 @@ func Parse(reader io.Reader, file string) (Data, error) { case isNumeric(tokens[0], true), tokens[0] == "?": switch { case slice == nil: - return Data{}, SyntaxError{ + return Set{}, SyntaxError{ expected: "coin type declaration", got: tokens[0], file: file, linenr: linenr, } case data.StartYear == 0: - return Data{}, SyntaxError{ + return Set{}, SyntaxError{ expected: "start year declaration", got: tokens[0], file: file, @@ -132,7 +132,7 @@ func Parse(reader io.Reader, file string) (Data, error) { if tokcnt == 1 { word = "entry" } - return Data{}, SyntaxError{ + return Set{}, SyntaxError{ expected: fmt.Sprintf("%d mintage entries", numcoins), got: fmt.Sprintf("%d %s", tokcnt, word), file: file, @@ -161,7 +161,7 @@ func Parse(reader io.Reader, file string) (Data, error) { } *slice = append(*slice, row) default: - return Data{}, SyntaxError{ + return Set{}, SyntaxError{ expected: "‘BEGIN’ directive or mintage row", got: fmt.Sprintf("invalid token ‘%s’", tokens[0]), file: file, diff --git a/mintages/parser_test.go b/mintage/parser_test.go index f61b63d..0a67685 100644 --- a/mintages/parser_test.go +++ b/mintage/parser_test.go @@ -1,4 +1,4 @@ -package mintages +package mintage import ( "bytes" |