stack_wallet/test/formet_test.dart
2022-08-26 16:11:35 +08:00

85 lines
2.2 KiB
Dart

import 'package:decimal/decimal.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:stackwallet/utilities/format.dart';
void main() {
group("satoshisToAmount", () {
test("12345", () {
expect(Format.satoshisToAmount(12345), Decimal.parse("0.00012345"));
});
test("100012345", () {
expect(Format.satoshisToAmount(100012345), Decimal.parse("1.00012345"));
});
test("0", () {
expect(Format.satoshisToAmount(0), Decimal.zero);
});
test("1000000000", () {
expect(Format.satoshisToAmount(1000000000), Decimal.parse("10"));
});
});
group("satoshiAmountToPrettyString", () {
const locale = "en_US";
test("12345", () {
expect(Format.satoshiAmountToPrettyString(12345, locale), "0.00012345");
});
test("100012345", () {
expect(
Format.satoshiAmountToPrettyString(100012345, locale), "1.00012345");
});
test("123450000", () {
expect(
Format.satoshiAmountToPrettyString(123450000, locale), "1.23450000");
});
test("1230045000", () {
expect(Format.satoshiAmountToPrettyString(1230045000, locale),
"12.30045000");
});
test("1000000000", () {
expect(Format.satoshiAmountToPrettyString(1000000000, locale),
"10.00000000");
});
test("0", () {
expect(Format.satoshiAmountToPrettyString(0, locale), "0.00000000");
});
});
group("extractDateFrom", () {
test("1614578400", () {
expect(Format.extractDateFrom(1614578400, localized: false),
"1 Mar 2021, 6:00");
});
test("1641589563", () {
expect(Format.extractDateFrom(1641589563, localized: false),
"7 Jan 2022, 21:06");
});
});
group("formatDate", () {
test("formatDate", () {
final date = DateTime(2020);
expect(Format.formatDate(date), "01/01/20");
});
test("formatDate", () {
final date = DateTime(2021, 2, 6, 23, 58);
expect(Format.formatDate(date), "02/06/21");
});
test("formatDate", () {
final date = DateTime(2021, 13);
expect(Format.formatDate(date), "01/01/22");
});
test("formatDate", () {
final date = DateTime(2021, 2, 35);
expect(Format.formatDate(date), "03/07/21");
});
});
}