summaryrefslogtreecommitdiff
path: root/dhall/src/tests.rs
diff options
context:
space:
mode:
authorNadrieril2019-08-07 21:38:01 +0200
committerNadrieril2019-08-07 21:38:01 +0200
commit6654d441e5741013a8618907773ac54101e3fdf2 (patch)
tree30277f96a5e6605e3cf7040531158a8b10e5aad7 /dhall/src/tests.rs
parent51c4f79fe092191d670ffa2f9098693079dbc1be (diff)
Add binary-decode tests
Diffstat (limited to '')
-rw-r--r--dhall/src/tests.rs33
1 files changed, 32 insertions, 1 deletions
diff --git a/dhall/src/tests.rs b/dhall/src/tests.rs
index 8b32fb4..da48d15 100644
--- a/dhall/src/tests.rs
+++ b/dhall/src/tests.rs
@@ -45,6 +45,7 @@ pub enum Feature {
Parser,
Printer,
BinaryEncoding,
+ BinaryDecoding,
Import,
Normalization,
AlphaNormalization,
@@ -84,6 +85,7 @@ pub fn run_test(
Parser => "parser/",
Printer => "parser/",
BinaryEncoding => "parser/",
+ BinaryDecoding => "binary-decode/",
Import => "import/",
Normalization => "normalization/",
AlphaNormalization => "alpha-normalization/",
@@ -94,6 +96,24 @@ pub fn run_test(
"../dhall-lang/tests/".to_owned() + feature_prefix + base_path;
match status {
Success => {
+ match feature {
+ BinaryDecoding => {
+ let expr_file_path = base_path.clone() + "A.dhallb";
+ let expr_file_path = PathBuf::from(&expr_file_path);
+ let mut expr_data = Vec::new();
+ {
+ File::open(&expr_file_path)?
+ .read_to_end(&mut expr_data)?;
+ }
+ let expr = Parsed::parse_binary(&expr_data)?;
+ let expected_file_path = base_path + "B.dhall";
+ let expected = parse_file_str(&expected_file_path)?;
+ assert_eq_pretty!(expr, expected);
+
+ return Ok(());
+ }
+ _ => {}
+ }
let expr_file_path = base_path.clone() + "A.dhall";
let expr = parse_file_str(&expr_file_path)?;
@@ -164,7 +184,9 @@ pub fn run_test(
.normalize();
match feature {
- Parser | Printer | BinaryEncoding => unreachable!(),
+ Parser | Printer | BinaryEncoding | BinaryDecoding => {
+ unreachable!()
+ }
Import => {
let expr = expr.skip_typecheck().normalize();
assert_eq_display!(expr, expected);
@@ -201,6 +223,15 @@ pub fn run_test(
}
}
Printer | BinaryEncoding => unreachable!(),
+ BinaryDecoding => {
+ let expr_file_path = file_path + "b";
+ let mut expr_data = Vec::new();
+ {
+ File::open(&PathBuf::from(&expr_file_path))?
+ .read_to_end(&mut expr_data)?;
+ }
+ Parsed::parse_binary(&expr_data).unwrap_err();
+ }
Import => {
parse_file_str(&file_path)?.resolve().unwrap_err();
}