summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--Cargo.lock13
-rw-r--r--dhall/Cargo.toml1
-rw-r--r--dhall/build.rs20
-rw-r--r--dhall/src/tests.rs12
4 files changed, 45 insertions, 1 deletions
diff --git a/Cargo.lock b/Cargo.lock
index d5605ab..45ace90 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -153,6 +153,7 @@ dependencies = [
"reqwest 0.10.4 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.104 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_cbor 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "sha2 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)",
"smallvec 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
"url 2.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
"version-sync 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -1081,6 +1082,17 @@ dependencies = [
]
[[package]]
+name = "sha2"
+version = "0.8.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "block-buffer 0.7.3 (registry+https://github.com/rust-lang/crates.io-index)",
+ "digest 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)",
+ "fake-simd 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
+ "opaque-debug 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
name = "slab"
version = "0.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1571,6 +1583,7 @@ dependencies = [
"checksum serde_json 1.0.48 (registry+https://github.com/rust-lang/crates.io-index)" = "9371ade75d4c2d6cb154141b9752cf3781ec9c05e0e5cf35060e1e70ee7b9c25"
"checksum serde_urlencoded 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)" = "9ec5d77e2d4c73717816afac02670d5c4f534ea95ed430442cad02e7a6e32c97"
"checksum sha-1 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)" = "f7d94d0bede923b3cea61f3f1ff57ff8cdfd77b400fb8f9998949e0cf04163df"
+"checksum sha2 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "27044adfd2e1f077f649f59deb9490d3941d674002f7d062870a60ebe9bd47a0"
"checksum slab 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "c111b5bd5695e56cffe5129854aa230b39c93a305372fdbb2668ca2394eea9f8"
"checksum smallvec 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5c2fb2ec9bcd216a5b0d0ccf31ab17b5ed1d627960edff65bbe95d3ce221cefc"
"checksum static_assertions 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "7f3eb36b47e512f8f1c9e3d10c2c1965bc992bd9cdb024fa581e2194501c83d3"
diff --git a/dhall/Cargo.toml b/dhall/Cargo.toml
index 75d38f1..ae6665e 100644
--- a/dhall/Cargo.toml
+++ b/dhall/Cargo.toml
@@ -22,6 +22,7 @@ pest_consume = "1.0"
reqwest = { version = "0.10", features = ["blocking"] }
serde = "1.0"
serde_cbor = "0.9.0"
+sha2 = "0.8.1"
smallvec = "1.0.0"
url = "2.1"
diff --git a/dhall/build.rs b/dhall/build.rs
index 19abcc4..c79682d 100644
--- a/dhall/build.rs
+++ b/dhall/build.rs
@@ -14,6 +14,8 @@ enum FileType {
Text,
/// Dhall binary file
Binary,
+ /// Text file with hash
+ Hash,
/// Text file with expected text output
UI,
}
@@ -23,6 +25,7 @@ impl FileType {
match self {
FileType::Text => "dhall",
FileType::Binary => "dhallb",
+ FileType::Hash => "hash",
FileType::UI => "txt",
}
}
@@ -30,6 +33,7 @@ impl FileType {
match self {
FileType::Text => "TestFile::Source",
FileType::Binary => "TestFile::Binary",
+ FileType::Hash => "TestFile::Binary",
FileType::UI => "TestFile::UI",
}
}
@@ -280,6 +284,22 @@ fn generate_tests() -> std::io::Result<()> {
..default_feature.clone()
},
TestFeature {
+ module_name: "semantic_hash",
+ directory: "semantic-hash/success/",
+ variant: "SemanticHash",
+ exclude_path: Rc::new(|path: &str| {
+ false
+ // We don't support bignums
+ || path == "simple/integerToDouble"
+ // See https://github.com/pyfisch/cbor/issues/109
+ || path == "prelude/Integer/toDouble/0"
+ || path == "prelude/Integer/toDouble/1"
+ || path == "prelude/Natural/toDouble/0"
+ }),
+ output_type: Some(FileType::Hash),
+ ..default_feature.clone()
+ },
+ TestFeature {
module_name: "beta_normalize",
directory: "normalization/success/",
variant: "Normalization",
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)?;