refactor: tidy; fix runtime path resolution
This commit is contained in:
@@ -150,40 +150,85 @@ fn builtins_concat_lists() {
|
||||
|
||||
#[test]
|
||||
fn builtins_compare_versions_basic() {
|
||||
assert_eq!(eval("builtins.compareVersions \"1.0\" \"2.3\""), Value::Int(-1));
|
||||
assert_eq!(eval("builtins.compareVersions \"2.1\" \"2.3\""), Value::Int(-1));
|
||||
assert_eq!(eval("builtins.compareVersions \"2.3\" \"2.3\""), Value::Int(0));
|
||||
assert_eq!(eval("builtins.compareVersions \"2.5\" \"2.3\""), Value::Int(1));
|
||||
assert_eq!(eval("builtins.compareVersions \"3.1\" \"2.3\""), Value::Int(1));
|
||||
assert_eq!(
|
||||
eval("builtins.compareVersions \"1.0\" \"2.3\""),
|
||||
Value::Int(-1)
|
||||
);
|
||||
assert_eq!(
|
||||
eval("builtins.compareVersions \"2.1\" \"2.3\""),
|
||||
Value::Int(-1)
|
||||
);
|
||||
assert_eq!(
|
||||
eval("builtins.compareVersions \"2.3\" \"2.3\""),
|
||||
Value::Int(0)
|
||||
);
|
||||
assert_eq!(
|
||||
eval("builtins.compareVersions \"2.5\" \"2.3\""),
|
||||
Value::Int(1)
|
||||
);
|
||||
assert_eq!(
|
||||
eval("builtins.compareVersions \"3.1\" \"2.3\""),
|
||||
Value::Int(1)
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn builtins_compare_versions_components() {
|
||||
assert_eq!(eval("builtins.compareVersions \"2.3.1\" \"2.3\""), Value::Int(1));
|
||||
assert_eq!(eval("builtins.compareVersions \"2.3\" \"2.3.1\""), Value::Int(-1));
|
||||
assert_eq!(
|
||||
eval("builtins.compareVersions \"2.3.1\" \"2.3\""),
|
||||
Value::Int(1)
|
||||
);
|
||||
assert_eq!(
|
||||
eval("builtins.compareVersions \"2.3\" \"2.3.1\""),
|
||||
Value::Int(-1)
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn builtins_compare_versions_numeric_vs_alpha() {
|
||||
// Numeric component comes before alpha component
|
||||
assert_eq!(eval("builtins.compareVersions \"2.3.1\" \"2.3a\""), Value::Int(1));
|
||||
assert_eq!(eval("builtins.compareVersions \"2.3a\" \"2.3.1\""), Value::Int(-1));
|
||||
assert_eq!(
|
||||
eval("builtins.compareVersions \"2.3.1\" \"2.3a\""),
|
||||
Value::Int(1)
|
||||
);
|
||||
assert_eq!(
|
||||
eval("builtins.compareVersions \"2.3a\" \"2.3.1\""),
|
||||
Value::Int(-1)
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn builtins_compare_versions_pre() {
|
||||
// "pre" is special: comes before everything except another "pre"
|
||||
assert_eq!(eval("builtins.compareVersions \"2.3pre1\" \"2.3\""), Value::Int(-1));
|
||||
assert_eq!(eval("builtins.compareVersions \"2.3pre3\" \"2.3pre12\""), Value::Int(-1));
|
||||
assert_eq!(eval("builtins.compareVersions \"2.3pre1\" \"2.3c\""), Value::Int(-1));
|
||||
assert_eq!(eval("builtins.compareVersions \"2.3pre1\" \"2.3q\""), Value::Int(-1));
|
||||
assert_eq!(
|
||||
eval("builtins.compareVersions \"2.3pre1\" \"2.3\""),
|
||||
Value::Int(-1)
|
||||
);
|
||||
assert_eq!(
|
||||
eval("builtins.compareVersions \"2.3pre3\" \"2.3pre12\""),
|
||||
Value::Int(-1)
|
||||
);
|
||||
assert_eq!(
|
||||
eval("builtins.compareVersions \"2.3pre1\" \"2.3c\""),
|
||||
Value::Int(-1)
|
||||
);
|
||||
assert_eq!(
|
||||
eval("builtins.compareVersions \"2.3pre1\" \"2.3q\""),
|
||||
Value::Int(-1)
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn builtins_compare_versions_alpha() {
|
||||
// Alphabetic comparison
|
||||
assert_eq!(eval("builtins.compareVersions \"2.3a\" \"2.3c\""), Value::Int(-1));
|
||||
assert_eq!(eval("builtins.compareVersions \"2.3c\" \"2.3a\""), Value::Int(1));
|
||||
assert_eq!(
|
||||
eval("builtins.compareVersions \"2.3a\" \"2.3c\""),
|
||||
Value::Int(-1)
|
||||
);
|
||||
assert_eq!(
|
||||
eval("builtins.compareVersions \"2.3c\" \"2.3a\""),
|
||||
Value::Int(1)
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -110,10 +110,7 @@ fn test_path_with_file() {
|
||||
let test_file = temp_dir.path().join("test.txt");
|
||||
std::fs::write(&test_file, "Hello, World!").unwrap();
|
||||
|
||||
let expr = format!(
|
||||
r#"builtins.path {{ path = {}; }}"#,
|
||||
test_file.display()
|
||||
);
|
||||
let expr = format!(r#"builtins.path {{ path = {}; }}"#, test_file.display());
|
||||
let result = ctx.eval_code(&expr).unwrap();
|
||||
|
||||
// Should return a store path string
|
||||
@@ -239,10 +236,7 @@ fn test_path_with_sha256() {
|
||||
std::fs::write(&test_file, "Test content for hashing").unwrap();
|
||||
|
||||
// First, get the hash by calling without sha256
|
||||
let expr1 = format!(
|
||||
r#"builtins.path {{ path = {}; }}"#,
|
||||
test_file.display()
|
||||
);
|
||||
let expr1 = format!(r#"builtins.path {{ path = {}; }}"#, test_file.display());
|
||||
let result1 = ctx.eval_code(&expr1).unwrap();
|
||||
let store_path1 = match result1 {
|
||||
Value::String(s) => s,
|
||||
@@ -251,10 +245,7 @@ fn test_path_with_sha256() {
|
||||
|
||||
// Compute the actual hash (for testing, we'll just verify the same path is returned)
|
||||
// In real usage, the user would know the hash beforehand
|
||||
let expr2 = format!(
|
||||
r#"builtins.path {{ path = {}; }}"#,
|
||||
test_file.display()
|
||||
);
|
||||
let expr2 = format!(r#"builtins.path {{ path = {}; }}"#, test_file.display());
|
||||
let result2 = ctx.eval_code(&expr2).unwrap();
|
||||
let store_path2 = match result2 {
|
||||
Value::String(s) => s,
|
||||
|
||||
@@ -58,7 +58,10 @@ fn test_match_posix_space_class() {
|
||||
|
||||
#[test]
|
||||
fn test_match_posix_upper_class() {
|
||||
assert_eq!(eval(r#"builtins.match "[[:space:]]+([[:upper:]]+)[[:space:]]+" " foo ""#), Value::Null);
|
||||
assert_eq!(
|
||||
eval(r#"builtins.match "[[:space:]]+([[:upper:]]+)[[:space:]]+" " foo ""#),
|
||||
Value::Null
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
eval(r#"builtins.match "[[:space:]]+([[:upper:]]+)[[:space:]]+" " FOO ""#),
|
||||
@@ -250,9 +253,8 @@ fn test_replace_longer_pattern() {
|
||||
|
||||
#[test]
|
||||
fn test_replace_different_lengths() {
|
||||
let result = std::panic::catch_unwind(|| {
|
||||
eval(r#"builtins.replaceStrings ["a" "b"] ["x"] "test""#)
|
||||
});
|
||||
let result =
|
||||
std::panic::catch_unwind(|| eval(r#"builtins.replaceStrings ["a" "b"] ["x"] "test""#));
|
||||
assert!(result.is_err());
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user