Fixes/additions for lexing units
This commit is contained in:
parent
83fd5c233a
commit
35043932d5
@ -57,7 +57,7 @@ pub fn lex(input: &str) -> Result<TokenVector, String> {
|
|||||||
let string = &input[start_index..=end_index];
|
let string = &input[start_index..=end_index];
|
||||||
match string.trim_end() {
|
match string.trim_end() {
|
||||||
// allow for two-word units
|
// allow for two-word units
|
||||||
"nautical" | "light" | "sq" | "square" | "cubic" => {
|
"nautical" | "light" | "sq" | "square" | "cubic" | "metric" => {
|
||||||
byte_index += current_char.len_utf8();
|
byte_index += current_char.len_utf8();
|
||||||
chars.next();
|
chars.next();
|
||||||
end_index += 1;
|
end_index += 1;
|
||||||
@ -126,7 +126,8 @@ pub fn lex(input: &str) -> Result<TokenVector, String> {
|
|||||||
"yd" | "yard" | "yards" => tokens.push(Token::Unit(Yard)),
|
"yd" | "yard" | "yards" => tokens.push(Token::Unit(Yard)),
|
||||||
"mi" | "mile" | "miles" => tokens.push(Token::Unit(Mile)),
|
"mi" | "mile" | "miles" => tokens.push(Token::Unit(Mile)),
|
||||||
"nmi" | "nautical mile" | "nautical miles" => tokens.push(Token::Unit(NauticalMile)),
|
"nmi" | "nautical mile" | "nautical miles" => tokens.push(Token::Unit(NauticalMile)),
|
||||||
"lightyear" | "lightyears" | "light year" | "light years" => tokens.push(Token::Unit(LightYear)),
|
"ly" | "lightyear" | "lightyears" | "light yr" | "light yrs" | "light year" | "light years" => tokens.push(Token::Unit(LightYear)),
|
||||||
|
"lightsec" | "lightsecs" | "lightsecond" | "lightseconds" | "light sec" | "light secs" | "light second" | "light seconds" => tokens.push(Token::Unit(LightYear)),
|
||||||
|
|
||||||
"sqmm" | "sq mm" | "sq millimeter" | "sq millimeters" => tokens.push(Token::Unit(SquareMillimeter)),
|
"sqmm" | "sq mm" | "sq millimeter" | "sq millimeters" => tokens.push(Token::Unit(SquareMillimeter)),
|
||||||
"sqcm" | "sq cm" | "sq centimeter" | "sq centimeters" => tokens.push(Token::Unit(SquareCentimeter)),
|
"sqcm" | "sq cm" | "sq centimeter" | "sq centimeters" => tokens.push(Token::Unit(SquareCentimeter)),
|
||||||
|
|||||||
@ -268,6 +268,7 @@ mod tests {
|
|||||||
assert_eq!(convert_test(1760.0, Yard, Mile), 1.0);
|
assert_eq!(convert_test(1760.0, Yard, Mile), 1.0);
|
||||||
assert_eq!(convert_test(1852.0, Meter, NauticalMile), 1.0);
|
assert_eq!(convert_test(1852.0, Meter, NauticalMile), 1.0);
|
||||||
assert_eq!(convert_test(9460730472580800.0, Meter, LightYear), 1.0);
|
assert_eq!(convert_test(9460730472580800.0, Meter, LightYear), 1.0);
|
||||||
|
assert_eq!(convert_test(299792458.0, Meter, LightSecond), 1.0);
|
||||||
|
|
||||||
assert_eq!(convert_test(100.0, SquareMillimeter, SquareCentimeter), 1.0);
|
assert_eq!(convert_test(100.0, SquareMillimeter, SquareCentimeter), 1.0);
|
||||||
assert_eq!(convert_test(100.0, SquareCentimeter, SquareDecimeter), 1.0);
|
assert_eq!(convert_test(100.0, SquareCentimeter, SquareDecimeter), 1.0);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user