MCPcopy Create free account
hub / github.com/NodeDB-Lab/nodedb / case_when

Function case_when

nodedb-query/src/expr_parse/parser.rs:543–554  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

541
542 #[test]
543 fn case_when() {
544 let (expr, deps) =
545 parse_ok("CASE WHEN discount > 0 THEN price * (1 - discount) ELSE price END");
546 assert!(deps.contains(&"discount".to_string()));
547 assert!(deps.contains(&"price".to_string()));
548
549 let doc = Value::from(serde_json::json!({"price": 100.0, "discount": 0.2}));
550 assert_eq!(expr.eval(&doc).as_f64(), Some(80.0));
551
552 let doc2 = Value::from(serde_json::json!({"price": 100.0, "discount": 0}));
553 assert_eq!(expr.eval(&doc2).as_f64(), Some(100.0));
554 }
555
556 #[test]
557 fn rejects_now() {

Callers

nothing calls this directly

Calls 1

parse_okFunction · 0.70

Tested by

no test coverage detected