From df245c316029f5b3037c14514bd3535613f26222 Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Wed, 6 Mar 2019 00:43:25 +0100 Subject: Implement normalization for some more builtins --- dhall/tests/macros.rs | 42 ++++++++++++++++++++++++++++++++++++------ dhall/tests/tests.rs | 8 ++++---- 2 files changed, 40 insertions(+), 10 deletions(-) (limited to 'dhall/tests') diff --git a/dhall/tests/macros.rs b/dhall/tests/macros.rs index 119d6d4..131683b 100644 --- a/dhall/tests/macros.rs +++ b/dhall/tests/macros.rs @@ -13,24 +13,54 @@ macro_rules! parse_str { ($str:expr) => { { let pest_expr = parser::parse_expr_pest(&$str).map_err(|e| println!("{}", e)).unwrap(); - // Check with old parser - match parser::parse_expr_lalrpop(&$str) { - Ok(larlpop_expr) => assert_eq!(pest_expr, larlpop_expr), - Err(_) => {}, - }; + // // Check with old parser + // match parser::parse_expr_lalrpop(&$str) { + // Ok(larlpop_expr) => assert_eq!(pest_expr, larlpop_expr), + // Err(_) => {}, + // }; // panic!("{:?}", pest_expr); pest_expr } }; } +#[macro_export] +macro_rules! assert_eq_ { + ($left:expr, $right:expr) => ({ + match (&$left, &$right) { + (left_val, right_val) => { + if !(*left_val == *right_val) { + panic!(r#"assertion failed: `(left == right)` + left: `{}`, + right: `{}`"#, left_val, right_val) + } + } + } + }); + ($left:expr, $right:expr,) => ({ + assert_eq!($left, $right) + }); + ($left:expr, $right:expr, $($arg:tt)+) => ({ + match (&($left), &($right)) { + (left_val, right_val) => { + if !(*left_val == *right_val) { + panic!(r#"assertion failed: `(left == right)` + left: `{:?}`, + right: `{:?}`: {}"#, left_val, right_val, + format_args!($($arg)+)) + } + } + } + }); +} + #[macro_export] macro_rules! run_spec_test { (normalization, $path:expr) => { let (expr_str, expected_str) = include_test_strs_ab!($path); let expr = parse_str!(expr_str); let expected = parse_str!(expected_str); - assert_eq!(normalize::<_, X, _>(&expr), normalize::<_, X, _>(&expected)); + assert_eq_!(normalize::<_, X, _>(&expr), normalize::<_, X, _>(&expected)); }; (parser, $path:expr) => { let expr_str = include_test_str!(concat!($path, "A")); diff --git a/dhall/tests/tests.rs b/dhall/tests/tests.rs index 8c4b42b..4da5bda 100644 --- a/dhall/tests/tests.rs +++ b/dhall/tests/tests.rs @@ -151,10 +151,10 @@ make_spec_test!(normalization, spec_normalization_success_simple_multiLine, "nor // make_spec_test!(normalization, spec_normalization_success_simple_naturalBuild, "normalization/success/simple/naturalBuild"); make_spec_test!(normalization, spec_normalization_success_simple_naturalPlus, "normalization/success/simple/naturalPlus"); make_spec_test!(normalization, spec_normalization_success_simple_naturalShow, "normalization/success/simple/naturalShow"); -// make_spec_test!(normalization, spec_normalization_success_simple_naturalToInteger, "normalization/success/simple/naturalToInteger"); -// make_spec_test!(normalization, spec_normalization_success_simple_optionalBuild, "normalization/success/simple/optionalBuild"); -// make_spec_test!(normalization, spec_normalization_success_simple_optionalBuildFold, "normalization/success/simple/optionalBuildFold"); -// make_spec_test!(normalization, spec_normalization_success_simple_optionalFold, "normalization/success/simple/optionalFold"); +make_spec_test!(normalization, spec_normalization_success_simple_naturalToInteger, "normalization/success/simple/naturalToInteger"); +make_spec_test!(normalization, spec_normalization_success_simple_optionalBuild, "normalization/success/simple/optionalBuild"); +make_spec_test!(normalization, spec_normalization_success_simple_optionalBuildFold, "normalization/success/simple/optionalBuildFold"); +make_spec_test!(normalization, spec_normalization_success_simple_optionalFold, "normalization/success/simple/optionalFold"); // make_spec_test!(normalization, spec_normalization_success_simple_sortOperator, "normalization/success/simple/sortOperator"); // make_spec_test!(normalization, spec_normalization_success_simplifications_and, "normalization/success/simplifications/and"); // make_spec_test!(normalization, spec_normalization_success_simplifications_eq, "normalization/success/simplifications/eq"); -- cgit v1.2.3