🐐 Array concat
This commit is contained in:
37
tests.py
37
tests.py
@@ -701,6 +701,9 @@ error_tests = [
|
||||
("FALSITAS AVT NVLLVS", CentvrionError), # no short-circuit: right side evaluated, NVLLVS not boolean
|
||||
("VERITAS ET NVLLVS", CentvrionError), # no short-circuit: right side evaluated, NVLLVS not boolean
|
||||
("NVLLVS ET VERITAS", CentvrionError), # NVLLVS cannot be used as boolean in ET
|
||||
('I @ [II]', CentvrionError), # @ requires two arrays (int @ array)
|
||||
('[I] @ "hello"', CentvrionError), # @ requires two arrays (array @ string)
|
||||
('"a" @ "b"', CentvrionError), # @ requires two arrays (string @ string)
|
||||
('"hello" + " world"', CentvrionError), # use & for string concatenation, not +
|
||||
("[I, II][III]", CentvrionError), # index too high
|
||||
("CVM SVBNVLLA\n[I, II][-I]", CentvrionError), # negative index
|
||||
@@ -1031,6 +1034,40 @@ class TestArithmeticEdge(unittest.TestCase):
|
||||
run_test(self, source, nodes, value)
|
||||
|
||||
|
||||
# --- Array concatenation ---
|
||||
|
||||
array_concat_tests = [
|
||||
("[I, II] @ [III, IV]",
|
||||
Program([], [ExpressionStatement(BinOp(DataArray([Numeral("I"), Numeral("II")]), DataArray([Numeral("III"), Numeral("IV")]), "SYMBOL_AT"))]),
|
||||
ValList([ValInt(1), ValInt(2), ValInt(3), ValInt(4)])),
|
||||
("[] @ [I]",
|
||||
Program([], [ExpressionStatement(BinOp(DataArray([]), DataArray([Numeral("I")]), "SYMBOL_AT"))]),
|
||||
ValList([ValInt(1)])),
|
||||
("[I] @ []",
|
||||
Program([], [ExpressionStatement(BinOp(DataArray([Numeral("I")]), DataArray([]), "SYMBOL_AT"))]),
|
||||
ValList([ValInt(1)])),
|
||||
("[] @ []",
|
||||
Program([], [ExpressionStatement(BinOp(DataArray([]), DataArray([]), "SYMBOL_AT"))]),
|
||||
ValList([])),
|
||||
('["a"] @ [I]',
|
||||
Program([], [ExpressionStatement(BinOp(DataArray([String("a")]), DataArray([Numeral("I")]), "SYMBOL_AT"))]),
|
||||
ValList([ValStr("a"), ValInt(1)])),
|
||||
# left-associative chaining
|
||||
("[I] @ [II] @ [III]",
|
||||
Program([], [ExpressionStatement(BinOp(BinOp(DataArray([Numeral("I")]), DataArray([Numeral("II")]), "SYMBOL_AT"), DataArray([Numeral("III")]), "SYMBOL_AT"))]),
|
||||
ValList([ValInt(1), ValInt(2), ValInt(3)])),
|
||||
# concat with variable
|
||||
("DESIGNA a VT [I, II]\nDESIGNA b VT [III]\na @ b",
|
||||
Program([], [Designa(ID("a"), DataArray([Numeral("I"), Numeral("II")])), Designa(ID("b"), DataArray([Numeral("III")])), ExpressionStatement(BinOp(ID("a"), ID("b"), "SYMBOL_AT"))]),
|
||||
ValList([ValInt(1), ValInt(2), ValInt(3)])),
|
||||
]
|
||||
|
||||
class TestArrayConcat(unittest.TestCase):
|
||||
@parameterized.expand(array_concat_tests)
|
||||
def test_array_concat(self, source, nodes, value):
|
||||
run_test(self, source, nodes, value)
|
||||
|
||||
|
||||
# --- String concatenation ---
|
||||
|
||||
string_concat_tests = [
|
||||
|
||||
Reference in New Issue
Block a user