aboutsummaryrefslogtreecommitdiffstats
path: root/modelica-parser-lalrpop/tests/parser.rs
diff options
context:
space:
mode:
Diffstat (limited to 'modelica-parser-lalrpop/tests/parser.rs')
-rw-r--r--modelica-parser-lalrpop/tests/parser.rs40
1 files changed, 40 insertions, 0 deletions
diff --git a/modelica-parser-lalrpop/tests/parser.rs b/modelica-parser-lalrpop/tests/parser.rs
new file mode 100644
index 0000000..f5f493a
--- /dev/null
+++ b/modelica-parser-lalrpop/tests/parser.rs
@@ -0,0 +1,40 @@
+
+extern crate modelica_parser;
+
+use modelica_parser::parser::{parse_integer, parse_float, parse_model};
+
+#[test]
+fn test_lexical() {
+ assert_eq!(&format!("{:?}", parse_integer("+123").unwrap()),
+ "123");
+ assert_eq!(&format!("{:?}", parse_integer("-9").unwrap()),
+ "-9");
+ assert_eq!(&format!("{:?}", parse_float("-1.0e0").unwrap()),
+ "-1");
+ assert_eq!(&format!("{:?}", 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!("{:?}", 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!("{:?}", parse_model(example2).unwrap()), example2);
+}