array functions, need to validate lambda arg numb
This commit is contained in:
parent
01fcad2561
commit
fb02479108
2 changed files with 88 additions and 18 deletions
|
|
@ -17,7 +17,7 @@ class ArrayFunctions:
|
|||
for array in arrays:
|
||||
output.extend(array.value)
|
||||
|
||||
return Array(output)
|
||||
return ResolvedArray(output)
|
||||
|
||||
@staticmethod
|
||||
def array_at(array: Array, idx: Integer) -> Resolvable:
|
||||
|
|
@ -38,14 +38,14 @@ class ArrayFunctions:
|
|||
else:
|
||||
output.append(elem)
|
||||
|
||||
return Array(output)
|
||||
return ResolvedArray(output)
|
||||
|
||||
@staticmethod
|
||||
def array_reverse(array: Array) -> Array:
|
||||
"""
|
||||
Reverse an Array.
|
||||
"""
|
||||
return Array(list(reversed(array.value)))
|
||||
return ResolvedArray(list(reversed(array.value)))
|
||||
|
||||
# pylint: disable=unused-argument
|
||||
|
||||
|
|
|
|||
|
|
@ -3,18 +3,88 @@ from ytdl_sub.script.script import Script
|
|||
|
||||
class TestArrayFunctions:
|
||||
def test_array_extend(self):
|
||||
assert Script(
|
||||
{
|
||||
"array1": "{['a', 3.14]}",
|
||||
"array2": "{['b', 8.8]}",
|
||||
"array3": "{['c', 3.17]}",
|
||||
"array_extended_output": "{%array_extend(array1, array2, array3)}",
|
||||
}
|
||||
).resolve(update=True).get("array_extended_output").native == [
|
||||
"a",
|
||||
3.14,
|
||||
"b",
|
||||
8.8,
|
||||
"c",
|
||||
3.17,
|
||||
]
|
||||
output = (
|
||||
Script(
|
||||
{
|
||||
"array1": "{['a']}",
|
||||
"array2": "{['b']}",
|
||||
"array3": "{['c']}",
|
||||
"output": "{%array_extend(array1, array2, array3)}",
|
||||
}
|
||||
)
|
||||
.resolve(update=True)
|
||||
.get("output")
|
||||
.native
|
||||
)
|
||||
assert output == ["a", "b", "c"]
|
||||
|
||||
def test_array_at(self):
|
||||
output = (
|
||||
Script(
|
||||
{
|
||||
"array1": "{['a', 'b', 'c']}",
|
||||
"output": "{%array_at(array1, 1)}",
|
||||
}
|
||||
)
|
||||
.resolve(update=True)
|
||||
.get("output")
|
||||
.native
|
||||
)
|
||||
assert output == "b"
|
||||
|
||||
def test_array_flatten(self):
|
||||
output = (
|
||||
Script(
|
||||
{
|
||||
"array1": "{['a', ['b'], [['c']]]}",
|
||||
"output": "{%array_flatten(array1)}",
|
||||
}
|
||||
)
|
||||
.resolve(update=True)
|
||||
.get("output")
|
||||
.native
|
||||
)
|
||||
assert output == ["a", "b", "c"]
|
||||
|
||||
def test_array_reverse(self):
|
||||
output = (
|
||||
Script(
|
||||
{
|
||||
"array1": "{['a', 'b', 'c']}",
|
||||
"output": "{%array_reverse(array1)}",
|
||||
}
|
||||
)
|
||||
.resolve(update=True)
|
||||
.get("output")
|
||||
.native
|
||||
)
|
||||
assert output == ["c", "b", "a"]
|
||||
|
||||
def test_array_apply(self):
|
||||
output = (
|
||||
Script(
|
||||
{
|
||||
"array1": "{['a', 'b', 'c']}",
|
||||
"output": "{%array_apply(array1, %capitalize)}",
|
||||
}
|
||||
)
|
||||
.resolve(update=True)
|
||||
.get("output")
|
||||
.native
|
||||
)
|
||||
assert output == ["A", "B", "C"]
|
||||
|
||||
def test_array_enumerate(self):
|
||||
output = (
|
||||
Script(
|
||||
{
|
||||
"%enumerate_output": "{[$0, $1]}",
|
||||
"array1": "{['a', 'b', 'c']}",
|
||||
"output": "{%array_apply(array1, %enumerate_output)}",
|
||||
}
|
||||
)
|
||||
.resolve(update=True)
|
||||
.get("output")
|
||||
.native
|
||||
)
|
||||
assert output == [[0, "a"], [1, "b"], [2, "c"]]
|
||||
|
|
|
|||
Loading…
Reference in a new issue