feat(expansion) 10291 expansion
This commit is contained in:
parent
2ebf56dde7
commit
b443cd1876
4 changed files with 75 additions and 14 deletions
|
|
@ -42,7 +42,7 @@ Test(expand, single_quotes_no_expansion)
|
|||
cr_assert_str_eq((char *)command2->command->data, "echo $VAR",
|
||||
"Variable should not expand inside single quotes");
|
||||
ast_free(&ast);
|
||||
hash_map_free(vars);
|
||||
hash_map_free(&vars);
|
||||
}
|
||||
|
||||
Test(expand, single_dollar)
|
||||
|
|
@ -61,7 +61,7 @@ Test(expand, single_dollar)
|
|||
cr_assert_str_eq((char *)command2->command->data, "echo $ sign",
|
||||
"Variable should not expand inside single quotes");
|
||||
ast_free(&ast);
|
||||
hash_map_free(vars);
|
||||
hash_map_free(&vars);
|
||||
}
|
||||
|
||||
Test(expand, empty_braces_no_expansion)
|
||||
|
|
@ -78,7 +78,7 @@ Test(expand, empty_braces_no_expansion)
|
|||
struct ast_command *command2 = expand(ast_command, vars);
|
||||
cr_assert_null(command2, "Expansion should fail on empty braces");
|
||||
ast_free(&ast);
|
||||
hash_map_free(vars);
|
||||
hash_map_free(&vars);
|
||||
}
|
||||
|
||||
Test(expand, basic_expansion)
|
||||
|
|
@ -97,7 +97,7 @@ Test(expand, basic_expansion)
|
|||
cr_assert_str_eq((char *)command2->command->data, "echo expanded",
|
||||
"Variable should expand correctly");
|
||||
ast_free(&ast);
|
||||
hash_map_free(vars);
|
||||
hash_map_free(&vars);
|
||||
}
|
||||
|
||||
Test(expand, multiple_expansion)
|
||||
|
|
@ -119,7 +119,7 @@ Test(expand, multiple_expansion)
|
|||
"echo expanded values here",
|
||||
"Multiple variables should expand correctly");
|
||||
ast_free(&ast);
|
||||
hash_map_free(vars);
|
||||
hash_map_free(&vars);
|
||||
}
|
||||
|
||||
Test(expand, env_variable)
|
||||
|
|
@ -154,7 +154,7 @@ Test(expand, undefined_variable)
|
|||
cr_assert_str_eq((char *)command2->command->data, "echo ",
|
||||
"Undefined variable should expand to empty string");
|
||||
ast_free(&ast);
|
||||
hash_map_free(vars);
|
||||
hash_map_free(&vars);
|
||||
}
|
||||
|
||||
Test(expand, nested_expansion)
|
||||
|
|
@ -174,7 +174,7 @@ Test(expand, nested_expansion)
|
|||
cr_assert_str_eq((char *)command2->command->data, "echo expanded",
|
||||
"Nested variable should expand correctly");
|
||||
ast_free(&ast);
|
||||
hash_map_free(vars);
|
||||
hash_map_free(&vars);
|
||||
}
|
||||
|
||||
Test(expand, mixed_quotes_expansion)
|
||||
|
|
@ -196,7 +196,7 @@ Test(expand, mixed_quotes_expansion)
|
|||
"Variable in double quotes should expand, while variable "
|
||||
"in single quotes should not");
|
||||
ast_free(&ast);
|
||||
hash_map_free(vars);
|
||||
hash_map_free(&vars);
|
||||
}
|
||||
|
||||
Test(expand, adjacent_variables)
|
||||
|
|
@ -216,5 +216,21 @@ Test(expand, adjacent_variables)
|
|||
cr_assert_str_eq((char *)command2->command->data, "echo helloworld",
|
||||
"Adjacent variables should expand correctly");
|
||||
ast_free(&ast);
|
||||
hash_map_free(vars);
|
||||
hash_map_free(&vars);
|
||||
}
|
||||
|
||||
Test(expand, random)
|
||||
{
|
||||
char str[] = "$RANDOM";
|
||||
char *str_heap = strdup(str);
|
||||
struct list *list = list_append(NULL, str_heap);
|
||||
struct ast *ast = ast_create_command(list);
|
||||
struct ast_command *ast_command = ast_get_command(ast);
|
||||
|
||||
struct ast_command *command2 = expand(ast_command, NULL);
|
||||
cr_assert_not_null(command2, "Expansion returned NULL");
|
||||
int rnd = atoi((char *)command2->command->data);
|
||||
cr_assert(rnd >= 0 && rnd <= 32767,
|
||||
"RANDOM variable should expand to a value between 0 and 32767");
|
||||
ast_free(&ast);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue