mirror of
https://github.com/microsoft/regorus.git
synced 2026-08-05 02:16:11 +00:00
Preserve false in single-expression queries (#145)
Note: 1 = 2 is different from 1 == 2 See issue for details fixes #144 Signed-off-by: Anand Krishnamoorthi <anakrish@microsoft.com>
This commit is contained in:
committed by
GitHub
parent
7d32bd9377
commit
8d282f1ffd
+39
-3
@@ -186,17 +186,33 @@ impl Default for QueryResult {
|
||||
/// ```
|
||||
/// # use regorus::*;
|
||||
/// # fn main() -> anyhow::Result<()> {
|
||||
/// // Create engine and evaluate "true; true; false".
|
||||
/// // Create engine and evaluate "1 + 1".
|
||||
/// let results = Engine::new().eval_query("1 + 1".to_string(), false)?;
|
||||
///
|
||||
/// assert!(results.result.len() == 1);
|
||||
/// assert_eq!(results.result.len(), 1);
|
||||
/// assert_eq!(results.result[0].expressions[0].value, Value::from(2u64));
|
||||
/// assert_eq!(results.result[0].expressions[0].text.as_ref(), "1 + 1");
|
||||
/// # Ok(())
|
||||
/// # }
|
||||
/// ```
|
||||
///
|
||||
/// If any expression evaluates to false, then no results are produced.
|
||||
/// If a query contains only one expression, and even if the expression evaluates
|
||||
/// to false, the value will be returned.
|
||||
/// ```
|
||||
/// # use regorus::*;
|
||||
/// # fn main() -> anyhow::Result<()> {
|
||||
/// // Create engine and evaluate "1 > 2" which is false.
|
||||
/// let results = Engine::new().eval_query("1 > 2".to_string(), false)?;
|
||||
///
|
||||
/// assert_eq!(results.result.len(), 1);
|
||||
/// assert_eq!(results.result[0].expressions[0].value, Value::from(false));
|
||||
/// assert_eq!(results.result[0].expressions[0].text.as_ref(), "1 > 2");
|
||||
/// # Ok(())
|
||||
/// # }
|
||||
/// ```
|
||||
///
|
||||
/// In a query containing multiple expressions, if any expression evaluates to false,
|
||||
/// then no results are produced.
|
||||
/// ```
|
||||
/// # use regorus::*;
|
||||
/// # fn main() -> anyhow::Result<()> {
|
||||
@@ -208,6 +224,26 @@ impl Default for QueryResult {
|
||||
/// # }
|
||||
/// ```
|
||||
///
|
||||
/// Note that `=` is different from `==`. The former evaluates to undefined if the LHS and RHS
|
||||
/// are not equal. The latter evaluates to either true or false.
|
||||
/// ```
|
||||
/// # use regorus::*;
|
||||
/// # fn main() -> anyhow::Result<()> {
|
||||
/// // Create engine and evaluate "1 = 2" which is undefined and produces no resutl.
|
||||
/// let results = Engine::new().eval_query("1 = 2".to_string(), false)?;
|
||||
///
|
||||
/// assert_eq!(results.result.len(), 0);
|
||||
///
|
||||
/// // Create engine and evaluate "1 == 2" which evaluates to false.
|
||||
/// let results = Engine::new().eval_query("1 == 2".to_string(), false)?;
|
||||
///
|
||||
/// assert_eq!(results.result.len(), 1);
|
||||
/// assert_eq!(results.result[0].expressions[0].value, Value::from(false));
|
||||
/// assert_eq!(results.result[0].expressions[0].text.as_ref(), "1 == 2");
|
||||
/// # Ok(())
|
||||
/// # }
|
||||
/// ```
|
||||
///
|
||||
/// Queries containing loops produce multiple results.
|
||||
/// ```
|
||||
/// # use regorus::*;
|
||||
|
||||
Reference in New Issue
Block a user