Merge pull request #298 from bucaran/master
commit
fed8c86313
@ -1,8 +0,0 @@
|
||||
# Remove item from list. List must be the name of a global variable.
|
||||
# @params <item> <list>
|
||||
function array.delete
|
||||
set -l item $argv[1]
|
||||
if set -l index (contains -i -- $item $$argv[2])
|
||||
set -e $argv[2][$index]
|
||||
end
|
||||
end
|
@ -0,0 +1,35 @@
|
||||
# NAME
|
||||
# list.erase - erase items from lists
|
||||
#
|
||||
# SYNOPSIS
|
||||
# <item> [<item>...] [--from] <list>
|
||||
# <item> [<item>...] --from <list1> [<list2>...]
|
||||
#
|
||||
# DESCRIPTION
|
||||
# Erase any number of items from any number of lists. If more than one
|
||||
# list is specified it must be separated from the items with --from.
|
||||
#
|
||||
# NOTES
|
||||
# While items are basically any valid sequence of symbols, lists refer
|
||||
# to any global variable or local variable in the scope of the calling
|
||||
# function by name.
|
||||
#
|
||||
#/
|
||||
function -S list.erase
|
||||
# List to erase from is last item by default.
|
||||
set -l items $argv[1..-2]
|
||||
set -l lists $argv[-1]
|
||||
if set -l index (contains -i -- --from $argv)
|
||||
# Everything before --from are items to erase and everything
|
||||
# after, lists to erase any found items from.
|
||||
set items $argv[1..(math $index-1)]
|
||||
set lists $argv[(math $index+1)..-1]
|
||||
end
|
||||
for item in $items
|
||||
for list in $lists
|
||||
if set -l index (contains -i -- $item $$list)
|
||||
set -e $list[1][$index]
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
@ -0,0 +1,48 @@
|
||||
function describe_list_erase
|
||||
function before_each
|
||||
set -g nums_until_10 1 2 3 4 5 6 7 8 9 10
|
||||
set -g odds_until_10 1 3 5 7 9
|
||||
end
|
||||
|
||||
function it_erases_one_element
|
||||
list.erase 1 nums_until_10
|
||||
expect $nums_until_10 to_not_include 1
|
||||
end
|
||||
|
||||
function it_erases_one_element_with_from_syntax
|
||||
list.erase 1 --from nums_until_10
|
||||
expect $nums_until_10 to_not_include 1
|
||||
end
|
||||
|
||||
function it_erases_one_element_from_multiple_lists
|
||||
list.erase 1 --from nums_until_10 odds_until_10
|
||||
expect $nums_until_10 to_not_include 1 and
|
||||
expect $odds_until_10 to_not_include 1
|
||||
end
|
||||
|
||||
function it_erases_one_element_from_multiple_lists_when_only_one_has_the_element
|
||||
list.erase 2 --from nums_until_10 odds_until_10
|
||||
expect $nums_until_10 to_not_include 2
|
||||
end
|
||||
|
||||
function it_erases_multiple_elements
|
||||
list.erase 1 2 nums_until_10
|
||||
expect $nums_until_10 to_not_include 1 and
|
||||
expect $nums_until_10 to_not_include 2
|
||||
end
|
||||
|
||||
function it_erases_multiple_elements_with_from_syntax
|
||||
list.erase 1 2 --from nums_until_10
|
||||
expect $nums_until_10 to_not_include 1 and
|
||||
expect $nums_until_10 to_not_include 2
|
||||
end
|
||||
|
||||
function it_erases_multiple_elements_from_multiple_lists
|
||||
list.erase 1 2 --from nums_until_10 odds_until_10
|
||||
expect $nums_until_10 to_not_include 1 and
|
||||
expect $nums_until_10 to_not_include 2 and
|
||||
expect $odds_until_10 to_not_include 1
|
||||
end
|
||||
end
|
||||
|
||||
import plugins/fish-spec
|
Loading…
Reference in New Issue