mirror of
https://github.com/walles/moar.git
synced 2024-09-11 12:15:43 +03:00
parent
5932600b65
commit
083f64dc9d
@ -2,8 +2,16 @@ package m
|
||||
|
||||
import "fmt"
|
||||
|
||||
// Formats a number into a string with _ between each three-group of digits
|
||||
// Formats a number into a string with _ between each three-group of digits, for
|
||||
// numbers >= 10_000.
|
||||
//
|
||||
// Regarding the >= 10_000 exception:
|
||||
// https://en.wikipedia.org/wiki/Decimal_separator#Exceptions_to_digit_grouping
|
||||
func formatNumber(number uint) string {
|
||||
if number < 10_000 {
|
||||
return fmt.Sprint(number)
|
||||
}
|
||||
|
||||
result := ""
|
||||
|
||||
chars := []rune(fmt.Sprint(number))
|
||||
|
@ -10,7 +10,10 @@ func TestNumberFormatting(t *testing.T) {
|
||||
assert.Equal(t, "1", formatNumber(1))
|
||||
assert.Equal(t, "10", formatNumber(10))
|
||||
assert.Equal(t, "100", formatNumber(100))
|
||||
assert.Equal(t, "1_000", formatNumber(1000))
|
||||
|
||||
// Ref: // https://en.wikipedia.org/wiki/Decimal_separator#Exceptions_to_digit_grouping
|
||||
assert.Equal(t, "1000", formatNumber(1000))
|
||||
|
||||
assert.Equal(t, "10_000", formatNumber(10000))
|
||||
assert.Equal(t, "100_000", formatNumber(100000))
|
||||
assert.Equal(t, "1_000_000", formatNumber(1000000))
|
||||
|
@ -276,7 +276,7 @@ func testStatusText(t *testing.T, fromLine int, toLine int, totalLines int, expe
|
||||
func TestStatusText(t *testing.T) {
|
||||
testStatusText(t, 1, 10, 20, "20 lines 50%")
|
||||
testStatusText(t, 1, 5, 5, "5 lines 100%")
|
||||
testStatusText(t, 998, 999, 1000, "1_000 lines 99%")
|
||||
testStatusText(t, 998, 999, 1000, "1000 lines 99%")
|
||||
|
||||
testStatusText(t, 0, 0, 0, "<empty>")
|
||||
testStatusText(t, 1, 1, 1, "1 line 100%")
|
||||
|
Loading…
Reference in New Issue
Block a user