From 5956dd68550c438524cb3ecc05b26080678beb01 Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Sat, 25 Jul 2015 22:08:35 -0700 Subject: [PATCH] update packages for avoiding a possible windows bug in go-humanize --- Godeps/Godeps.json | 6 +- .../github.com/dustin/go-humanize/bigbytes.go | 2 +- .../dustin/go-humanize/bigbytes_test.go | 4 +- .../github.com/dustin/go-humanize/bytes.go | 2 +- .../dustin/go-humanize/bytes_test.go | 6 +- .../github.com/dustin/go-humanize/comma.go | 2 +- .../github.com/dustin/go-humanize/number.go | 192 ++++++++++++++++++ .../dustin/go-humanize/number_test.go | 78 +++++++ .../minio/minio/pkg/iodine/iodine.go | 4 +- .../_workspace/src/gopkg.in/check.v1/check.go | 2 +- buildscripts/updatedeps.sh | 2 +- 11 files changed, 285 insertions(+), 15 deletions(-) create mode 100644 Godeps/_workspace/src/github.com/dustin/go-humanize/number.go create mode 100644 Godeps/_workspace/src/github.com/dustin/go-humanize/number_test.go diff --git a/Godeps/Godeps.json b/Godeps/Godeps.json index b52600fa..28be2f1d 100644 --- a/Godeps/Godeps.json +++ b/Godeps/Godeps.json @@ -7,7 +7,7 @@ "Deps": [ { "ImportPath": "github.com/dustin/go-humanize", - "Rev": "8cc1aaa2d955ee82833337cfb10babc42be6bce6" + "Rev": "c128122e0b9b93799aef8181a537e5d8fd7081d6" }, { "ImportPath": "github.com/fatih/color", @@ -29,8 +29,8 @@ }, { "ImportPath": "github.com/minio/minio/pkg/iodine", - "Comment": "release-1434511043-231-ga23a61d", - "Rev": "a23a61da113fcf353d097b4323f66afae62cd430" + "Comment": "warning: tag 'release-1434511043' is really 'RELEASE.Wed-Jun-17-03-17-23-GMT-2015' here\nrelease-1434511043-265-g7133513", + "Rev": "71335136005e1836b6192a45eaaa68a2779b893a" }, { "ImportPath": "github.com/minio/pb", diff --git a/Godeps/_workspace/src/github.com/dustin/go-humanize/bigbytes.go b/Godeps/_workspace/src/github.com/dustin/go-humanize/bigbytes.go index 6876e92e..e4a814a9 100644 --- a/Godeps/_workspace/src/github.com/dustin/go-humanize/bigbytes.go +++ b/Godeps/_workspace/src/github.com/dustin/go-humanize/bigbytes.go @@ -115,7 +115,7 @@ func humanateBigBytes(s, base *big.Int, sizes []string) string { // // BigBytes(82854982) -> 83MB func BigBytes(s *big.Int) string { - sizes := []string{"B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"} + sizes := []string{"B", "kB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"} return humanateBigBytes(s, bigSIExp, sizes) } diff --git a/Godeps/_workspace/src/github.com/dustin/go-humanize/bigbytes_test.go b/Godeps/_workspace/src/github.com/dustin/go-humanize/bigbytes_test.go index a0f977a6..da367d41 100644 --- a/Godeps/_workspace/src/github.com/dustin/go-humanize/bigbytes_test.go +++ b/Godeps/_workspace/src/github.com/dustin/go-humanize/bigbytes_test.go @@ -86,8 +86,8 @@ func TestBigBytes(t *testing.T) { {"bytes(803)", bbyte(803), "803B"}, {"bytes(999)", bbyte(999), "999B"}, - {"bytes(1024)", bbyte(1024), "1.0KB"}, - {"bytes(1MB - 1)", bbyte(MByte - Byte), "1000KB"}, + {"bytes(1024)", bbyte(1024), "1.0kB"}, + {"bytes(1MB - 1)", bbyte(MByte - Byte), "1000kB"}, {"bytes(1MB)", bbyte(1024 * 1024), "1.0MB"}, {"bytes(1GB - 1K)", bbyte(GByte - KByte), "1000MB"}, diff --git a/Godeps/_workspace/src/github.com/dustin/go-humanize/bytes.go b/Godeps/_workspace/src/github.com/dustin/go-humanize/bytes.go index 4c4b5af1..b7a77b52 100644 --- a/Godeps/_workspace/src/github.com/dustin/go-humanize/bytes.go +++ b/Godeps/_workspace/src/github.com/dustin/go-humanize/bytes.go @@ -86,7 +86,7 @@ func humanateBytes(s uint64, base float64, sizes []string) string { // // Bytes(82854982) -> 83MB func Bytes(s uint64) string { - sizes := []string{"B", "KB", "MB", "GB", "TB", "PB", "EB"} + sizes := []string{"B", "kB", "MB", "GB", "TB", "PB", "EB"} return humanateBytes(s, 1000, sizes) } diff --git a/Godeps/_workspace/src/github.com/dustin/go-humanize/bytes_test.go b/Godeps/_workspace/src/github.com/dustin/go-humanize/bytes_test.go index 76a594c1..7497fa00 100644 --- a/Godeps/_workspace/src/github.com/dustin/go-humanize/bytes_test.go +++ b/Godeps/_workspace/src/github.com/dustin/go-humanize/bytes_test.go @@ -80,9 +80,9 @@ func TestBytes(t *testing.T) { {"bytes(803)", Bytes(803), "803B"}, {"bytes(999)", Bytes(999), "999B"}, - {"bytes(1024)", Bytes(1024), "1.0KB"}, - {"bytes(9999)", Bytes(9999), "10KB"}, - {"bytes(1MB - 1)", Bytes(MByte - Byte), "1000KB"}, + {"bytes(1024)", Bytes(1024), "1.0kB"}, + {"bytes(9999)", Bytes(9999), "10kB"}, + {"bytes(1MB - 1)", Bytes(MByte - Byte), "1000kB"}, {"bytes(1MB)", Bytes(1024 * 1024), "1.0MB"}, {"bytes(1GB - 1K)", Bytes(GByte - KByte), "1000MB"}, diff --git a/Godeps/_workspace/src/github.com/dustin/go-humanize/comma.go b/Godeps/_workspace/src/github.com/dustin/go-humanize/comma.go index 9d0d2ed1..20711c15 100644 --- a/Godeps/_workspace/src/github.com/dustin/go-humanize/comma.go +++ b/Godeps/_workspace/src/github.com/dustin/go-humanize/comma.go @@ -18,7 +18,7 @@ func Comma(v int64) string { v = 0 - v } - parts := []string{"", "", "", "", "", "", "", ""} + parts := []string{"", "", "", "", "", "", ""} j := len(parts) - 1 for v > 999 { diff --git a/Godeps/_workspace/src/github.com/dustin/go-humanize/number.go b/Godeps/_workspace/src/github.com/dustin/go-humanize/number.go new file mode 100644 index 00000000..32141348 --- /dev/null +++ b/Godeps/_workspace/src/github.com/dustin/go-humanize/number.go @@ -0,0 +1,192 @@ +package humanize + +/* +Slightly adapted from the source to fit go-humanize. + +Author: https://github.com/gorhill +Source: https://gist.github.com/gorhill/5285193 + +*/ + +import ( + "math" + "strconv" +) + +var ( + renderFloatPrecisionMultipliers = [...]float64{ + 1, + 10, + 100, + 1000, + 10000, + 100000, + 1000000, + 10000000, + 100000000, + 1000000000, + } + + renderFloatPrecisionRounders = [...]float64{ + 0.5, + 0.05, + 0.005, + 0.0005, + 0.00005, + 0.000005, + 0.0000005, + 0.00000005, + 0.000000005, + 0.0000000005, + } +) + +// FormatFloat produces a formatted number as string based on the following user-specified criteria: +// * thousands separator +// * decimal separator +// * decimal precision +// +// Usage: s := RenderFloat(format, n) +// The format parameter tells how to render the number n. +// +// See examples: http://play.golang.org/p/LXc1Ddm1lJ +// +// Examples of format strings, given n = 12345.6789: +// "#,###.##" => "12,345.67" +// "#,###." => "12,345" +// "#,###" => "12345,678" +// "#\u202F###,##" => "12 345,68" +// "#.###,###### => 12.345,678900 +// "" (aka default format) => 12,345.67 +// +// The highest precision allowed is 9 digits after the decimal symbol. +// There is also a version for integer number, FormatInteger(), +// which is convenient for calls within template. +func FormatFloat(format string, n float64) string { + // Special cases: + // NaN = "NaN" + // +Inf = "+Infinity" + // -Inf = "-Infinity" + if math.IsNaN(n) { + return "NaN" + } + if n > math.MaxFloat64 { + return "Infinity" + } + if n < -math.MaxFloat64 { + return "-Infinity" + } + + // default format + precision := 2 + decimalStr := "." + thousandStr := "," + positiveStr := "" + negativeStr := "-" + + if len(format) > 0 { + format := []rune(format) + + // If there is an explicit format directive, + // then default values are these: + precision = 9 + thousandStr = "" + + // collect indices of meaningful formatting directives + formatIndx := []int{} + for i, char := range format { + if char != '#' && char != '0' { + formatIndx = append(formatIndx, i) + } + } + + if len(formatIndx) > 0 { + // Directive at index 0: + // Must be a '+' + // Raise an error if not the case + // index: 0123456789 + // +0.000,000 + // +000,000.0 + // +0000.00 + // +0000 + if formatIndx[0] == 0 { + if format[formatIndx[0]] != '+' { + panic("RenderFloat(): invalid positive sign directive") + } + positiveStr = "+" + formatIndx = formatIndx[1:] + } + + // Two directives: + // First is thousands separator + // Raise an error if not followed by 3-digit + // 0123456789 + // 0.000,000 + // 000,000.00 + if len(formatIndx) == 2 { + if (formatIndx[1] - formatIndx[0]) != 4 { + panic("RenderFloat(): thousands separator directive must be followed by 3 digit-specifiers") + } + thousandStr = string(format[formatIndx[0]]) + formatIndx = formatIndx[1:] + } + + // One directive: + // Directive is decimal separator + // The number of digit-specifier following the separator indicates wanted precision + // 0123456789 + // 0.00 + // 000,0000 + if len(formatIndx) == 1 { + decimalStr = string(format[formatIndx[0]]) + precision = len(format) - formatIndx[0] - 1 + } + } + } + + // generate sign part + var signStr string + if n >= 0.000000001 { + signStr = positiveStr + } else if n <= -0.000000001 { + signStr = negativeStr + n = -n + } else { + signStr = "" + n = 0.0 + } + + // split number into integer and fractional parts + intf, fracf := math.Modf(n + renderFloatPrecisionRounders[precision]) + + // generate integer part string + intStr := strconv.Itoa(int(intf)) + + // add thousand separator if required + if len(thousandStr) > 0 { + for i := len(intStr); i > 3; { + i -= 3 + intStr = intStr[:i] + thousandStr + intStr[i:] + } + } + + // no fractional part, we can leave now + if precision == 0 { + return signStr + intStr + } + + // generate fractional part + fracStr := strconv.Itoa(int(fracf * renderFloatPrecisionMultipliers[precision])) + // may need padding + if len(fracStr) < precision { + fracStr = "000000000000000"[:precision-len(fracStr)] + fracStr + } + + return signStr + intStr + decimalStr + fracStr +} + +// FormatInteger produces a formatted number as string. +// See FormatFloat. +func FormatInteger(format string, n int) string { + return FormatFloat(format, float64(n)) +} diff --git a/Godeps/_workspace/src/github.com/dustin/go-humanize/number_test.go b/Godeps/_workspace/src/github.com/dustin/go-humanize/number_test.go new file mode 100644 index 00000000..dd38a5bb --- /dev/null +++ b/Godeps/_workspace/src/github.com/dustin/go-humanize/number_test.go @@ -0,0 +1,78 @@ +package humanize + +import ( + "math" + "testing" +) + +type TestStruct struct { + name string + format string + num float64 + formatted string +} + +func TestFormatFloat(t *testing.T) { + tests := []TestStruct{ + {"default", "", 12345.6789, "12,345.68"}, + {"#", "#", 12345.6789, "12345.678900000"}, + {"#.", "#.", 12345.6789, "12346"}, + {"#,#", "#,#", 12345.6789, "12345,7"}, + {"#,##", "#,##", 12345.6789, "12345,68"}, + {"#,###", "#,###", 12345.6789, "12345,679"}, + {"#,###.", "#,###.", 12345.6789, "12,346"}, + {"#,###.##", "#,###.##", 12345.6789, "12,345.68"}, + {"#,###.###", "#,###.###", 12345.6789, "12,345.679"}, + {"#,###.####", "#,###.####", 12345.6789, "12,345.6789"}, + {"#.###,######", "#.###,######", 12345.6789, "12.345,678900"}, + {"#\u202f###,##", "#\u202f###,##", 12345.6789, "12 345,68"}, + + // special cases + {"NaN", "#", math.NaN(), "NaN"}, + {"+Inf", "#", math.Inf(1), "Infinity"}, + {"-Inf", "#", math.Inf(-1), "-Infinity"}, + {"signStr <= -0.000000001", "", -0.000000002, "-0.00"}, + {"signStr = 0", "", 0, "0.00"}, + {"Format directive must start with +", "+000", 12345.6789, "+12345.678900000"}, + } + + for _, test := range tests { + got := FormatFloat(test.format, test.num) + if got != test.formatted { + t.Errorf("On %v (%v, %v), got %v, wanted %v", + test.name, test.format, test.num, got, test.formatted) + } + } + // Test a single integer + got := FormatInteger("#", 12345) + if got != "12345.000000000" { + t.Errorf("On %v (%v, %v), got %v, wanted %v", + "integerTest", "#", 12345, got, "12345.000000000") + } + // Test the things that could panic + panictests := []TestStruct{ + {"RenderFloat(): invalid positive sign directive", "-", 12345.6789, "12,345.68"}, + {"RenderFloat(): thousands separator directive must be followed by 3 digit-specifiers", "0.01", 12345.6789, "12,345.68"}, + } + for _, test := range panictests { + didPanic := false + var message interface{} + func() { + + defer func() { + if message = recover(); message != nil { + didPanic = true + } + }() + + // call the target function + _ = FormatFloat(test.format, test.num) + + }() + if didPanic != true { + t.Errorf("On %v, should have panic and did not.", + test.name) + } + } + +} diff --git a/Godeps/_workspace/src/github.com/minio/minio/pkg/iodine/iodine.go b/Godeps/_workspace/src/github.com/minio/minio/pkg/iodine/iodine.go index 96903052..4f78f2ea 100644 --- a/Godeps/_workspace/src/github.com/minio/minio/pkg/iodine/iodine.go +++ b/Godeps/_workspace/src/github.com/minio/minio/pkg/iodine/iodine.go @@ -1,5 +1,5 @@ /* - * Iodine, (C) 2015 Minio, Inc. + * Minio Cloud Storage, (C) 2015 Minio, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -202,7 +202,7 @@ func getSystemData() map[string]string { // EmitJSON writes JSON output for the error func (err Error) EmitJSON() ([]byte, error) { - return json.Marshal(err) + return json.MarshalIndent(err, "", "\t") } // EmitHumanReadable returns a human readable error message diff --git a/Godeps/_workspace/src/gopkg.in/check.v1/check.go b/Godeps/_workspace/src/gopkg.in/check.v1/check.go index c6fa0419..ca8c0f92 100644 --- a/Godeps/_workspace/src/gopkg.in/check.v1/check.go +++ b/Godeps/_workspace/src/gopkg.in/check.v1/check.go @@ -122,7 +122,7 @@ func (l *logger) String() string { } // ----------------------------------------------------------------------- -// Handling of temporary files and folders. +// Handling of temporary files and directories. type tempDir struct { sync.Mutex diff --git a/buildscripts/updatedeps.sh b/buildscripts/updatedeps.sh index c71d2e70..6c8281f2 100755 --- a/buildscripts/updatedeps.sh +++ b/buildscripts/updatedeps.sh @@ -21,7 +21,7 @@ _init() { } update() { - for dep in $1; do + for dep in $@; do godep update $dep; done }