mirror of
https://github.com/fish-shell/fish-shell.git
synced 2026-06-05 00:01:15 -03:00
fix stupid bug in previous commit
This fixes a stupid bug in my previous commit to standardize on a new `list_to_array_val()` function. This adds a unit test to keep this from regressing.
This commit is contained in:
@@ -1532,8 +1532,13 @@ std::unique_ptr<wcstring> list_to_array_val(const wcstring_list_t &list) {
|
||||
// Zero element arrays are internally encoded as this placeholder string.
|
||||
val->append(ENV_NULL);
|
||||
} else {
|
||||
bool need_sep = false;
|
||||
for (auto it : list) {
|
||||
if (!val->empty()) val->push_back(ARRAY_SEP);
|
||||
if (need_sep) {
|
||||
val->push_back(ARRAY_SEP);
|
||||
} else {
|
||||
need_sep = true;
|
||||
}
|
||||
val->append(it);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -948,21 +948,34 @@ static void test_list_to_array() {
|
||||
err(L"test_list_to_array failed on line %lu", __LINE__);
|
||||
}
|
||||
|
||||
list.push_back(L"abc");
|
||||
list.push_back(L"");
|
||||
val = list_to_array_val(list);
|
||||
if (*val != list[0]) {
|
||||
err(L"test_list_to_array failed on line %lu", __LINE__);
|
||||
}
|
||||
|
||||
list.push_back(L"def");
|
||||
list.push_back(L"abc");
|
||||
val = list_to_array_val(list);
|
||||
if (*val != L"abc" ARRAY_SEP_STR L"def") {
|
||||
if (*val != L"" ARRAY_SEP_STR L"abc") {
|
||||
err(L"test_list_to_array failed on line %lu", __LINE__);
|
||||
}
|
||||
|
||||
list.push_back(L"ghi");
|
||||
list.insert(list.begin(), L"ghi");
|
||||
val = list_to_array_val(list);
|
||||
if (*val != L"abc" ARRAY_SEP_STR L"def" ARRAY_SEP_STR L"ghi") {
|
||||
if (*val != L"ghi" ARRAY_SEP_STR L"" ARRAY_SEP_STR L"abc") {
|
||||
err(L"test_list_to_array failed on line %lu", __LINE__);
|
||||
}
|
||||
|
||||
list.push_back(L"");
|
||||
val = list_to_array_val(list);
|
||||
if (*val != L"ghi" ARRAY_SEP_STR L"" ARRAY_SEP_STR L"abc" ARRAY_SEP_STR L"") {
|
||||
err(L"test_list_to_array failed on line %lu", __LINE__);
|
||||
}
|
||||
|
||||
list.push_back(L"def");
|
||||
val = list_to_array_val(list);
|
||||
if (*val !=
|
||||
L"ghi" ARRAY_SEP_STR L"" ARRAY_SEP_STR L"abc" ARRAY_SEP_STR L"" ARRAY_SEP_STR L"def") {
|
||||
err(L"test_list_to_array failed on line %lu", __LINE__);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user