GithubHelp home page GithubHelp logo

eval's People

Contributors

fengcen avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

eval's Issues

Incorrect evaluation order when using data-like access

Evaluation order seems to be wrong when the dot operator is used.

    #[test]
    fn test_operator_precedence() {
        // Show that operator precedence is working as expected.
        assert_eq!(eval(r#""a" == "a" && "b" == "b""#), Ok(to_value(true)));
        
        let mut v = HashMap::new();
        v.insert("a", "1");
        v.insert("b", "2");
        
        // This is returning the expected result if we put the comparisons between parentheses.
        assert_eq!(Expr::new("(v.a == v.a) && (v.b == v.b)").value("v", v.clone()).exec(), 
            Ok(to_value(true)));

        // This should return the same result as the previous Expr, but it is instead 
        // returning Err(UnsupportedTypes("String(\"1\")", "Bool(true)")).
        assert_eq!(Expr::new("v.a == v.a && v.b == v.b").value("v", v).exec(), 
            Ok(to_value(true)));
    }

Incorrect evaluation when multiplying the result of parenthesis

example:
eval("2 * 4 + 4") will correctly evaluate to 12 while eval("2 * (2 + 2) + (1 + 3)") or even eval(2 * (4) + (4)) will evaluate to 16, even though the two expressions should have the same result.

fn main() {
    assert_eq!(eval("2 * 4 + 4"), Ok(to_value(12)));
    assert_eq!(eval("2 * (4) + (4)"), Ok(to_value(12)));
}
thread 'main' panicked at 'assertion failed: `(left == right)`
  left: `Ok(Number(16))`,
 right: `Ok(Number(12))`', src/main.rs:7:5

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.