From 9bfc8504a4da9e32062b5da28e1874c1de77a6f6 Mon Sep 17 00:00:00 2001 From: PlexSheep Date: Sun, 12 May 2024 20:20:36 +0200 Subject: [PATCH] test: add padding test #12 --- tests/format.rs | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/tests/format.rs b/tests/format.rs index ab35494..b35538a 100644 --- a/tests/format.rs +++ b/tests/format.rs @@ -21,3 +21,29 @@ fn format() { assert_eq!(Format::Base64.format(0x41414242, &options), "QUFCQg=="); assert_eq!(Format::Base64.format(0x4141414141414141, &options), "QUFBQUFBQUE="); } + +#[test] +fn format_padding() { + let mut options = FormatOptions::default(); + options.set_padding(true); + + assert_eq!(Format::Dec.format(1337, &options), "1337"); + assert_eq!(Format::Dec.format(u128::MAX, &options), format!("{}", u128::MAX)); + + assert_eq!(Format::Hex.format(0xFFF, &options), "0FFF"); + assert_eq!(Format::Hex.format(0xFFFF, &options), "FFFF"); + assert_eq!(Format::Hex.format(u128::MAX, &options), format!("{:X}", u128::MAX)); + + assert_eq!(Format::Bin.format(0b11110000_00001111, &options), "1111000000001111"); + assert_eq!(Format::Bin.format(0b110000_00001111, &options), "0011000000001111"); + assert_eq!(Format::Bin.format(u128::MAX, &options), format!("{:b}", u128::MAX)); + + assert_eq!(Format::Octal.format(0o13377331, &options), "13377331"); + assert_eq!(Format::Octal.format(u128::MAX, &options), format!("{:o}", u128::MAX)); + + assert_eq!(Format::Base32.format(0x41414242, &options), "IFAUEQQ="); + assert_eq!(Format::Base32.format(0x4141414141414141, &options), "IFAUCQKBIFAUC==="); + + assert_eq!(Format::Base64.format(0x41414242, &options), "QUFCQg=="); + assert_eq!(Format::Base64.format(0x4141414141414141, &options), "QUFBQUFBQUE="); +}