Add support for US tablespoons
This commit is contained in:
parent
1639748c68
commit
c16befe55c
|
@ -123,6 +123,11 @@ fn get_conversion(unit: NonMetric) -> Conversion {
|
|||
from: imperial_gallon_from,
|
||||
to: MetricQuantity { amount: imperial_gallon_to, unit: Metric::Litre },
|
||||
},
|
||||
NonMetric::USTablespoon => Conversion {
|
||||
offset: 0.0,
|
||||
from: 2.0 * 16.0 * 2.0 * 4.0 * us_gallon_from,
|
||||
to: MetricQuantity { amount: us_gallon_to, unit: Metric::Litre },
|
||||
},
|
||||
NonMetric::USFluidOunce => Conversion {
|
||||
offset: 0.0,
|
||||
from: 16.0 * 2.0 * 4.0 * us_gallon_from,
|
||||
|
@ -223,6 +228,7 @@ mod test {
|
|||
Test(NonMetric::ImperialPint, 0.56826125),
|
||||
Test(NonMetric::ImperialQuart, 1.1365225),
|
||||
Test(NonMetric::ImperialGallon, 4.54609),
|
||||
Test(NonMetric::USTablespoon, 0.01478676478125),
|
||||
Test(NonMetric::USFluidOunce, 0.0295735295625),
|
||||
Test(NonMetric::USCup, 0.2365882365),
|
||||
Test(NonMetric::USLiquidPint, 0.473176473),
|
||||
|
|
|
@ -89,6 +89,7 @@ fn unit_to_name(unit: NonMetric) -> &'static str {
|
|||
NonMetric::ImperialPint => "imperial pints",
|
||||
NonMetric::ImperialQuart => "imperial quarts",
|
||||
NonMetric::ImperialGallon => "imperial gallons",
|
||||
NonMetric::USTablespoon => "US tablespoons",
|
||||
NonMetric::USFluidOunce => "US fluid ounces",
|
||||
NonMetric::USCup => "US cups",
|
||||
NonMetric::USLiquidPint => "US liquid pints",
|
||||
|
@ -140,6 +141,7 @@ mod test {
|
|||
assert_eq!(run("1 imp pt"), Ok("5.683 dl".to_string()));
|
||||
assert_eq!(run("1 imp qt"), Ok("1.137 l".to_string()));
|
||||
assert_eq!(run("1 imp gal"), Ok("4.546 l".to_string()));
|
||||
assert_eq!(run("1 Tbsp"), Ok("1.479 cl".to_string()));
|
||||
assert_eq!(run("1 US fl oz"), Ok("2.957 cl".to_string()));
|
||||
assert_eq!(run("1 US cup"), Ok("2.366 dl".to_string()));
|
||||
assert_eq!(run("1 US pt"), Ok("4.732 dl".to_string()));
|
||||
|
|
30
src/parse.rs
30
src/parse.rs
|
@ -205,6 +205,21 @@ fn parse_unit(input: String) -> Result<NonMetric, ParseError> {
|
|||
"imperial gallons" => Ok(NonMetric::ImperialGallon),
|
||||
"imp gal" => Ok(NonMetric::ImperialGallon),
|
||||
|
||||
"US tablespoon" => Ok(NonMetric::USTablespoon),
|
||||
"US tablespoons" => Ok(NonMetric::USTablespoon),
|
||||
"US Tbsp." => Ok(NonMetric::USTablespoon),
|
||||
"US Tbsp" => Ok(NonMetric::USTablespoon),
|
||||
"us tablespoon" => Ok(NonMetric::USTablespoon),
|
||||
"us tablespoons" => Ok(NonMetric::USTablespoon),
|
||||
"us tbsp." => Ok(NonMetric::USTablespoon),
|
||||
"us tbsp" => Ok(NonMetric::USTablespoon),
|
||||
"tablespoon" => Ok(NonMetric::USTablespoon),
|
||||
"tablespoons" => Ok(NonMetric::USTablespoon),
|
||||
"Tbsp." => Ok(NonMetric::USTablespoon),
|
||||
"Tbsp" => Ok(NonMetric::USTablespoon),
|
||||
"tbsp." => Ok(NonMetric::USTablespoon),
|
||||
"tbsp" => Ok(NonMetric::USTablespoon),
|
||||
|
||||
"US fluid ounce" => Ok(NonMetric::USFluidOunce),
|
||||
"US fluid ounces" => Ok(NonMetric::USFluidOunce),
|
||||
"US fl oz" => Ok(NonMetric::USFluidOunce),
|
||||
|
@ -506,6 +521,21 @@ mod test {
|
|||
assert_eq!(parse_unit("imperial gallons".to_string()), Ok(NonMetric::ImperialGallon));
|
||||
assert_eq!(parse_unit("imp gal".to_string()), Ok(NonMetric::ImperialGallon));
|
||||
|
||||
assert_eq!(parse_unit("US tablespoon".to_string()), Ok(NonMetric::USTablespoon));
|
||||
assert_eq!(parse_unit("US tablespoons".to_string()), Ok(NonMetric::USTablespoon));
|
||||
assert_eq!(parse_unit("US Tbsp.".to_string()), Ok(NonMetric::USTablespoon));
|
||||
assert_eq!(parse_unit("US Tbsp".to_string()), Ok(NonMetric::USTablespoon));
|
||||
assert_eq!(parse_unit("us tablespoon".to_string()), Ok(NonMetric::USTablespoon));
|
||||
assert_eq!(parse_unit("us tablespoons".to_string()), Ok(NonMetric::USTablespoon));
|
||||
assert_eq!(parse_unit("us tbsp.".to_string()), Ok(NonMetric::USTablespoon));
|
||||
assert_eq!(parse_unit("us tbsp".to_string()), Ok(NonMetric::USTablespoon));
|
||||
assert_eq!(parse_unit("tablespoon".to_string()), Ok(NonMetric::USTablespoon));
|
||||
assert_eq!(parse_unit("tablespoons".to_string()), Ok(NonMetric::USTablespoon));
|
||||
assert_eq!(parse_unit("Tbsp.".to_string()), Ok(NonMetric::USTablespoon));
|
||||
assert_eq!(parse_unit("Tbsp".to_string()), Ok(NonMetric::USTablespoon));
|
||||
assert_eq!(parse_unit("tbsp.".to_string()), Ok(NonMetric::USTablespoon));
|
||||
assert_eq!(parse_unit("tbsp".to_string()), Ok(NonMetric::USTablespoon));
|
||||
|
||||
assert_eq!(parse_unit("US fluid ounce".to_string()), Ok(NonMetric::USFluidOunce));
|
||||
assert_eq!(parse_unit("US fluid ounces".to_string()), Ok(NonMetric::USFluidOunce));
|
||||
assert_eq!(parse_unit("US fl oz".to_string()), Ok(NonMetric::USFluidOunce));
|
||||
|
|
|
@ -34,6 +34,7 @@ pub enum NonMetric {
|
|||
ImperialPint,
|
||||
ImperialQuart,
|
||||
ImperialGallon,
|
||||
USTablespoon,
|
||||
USFluidOunce,
|
||||
USCup,
|
||||
USLiquidPint,
|
||||
|
|
Loading…
Reference in New Issue