git.delta.rocks / jrsonnet / refs/commits / 078724755e3c

difftreelog

test(parser) merge new tests

Лач2020-05-29parents: #067b138 #3527065.patch.diff
in: master

3 files changed

modified.gitignorediffbeforeafterboth
1/target1/target
2
3.idea
4.vscode
25
added.rustfmt.tomldiffbeforeafterboth
--- /dev/null
+++ b/.rustfmt.toml
@@ -0,0 +1 @@
+hard_tabs = true
modifiedcrates/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() {