mirror of
https://github.com/tiffany352/rink-rs
synced 2024-11-10 13:44:15 +00:00
Allow of
in right-hand side of conversion
This commit is contained in:
parent
d629d707de
commit
5ccb9d064f
2 changed files with 26 additions and 2 deletions
20
src/eval.rs
20
src/eval.rs
|
@ -313,8 +313,24 @@ impl Context {
|
|||
.collect::<BTreeMap<_, _>>(),
|
||||
pow(&lv, res as i32)))
|
||||
},
|
||||
Expr::Of(ref _field, ref _expr) => {
|
||||
Err(format!("Property access in right-hand of conversion is not yet implemented"))
|
||||
Expr::Of(ref name, ref expr) => {
|
||||
let res = try!(self.eval(expr));
|
||||
let res = match res {
|
||||
Value::Substance(sub) => sub,
|
||||
_ => return Err(format!("Property access on non-substance"))
|
||||
};
|
||||
let name = if let Some(prop) = res.properties.properties.get(name) {
|
||||
if prop.input == Number::one() {
|
||||
&prop.input_name
|
||||
} else {
|
||||
name
|
||||
}
|
||||
} else {
|
||||
name
|
||||
};
|
||||
let mut map = BTreeMap::new();
|
||||
map.insert(self.canonicalize(&**name).unwrap_or_else(|| name.clone()), 1);
|
||||
Ok((map, Num::one()))
|
||||
},
|
||||
Expr::Add(ref left, ref right) | Expr::Sub(ref left, ref right) => {
|
||||
let left = try!(self.eval_unit_name(left));
|
||||
|
|
|
@ -206,3 +206,11 @@ fn test_duration_add() {
|
|||
fn test_0_seconds() {
|
||||
test("0 s", "0 second (time)");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn right_hand_property() {
|
||||
test("kg -> mass_shelled of egg",
|
||||
"20 egg_shelled (mass)");
|
||||
test("nauticalmile -> arcmin radius of earth / radian",
|
||||
"approx. 0.9993245 arcmin earth_radius / radian (length)");
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue