mirror of
https://github.com/fergalmoran/picard.git
synced 2026-04-05 03:55:14 +00:00
Make $slice() 'end' parameter optional
This commit is contained in:
committed by
Philipp Wolfer
parent
a9be2c5fd7
commit
9d5597f9ff
@@ -1258,12 +1258,13 @@ Returns a multi-value variable containing the elements between the `start` and
|
||||
The following example will create a multi-value variable with all artists
|
||||
in `%artists%` except the first, which can be used to create a "feat." list.
|
||||
|
||||
Example:
|
||||
Examples:
|
||||
|
||||
$setmulti(supporting_artists,$slice(%artists%,1,))
|
||||
$setmulti(supporting_artists,$slice(%artists%,1))
|
||||
$setmulti(supporting_artists,$slice(%artists%,1,-1))
|
||||
"""
|
||||
))
|
||||
def func_slice(parser, multi, start_index, end_index, separator=MULTI_VALUED_JOINER):
|
||||
def func_slice(parser, multi, start_index, end_index=None, separator=MULTI_VALUED_JOINER):
|
||||
try:
|
||||
start = int(start_index.eval(parser)) if start_index else None
|
||||
except ValueError:
|
||||
|
||||
@@ -1354,6 +1354,7 @@ class ScriptParserTest(PicardTestCase):
|
||||
self.assertScriptResultEquals("$slice(First:A; Second:B; Third:C,-2,2)", output_1_2, context)
|
||||
# Tests with missing inputs
|
||||
self.assertScriptResultEquals("$slice(First:A; Second:B; Third:C,,1)", output_0_1, context)
|
||||
self.assertScriptResultEquals("$slice(First:A; Second:B; Third:C,1)", output_1_3, context)
|
||||
self.assertScriptResultEquals("$slice(First:A; Second:B; Third:C,1,)", output_1_3, context)
|
||||
self.assertScriptResultEquals("$slice(First:A; Second:B; Third:C,,)", output_0_3, context)
|
||||
# Tests with invalid inputs (end < start)
|
||||
@@ -1365,13 +1366,11 @@ class ScriptParserTest(PicardTestCase):
|
||||
# Tests with separator override
|
||||
self.assertScriptResultEquals("$slice(First:A; Second:B; Third:C,1,3,:)", alternate_output, context)
|
||||
# Tests with invalid number of arguments
|
||||
areg = r"^\d+:\d+:\$slice: Wrong number of arguments for \$slice: Expected between 3 and 4, "
|
||||
areg = r"^\d+:\d+:\$slice: Wrong number of arguments for \$slice: Expected between 2 and 4, "
|
||||
with self.assertRaisesRegex(ScriptError, areg):
|
||||
self.parser.eval("$slice()")
|
||||
with self.assertRaisesRegex(ScriptError, areg):
|
||||
self.parser.eval("$slice(abc; def)")
|
||||
with self.assertRaisesRegex(ScriptError, areg):
|
||||
self.parser.eval("$slice(abc; def,0)")
|
||||
with self.assertRaisesRegex(ScriptError, areg):
|
||||
self.parser.eval("$slice(abc; def),0,1,:,extra")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user