aboutsummaryrefslogtreecommitdiff
path: root/src/sexp/step.rs
diff options
context:
space:
mode:
authorJoel Kronqvist <joel.kronqvist@iki.fi>2025-08-05 11:40:00 +0300
committerJoel Kronqvist <joel.kronqvist@iki.fi>2025-08-05 11:40:00 +0300
commitc629fac4297b8f13bdab00100f3b05549174154e (patch)
treecadc8f0c9b16021338134a9c7a90478bcd8f2bdc /src/sexp/step.rs
parent0d9c5b7fd7dec374ec357581f721f5cdc828b7ae (diff)
downloadmyslip-c629fac4297b8f13bdab00100f3b05549174154e.tar.gz
myslip-c629fac4297b8f13bdab00100f3b05549174154e.zip
Added boilerplate and tests for booleans, integer comparisons and boolean operators.
Diffstat (limited to 'src/sexp/step.rs')
-rw-r--r--src/sexp/step.rs114
1 files changed, 114 insertions, 0 deletions
diff --git a/src/sexp/step.rs b/src/sexp/step.rs
index ee76ebf..bb3ada5 100644
--- a/src/sexp/step.rs
+++ b/src/sexp/step.rs
@@ -44,6 +44,7 @@ impl SExp {
/// ```
///
/// Also, addition and multiplication can take more than two arguments:
+ /// (as of 2025-08-05 not allowed by the type system, might change)
/// ```rust
/// use myslip::sexp::{SExp::*, SLeaf::*, util::*};
///
@@ -84,6 +85,119 @@ impl SExp {
///
/// ```
///
+ /// **Integer comparisons**
+ ///
+ /// ```rust
+ /// use myslip::sexp::{SExp::*, SLeaf::*, util::*};
+ ///
+ /// assert_eq!(
+ /// scons(Lt, scons(1, scons(2, Nil))).step(),
+ /// Ok(Atom(True))
+ /// );
+ /// assert_eq!(
+ /// scons(Lt, scons(2, scons(2, Nil))).step(),
+ /// Ok(Atom(False))
+ /// );
+ ///
+ /// assert_eq!(
+ /// scons(Gt, scons(2, scons(1, Nil))).step(),
+ /// Ok(Atom(True))
+ /// );
+ /// assert_eq!(
+ /// scons(Lt, scons(1, scons(1, Nil))).step(),
+ /// Ok(Atom(False))
+ /// );
+ ///
+ /// assert_eq!(
+ /// scons(Le, scons(1, scons(2, Nil))).step(),
+ /// Ok(Atom(True))
+ /// );
+ /// assert_eq!(
+ /// scons(Le, scons(2, scons(2, Nil))).step(),
+ /// Ok(Atom(True))
+ /// );
+ /// assert_eq!(
+ /// scons(Lt, scons(2, scons(1, Nil))).step(),
+ /// Ok(Atom(False))
+ /// );
+ ///
+ /// assert_eq!(
+ /// scons(Ge, scons(2, scons(1, Nil))).step(),
+ /// Ok(Atom(True))
+ /// );
+ /// assert_eq!(
+ /// scons(Ge, scons(1, scons(1, Nil))).step(),
+ /// Ok(Atom(True))
+ /// );
+ /// assert_eq!(
+ /// scons(Lt, scons(1, scons(2, Nil))).step(),
+ /// Ok(Atom(False))
+ /// );
+ ///
+ /// assert_eq!(
+ /// scons(Eq, scons(1, scons(2, Nil))).step(),
+ /// Ok(Atom(False))
+ /// );
+ /// assert_eq!(
+ /// scons(Eq, scons(2, scons(2, Nil))).step(),
+ /// Ok(Atom(True))
+ /// );
+ ///
+ /// assert_eq!(
+ /// scons(Neq, scons(1, scons(2, Nil))).step(),
+ /// Ok(Atom(True))
+ /// );
+ /// assert_eq!(
+ /// scons(Neq, scons(2, scons(2, Nil))).step(),
+ /// Ok(Atom(False))
+ /// );
+ /// ```
+ ///
+ /// **Boolean expressions**
+ ///
+ /// ```rust
+ /// use myslip::sexp::{SExp::*, SLeaf::*, util::*};
+ /// assert_eq!(
+ /// scons(And, scons(True, scons(True, Nil))).step(),
+ /// Ok(Atom(True))
+ /// );
+ /// assert_eq!(
+ /// scons(And, scons(False, scons(True, Nil))).step(),
+ /// Ok(Atom(False))
+ /// );
+ ///
+ /// assert_eq!(
+ /// scons(Or, scons(False, scons(True, Nil))).step(),
+ /// Ok(Atom(True))
+ /// );
+ /// assert_eq!(
+ /// scons(Or, scons(False, scons(False, Nil))).step(),
+ /// Ok(Atom(False))
+ /// );
+ ///
+ /// assert_eq!(
+ /// scons(Xor, scons(False, scons(True, Nil))).step(),
+ /// Ok(Atom(True))
+ /// );
+ /// assert_eq!(
+ /// scons(Xor, scons(False, scons(False, Nil))).step(),
+ /// Ok(Atom(False))
+ /// );
+ /// assert_eq!(
+ /// scons(Xor, scons(True, scons(True, Nil))).step(),
+ /// Ok(Atom(False))
+ /// );
+ ///
+ /// assert_eq!(
+ /// scons(Not, scons(True, Nil)).step(),
+ /// Ok(Atom(False))
+ /// );
+ /// assert_eq!(
+ /// scons(Not, scons(False, Nil)).step(),
+ /// Ok(Atom(True))
+ /// );
+ /// ```
+ ///
/// **Quotes**
/// If an s-expression should not be evaluated
/// as a function, but it is instead to be treated