From 98525043edd20abb62da09726d75816d09d68f1e Mon Sep 17 00:00:00 2001 From: Yash Thakur <45539777+ysthakur@users.noreply.github.com> Date: Fri, 1 Mar 2024 19:35:07 -0500 Subject: [PATCH] Fix const string interpolation test (#12038) # Description Currently, in the test for interpolating strings at parse-time, the formatted string includes `(X years ago)` (from formatting a date) (test came from https://github.com/nushell/nushell/pull/11562). I didn't realize when I was writing it that it would have to be updated every year. This PR uses regex to check the output instead. # User-Facing Changes # Tests + Formatting # After Submitting --- tests/const_/mod.rs | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/tests/const_/mod.rs b/tests/const_/mod.rs index 7cca9b5581..2f03bcdc67 100644 --- a/tests/const_/mod.rs +++ b/tests/const_/mod.rs @@ -109,16 +109,21 @@ fn const_string() { } #[test] -fn const_string_interpolation() { - let actual = nu!(r#" - const x = 2 - const s = $"var: ($x), date: (2021-02-27T13:55:40+00:00), file size: (2kb)" - $s - "#); - assert_eq!( - actual.out, - "var: 2, date: Sat, 27 Feb 2021 13:55:40 +0000 (3 years ago), file size: 2.0 KiB" - ); +fn const_string_interpolation_var() { + let actual = nu!(r#"const x = 2; const s = $"($x)"; $s"#); + assert_eq!(actual.out, "2"); +} + +#[test] +fn const_string_interpolation_date() { + let actual = nu!(r#"const s = $"(2021-02-27T13:55:40+00:00)"; $s"#); + assert!(actual.out.contains("Sat, 27 Feb 2021 13:55:40 +0000")); +} + +#[test] +fn const_string_interpolation_filesize() { + let actual = nu!(r#"const s = $"(2kb)"; $s"#); + assert_eq!(actual.out, "2.0 KiB"); } #[test]