difftreelog
test(parser) merge new tests
in: master
3 files changed
.gitignorediffbeforeafterboth1/target1/target23.idea4.vscode25.rustfmt.tomldiffbeforeafterboth--- /dev/null
+++ b/.rustfmt.toml
@@ -0,0 +1 @@
+hard_tabs = true
crates/jsonnet-parser/src/lib.rsdiffbeforeafterboth--- a/crates/jsonnet-parser/src/lib.rs
+++ b/crates/jsonnet-parser/src/lib.rs
@@ -240,10 +240,28 @@
#[cfg(test)]
pub mod tests {
use super::{expr::*, parse};
+
+ mod expressions {
+ use super::*;
+
+ pub fn basic_math() -> Expr {
+ Expr::BinaryOp(
+ Box::new(Expr::Num(2.0)),
+ BinaryOpType::Add,
+ Box::new(Expr::BinaryOp(
+ Box::new(Expr::Num(2.0)),
+ BinaryOpType::Mul,
+ Box::new(Expr::Num(2.0)),
+ )),
+ )
+ }
+ }
+
#[test]
fn empty_object() {
- assert_eq!(parse("{}").unwrap(), Expr::Obj(ObjBody::MemberList(vec![])),);
+ assert_eq!(parse("{}").unwrap(), Expr::Obj(ObjBody::MemberList(vec![])));
}
+
#[test]
fn basic_math() {
assert_eq!(
@@ -260,6 +278,23 @@
);
}
+ #[test]
+ fn basic_math_with_indents() {
+ assert_eq!(parse("2 + 2 * 2 ").unwrap(), expressions::basic_math());
+ }
+
+ #[test]
+ fn basic_math_parened() {
+ assert_eq!(
+ parse("2+(2+2*2)").unwrap(),
+ Expr::BinaryOp(
+ Box::new(Expr::Num(2.0)),
+ BinaryOpType::Add,
+ Box::new(Expr::Parened(Box::new(expressions::basic_math()))),
+ )
+ );
+ }
+
/// Comments should not affect parsing
#[test]
fn comments() {