Make Amount a fmt.Stringer.
This commit is contained in:
parent
fc6f0dee54
commit
80b1f232bc
3 changed files with 22 additions and 7 deletions
|
@ -92,3 +92,8 @@ func (a Amount) Format(u AmountUnit) string {
|
|||
units := " " + u.String()
|
||||
return strconv.FormatFloat(a.ToUnit(u), 'f', -int(u+8), 64) + units
|
||||
}
|
||||
|
||||
// String is the equivalent of calling Format with AmountBitcoin.
|
||||
func (a Amount) String() string {
|
||||
return a.Format(AmountBitcoin)
|
||||
}
|
||||
|
|
|
@ -102,6 +102,7 @@ func TestAmountCreation(t *testing.T) {
|
|||
|
||||
if a != test.expected {
|
||||
t.Errorf("%v: Created amount %v does not match expected %v", test.name, a, test.expected)
|
||||
continue
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -178,6 +179,14 @@ func TestAmountUnitConversions(t *testing.T) {
|
|||
s := test.amount.Format(test.unit)
|
||||
if s != test.s {
|
||||
t.Errorf("%v: format '%v' does not match expected '%v'", test.name, s, test.s)
|
||||
continue
|
||||
}
|
||||
|
||||
// Verify that Amount.String works as advertised.
|
||||
s1 := test.amount.Format(AmountBitcoin)
|
||||
s2 := test.amount.String()
|
||||
if s1 != s2 {
|
||||
t.Errorf("%v: String does not match Format(AmountBitcoin): %v != %v", test.name, s1, s2)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,12 +8,12 @@ github.com/conformal/btcutil/amount.go AmountUnit.String 100.00% (8/8)
|
|||
github.com/conformal/btcutil/amount.go NewAmount 100.00% (8/8)
|
||||
github.com/conformal/btcutil/block.go NewBlockFromBytes 100.00% (7/7)
|
||||
github.com/conformal/btcutil/tx.go NewTxFromBytes 100.00% (7/7)
|
||||
github.com/conformal/btcutil/tx.go Tx.Sha 100.00% (5/5)
|
||||
github.com/conformal/btcutil/block.go Block.Sha 100.00% (5/5)
|
||||
github.com/conformal/btcutil/tx.go Tx.Sha 100.00% (5/5)
|
||||
github.com/conformal/btcutil/amount.go Amount.Format 100.00% (2/2)
|
||||
github.com/conformal/btcutil/address.go NewAddressScriptHash 100.00% (2/2)
|
||||
github.com/conformal/btcutil/hash160.go calcHash 100.00% (2/2)
|
||||
github.com/conformal/btcutil/hash160.go Hash160 100.00% (1/1)
|
||||
github.com/conformal/btcutil/block.go Block.MsgBlock 100.00% (1/1)
|
||||
github.com/conformal/btcutil/address.go AddressPubKeyHash.EncodeAddress 100.00% (1/1)
|
||||
github.com/conformal/btcutil/address.go AddressPubKeyHash.ScriptAddress 100.00% (1/1)
|
||||
github.com/conformal/btcutil/address.go AddressPubKeyHash.String 100.00% (1/1)
|
||||
|
@ -24,35 +24,36 @@ github.com/conformal/btcutil/address.go AddressPubKey.EncodeAddress 100.00% (1
|
|||
github.com/conformal/btcutil/address.go AddressPubKey.ScriptAddress 100.00% (1/1)
|
||||
github.com/conformal/btcutil/address.go AddressPubKey.String 100.00% (1/1)
|
||||
github.com/conformal/btcutil/amount.go Amount.ToUnit 100.00% (1/1)
|
||||
github.com/conformal/btcutil/amount.go Amount.String 100.00% (1/1)
|
||||
github.com/conformal/btcutil/block.go OutOfRangeError.Error 100.00% (1/1)
|
||||
github.com/conformal/btcutil/block.go Block.MsgBlock 100.00% (1/1)
|
||||
github.com/conformal/btcutil/block.go Block.Height 100.00% (1/1)
|
||||
github.com/conformal/btcutil/block.go Block.SetHeight 100.00% (1/1)
|
||||
github.com/conformal/btcutil/block.go NewBlock 100.00% (1/1)
|
||||
github.com/conformal/btcutil/block.go NewBlockFromBlockAndBytes 100.00% (1/1)
|
||||
github.com/conformal/btcutil/hash160.go Hash160 100.00% (1/1)
|
||||
github.com/conformal/btcutil/tx.go Tx.MsgTx 100.00% (1/1)
|
||||
github.com/conformal/btcutil/tx.go Tx.Index 100.00% (1/1)
|
||||
github.com/conformal/btcutil/tx.go Tx.SetIndex 100.00% (1/1)
|
||||
github.com/conformal/btcutil/tx.go NewTx 100.00% (1/1)
|
||||
github.com/conformal/btcutil/address.go DecodeAddress 95.65% (22/23)
|
||||
github.com/conformal/btcutil/appdata.go appDataDir 92.00% (23/25)
|
||||
github.com/conformal/btcutil/address.go NewAddressPubKeyHash 91.67% (11/12)
|
||||
github.com/conformal/btcutil/address.go NewAddressScriptHashFromHash 91.67% (11/12)
|
||||
github.com/conformal/btcutil/address.go NewAddressPubKeyHash 91.67% (11/12)
|
||||
github.com/conformal/btcutil/address.go EncodePrivateKey 90.91% (20/22)
|
||||
github.com/conformal/btcutil/block.go Block.TxLoc 88.89% (8/9)
|
||||
github.com/conformal/btcutil/block.go Block.Bytes 88.89% (8/9)
|
||||
github.com/conformal/btcutil/block.go Block.TxLoc 88.89% (8/9)
|
||||
github.com/conformal/btcutil/address.go AddressPubKey.serialize 85.71% (6/7)
|
||||
github.com/conformal/btcutil/address.go DecodePrivateKey 83.33% (20/24)
|
||||
github.com/conformal/btcutil/address.go NewAddressPubKey 83.33% (15/18)
|
||||
github.com/conformal/btcutil/address.go checkBitcoinNet 83.33% (5/6)
|
||||
github.com/conformal/btcutil/block.go Block.TxSha 75.00% (3/4)
|
||||
github.com/conformal/btcutil/address.go AddressPubKeyHash.IsForNet 60.00% (3/5)
|
||||
github.com/conformal/btcutil/address.go AddressScriptHash.IsForNet 60.00% (3/5)
|
||||
github.com/conformal/btcutil/address.go AddressPubKeyHash.IsForNet 60.00% (3/5)
|
||||
github.com/conformal/btcutil/address.go AddressPubKey.IsForNet 60.00% (3/5)
|
||||
github.com/conformal/btcutil/certgen.go NewTLSCertPair 0.00% (0/50)
|
||||
github.com/conformal/btcutil/address.go AddressPubKey.AddressPubKeyHash 0.00% (0/3)
|
||||
github.com/conformal/btcutil/appdata.go AppDataDir 0.00% (0/1)
|
||||
github.com/conformal/btcutil/address.go AddressPubKey.Format 0.00% (0/1)
|
||||
github.com/conformal/btcutil/address.go AddressPubKey.SetFormat 0.00% (0/1)
|
||||
github.com/conformal/btcutil ------------------------------- 78.46% (295/376)
|
||||
github.com/conformal/btcutil ------------------------------- 78.51% (296/377)
|
||||
|
||||
|
|
Loading…
Reference in a new issue