diff options
author | Nadrieril | 2020-04-05 21:34:10 +0100 |
---|---|---|
committer | Nadrieril | 2020-04-05 21:34:10 +0100 |
commit | 251b378fd8d93ea625a739cde06675e2bbc32c2c (patch) | |
tree | dbcb8175ed3477396064590db878b890973a8d10 /dhall/src | |
parent | 4290615769fc26c5e4b70843e7fbfddf6359af41 (diff) |
Add semantic-hash tests
Diffstat (limited to '')
-rw-r--r-- | dhall/src/tests.rs | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/dhall/src/tests.rs b/dhall/src/tests.rs index 2cd354f..a194c9a 100644 --- a/dhall/src/tests.rs +++ b/dhall/src/tests.rs @@ -63,6 +63,7 @@ enum Test { BinaryDecodingFailure(TestFile, TestFile), ImportSuccess(TestFile, TestFile), ImportFailure(TestFile, TestFile), + SemanticHash(TestFile, TestFile), TypeInferenceSuccess(TestFile, TestFile), TypeInferenceFailure(TestFile, TestFile), Normalization(TestFile, TestFile), @@ -132,7 +133,7 @@ impl TestFile { fn write_ui(&self, x: impl Display) -> Result<()> { match self { TestFile::UI(_) => {} - _ => panic!("Can't write an error to a non-UI file"), + _ => panic!("Can't write a ui string to a dhall file"), } let path = self.path(); create_dir_all(path.parent().unwrap())?; @@ -302,6 +303,15 @@ fn run_test(test: Test) -> Result<()> { let err = expr.resolve().unwrap_err(); expected.compare_ui(err)?; } + SemanticHash(expr, expected) => { + use sha2::Digest; + let expr = expr.normalize()?.to_expr_alpha(); + dbg!(&expr); + let expr_data = binary::encode(&expr)?; + let hash = sha2::Sha256::digest(&expr_data); + let hash = hex::encode(hash); + expected.compare_ui(format!("sha256:{}", hash))?; + } TypeInferenceSuccess(expr, expected) => { let ty = expr.typecheck()?.get_type()?; expected.compare(ty)?; |