aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib.rs
diff options
context:
space:
mode:
authorbnewbold <bnewbold@robocracy.org>2016-09-18 15:28:11 -0700
committerbnewbold <bnewbold@robocracy.org>2016-09-18 15:28:11 -0700
commit235e1abc21b54a60913adbe1062b8ad3a0bd09d6 (patch)
treea6c876524ed9a372e5875876c41885b7f87b82fb /src/lib.rs
parentf264a289fe0d504a99c01d5787edb92af8f6ca91 (diff)
downloadmodelthing-235e1abc21b54a60913adbe1062b8ad3a0bd09d6.tar.gz
modelthing-235e1abc21b54a60913adbe1062b8ad3a0bd09d6.zip
progress and fixes for parser
Diffstat (limited to 'src/lib.rs')
-rw-r--r--src/lib.rs34
1 files changed, 32 insertions, 2 deletions
diff --git a/src/lib.rs b/src/lib.rs
index 22e9af3..8d3f928 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -3,7 +3,37 @@ pub mod modelica_parser;
pub mod modelica_ast;
#[test]
-fn parse_integer() {
- assert_eq!(&format!("{}", modelica_parser::parse_integer("+123").unwrap()),
+fn test_lexical() {
+ assert_eq!(&format!("{:?}", modelica_parser::parse_integer("+123").unwrap()),
"123");
+ assert_eq!(&format!("{:?}", modelica_parser::parse_integer("-9").unwrap()),
+ "-9");
+ assert_eq!(&format!("{:?}", modelica_parser::parse_float("-1.0e0").unwrap()),
+ "-1");
+ assert_eq!(&format!("{:?}", modelica_parser::parse_float("123.456").unwrap()),
+ "123.456");
+}
+
+#[test]
+fn test_parse() {
+ let example1 =
+r#"model MinimalModel
+ Real x;
+equation
+ x = 1;
+end MinimalModel;
+"#;
+ assert_eq!(&format!("{:?}", modelica_parser::parse_model(example1).unwrap()), example1);
+
+ let example2 =
+r#"model MinimalModel
+ parameter Real a;
+ Real b;
+equation
+ connect(a, b);
+ a = 1;
+ b = ((abs(a) + 2) / 4);
+end MinimalModel;
+"#;
+ assert_eq!(&format!("{:?}", modelica_parser::parse_model(example2).unwrap()), example2);
}