From 653648e3ce86aeb8085463b26f6b2d8a390938f0 Mon Sep 17 00:00:00 2001 From: Uttarayan Mondal Date: Tue, 9 Mar 2021 17:48:35 +0530 Subject: [PATCH] Fix bug change digit_seperator to place_seperator --- Cargo.toml | 2 +- src/numtext.rs | 2 +- src/test.rs | 15 +++++++++++++++ 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 422ade8..4b1d601 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "ntext" -version = "0.2.0" +version = "0.2.1" authors = ["Uttarayan Mondal "] edition = "2018" description = "A rust library to write numbers as words" diff --git a/src/numtext.rs b/src/numtext.rs index 1e8d724..b286998 100644 --- a/src/numtext.rs +++ b/src/numtext.rs @@ -162,7 +162,7 @@ pub fn to_text_fmt(number: usize, fmt: &Formatting) -> String { if let Some(last_digit) = last { numtext.push_str(tens_place(last_digit, *digit, fmt).unwrap().as_str()); if place > 2 { - if let Some(sep) = fmt.digit_seperator { + if let Some(sep) = fmt.place_seperator { numtext.push_str(sep); } numtext.push_str(place_value(0, place, fmt).unwrap().as_str()); diff --git a/src/test.rs b/src/test.rs index b7c27f7..a39273a 100644 --- a/src/test.rs +++ b/src/test.rs @@ -25,4 +25,19 @@ mod tests { ); assert_eq!(to_text(12, fmt), "twelve"); } + #[test] + fn numbers_formatting() { + use crate::to_text_fmt as to_text; + use crate::Formatting; + let fmt = &Formatting::default(); + assert_eq!(to_text(1, fmt), "One"); + assert_eq!(to_text(10, fmt), "Ten"); + assert_eq!(to_text(100, fmt), "One Hundred"); + assert_eq!(to_text(1000, fmt), "One Thousand"); + assert_eq!(to_text(12315, fmt), "Twelve Thousand,Three Hundred,Fifteen"); + assert_eq!( + to_text(1235245, fmt), + "Twelve Million,Thirty-Five Thousand,Two Hundred,Forty-Five" + ); + } }