fix(expr): list items may hold commas, or be lists
Lists are stored as "[a,b]" and were split on every comma, so an item with a comma, or a list added to a list, came apart. NewList now writes a whole-list item as is (lists nest: [a,[b,c]]) and escapes \ , [ ] in any other item; GetList splits on top-level commas only and undoes the escapes. Plain lists keep their old text. The host test is no longer a known failure.
This commit is contained in:
parent
0daf0a44a3
commit
2ab70d87d2
3 changed files with 107 additions and 5 deletions
|
|
@ -53,9 +53,7 @@ internal static class ExpressionTests
|
|||
r.Add("expr: chat and echo", ChatFunctions);
|
||||
r.Add("expr: $name reads an unset variable like getvar[name]", DollarMatchesGetvar); // was a known failure; fixed by 79a39b7
|
||||
r.Add("expr: arithmetic that gives negative zero is false", NegativeZeroIsFalse); // was a known failure; fixed by 92a6318
|
||||
r.KnownFailure("expr: list items may contain commas or be lists",
|
||||
"lists are stored as \"[a,b]\" and split on every comma, so an item with a comma (or a nested list) becomes several items",
|
||||
ListItemsWithCommas);
|
||||
r.Add("expr: list items may contain commas or be lists", ListItemsWithCommas); // was a known failure
|
||||
r.Add("expr: # takes a regex pattern without backticks, as documented", RegexOperatorUnquoted); // was a known failure; fixed by c34b39c
|
||||
r.Add("expr: vitae[] reports no penalty when it cannot read vitae", VitaeWithoutHost); // was a known failure; fixed by 33f23f7
|
||||
}
|
||||
|
|
@ -914,6 +912,23 @@ internal static class ExpressionTests
|
|||
var e = Engine();
|
||||
Check.Eq(e.Evaluate("listcount[listcreate[`a,b`, c]]"), "2", "an item holding a comma");
|
||||
Check.Eq(e.Evaluate("listcount[listadd[listcreate[a], listcreate[b,c]]]"), "2", "a list added to a list");
|
||||
|
||||
// The items come back whole, and a nested list reads as a list again.
|
||||
Check.Eq(e.Evaluate("listgetitem[listcreate[`a,b`, c], 0]"), "a,b", "the comma item reads back unescaped");
|
||||
Check.Eq(e.Evaluate("listgetitem[listadd[listcreate[a], listcreate[b,c]], 1]"), "[b,c]", "the nested list reads back as a list");
|
||||
Check.Eq(e.Evaluate("listcount[listgetitem[listadd[listcreate[a], listcreate[b,c]], 1]]"), "2", "and has its own two items");
|
||||
Check.Eq(e.Evaluate("listcontains[listcreate[`a,b`, c], `a,b`]"), "1", "listcontains finds the comma item");
|
||||
Check.Eq(e.Evaluate("listindexof[listcreate[x, `a,b`], `a,b`]"), "1", "listindexof finds it at 1");
|
||||
|
||||
// Brackets and backslashes in plain text survive too; plain lists keep their old text.
|
||||
Check.Eq(e.Evaluate("listgetitem[listcreate[`x[1`, `c:\\d`], 0]"), "x[1", "an unbalanced bracket");
|
||||
Check.Eq(e.Evaluate("listgetitem[listcreate[`x[1`, `c:\\d`], 1]"), "c:\\d", "a backslash");
|
||||
Check.Eq(e.Evaluate("listcreate[a, b, c]"), "[a,b,c]", "a plain list is written as before");
|
||||
|
||||
// A nested list holding a comma item: the escape survives the nesting.
|
||||
e.Evaluate("setvar[inner, listcreate[`p,q`, r]]");
|
||||
e.Evaluate("setvar[outer, listadd[listcreate[z], getvar[inner]]]");
|
||||
Check.Eq(e.Evaluate("listgetitem[listgetitem[getvar[outer], 1], 0]"), "p,q", "two levels down");
|
||||
}
|
||||
|
||||
private static void RegexOperatorUnquoted()
|
||||
|
|
|
|||
Loading…
Reference in a new issue