From 0ac6a9fe83585b25b71dbb4b64c46b7482add87c Mon Sep 17 00:00:00 2001 From: "arduano@localhost" <> Date: Fri, 10 May 2024 07:43:51 +1000 Subject: [PATCH] Some minor fixes Some minor things I noticed while doing all the other stuff --- src/eval/error.rs | 4 +++- src/tests/attr_set.rs | 2 +- src/tests/mod.rs | 14 ++++++++++++-- src/tests/operators.rs | 11 +++++++++++ 4 files changed, 27 insertions(+), 4 deletions(-) diff --git a/src/eval/error.rs b/src/eval/error.rs index bc7bd1b..dfda09b 100644 --- a/src/eval/error.rs +++ b/src/eval/error.rs @@ -174,7 +174,9 @@ fn try_js_error_to_rust( } _ => { return Ok(NixError { - message: vec![NixErrorMessagePart::Plain("An error occurred.".to_owned())], + message: vec![NixErrorMessagePart::Plain( + "An unrecognized NixError occurred.".to_owned(), + )], kind: NixErrorKind::UnexpectedJsError { message: error.to_rust_string_lossy(scope), }, diff --git a/src/tests/attr_set.rs b/src/tests/attr_set.rs index 358af6f..035ba33 100644 --- a/src/tests/attr_set.rs +++ b/src/tests/attr_set.rs @@ -84,7 +84,7 @@ fn eval_attrset_non_string_attr() { fn eval_attrset_update() { assert_eq!(eval_ok("{} // {}"), Value::AttrSet(HashMap::new())); assert_eq!( - eval_ok("{a = 1; b = 2;} // {a = 3; c = 1;"), + eval_ok("{a = 1; b = 2;} // {a = 3; c = 1;}"), Value::AttrSet(HashMap::from([ ("a".to_owned(), Value::Int(3)), ("b".to_owned(), Value::Int(2)), diff --git a/src/tests/mod.rs b/src/tests/mod.rs index 9144714..5ae6b1e 100644 --- a/src/tests/mod.rs +++ b/src/tests/mod.rs @@ -2,7 +2,11 @@ #![allow(clippy::expect_fun_call)] #![allow(clippy::approx_constant)] -use crate::eval::{error::NixErrorKind, execution::evaluate, types::Value}; +use crate::eval::{ + error::NixErrorKind, + execution::evaluate, + types::{NixTypeKind, Value}, +}; mod attr_set; mod builtins; @@ -34,7 +38,13 @@ fn eval_if_then_else() { #[test] fn eval_if_then_else_invalid_type() { - assert!(evaluate("if 0 then 1 else 0").is_err()); + assert_eq!( + eval_err("if 0 then 1 else 0"), + NixErrorKind::TypeMismatch { + expected: vec![NixTypeKind::Bool], + got: NixTypeKind::Int, + } + ); } #[test] diff --git a/src/tests/operators.rs b/src/tests/operators.rs index 5a94774..45efab9 100644 --- a/src/tests/operators.rs +++ b/src/tests/operators.rs @@ -139,6 +139,17 @@ fn eval_path_string_concatenation() { #[test] fn eval_path_concat() { + let curr_dir = std::env::current_dir().unwrap(); + + assert_eq!( + eval_ok("./foo + ./bar"), + Value::Path(format!( + "{}/foo{}/bar", + curr_dir.display(), + curr_dir.display() + )) + ); + assert_eq!(eval_ok(r#"/. + "a""#), Value::Path("/a".to_owned())); assert_eq!(eval_ok(r#"/. + "./a/../b""#), Value::Path("/b".to_owned())); }