2018-02-13 18:11:27 -05:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
testMapEmptyList() {
|
2020-12-14 10:08:36 -05:00
|
|
|
assertEquals "" "$(list | list_map lambda x . 'echo $(($x + 1))')"
|
2018-02-13 18:11:27 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
testMapEmptyList_ifNoArgumentsInLambda() {
|
2020-12-14 10:08:36 -05:00
|
|
|
assertEquals "" "$(list | list_map lambda . 'echo 3')"
|
2018-02-13 18:11:27 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
testMapOneElementList() {
|
2020-12-14 10:08:36 -05:00
|
|
|
assertEquals "3" "$(list 2 | list_map lambda x . 'echo $(($x + 1))')"
|
2018-02-13 18:11:27 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
testMapList() {
|
2020-12-14 10:08:36 -05:00
|
|
|
assertEquals "2 3 4 5 6" "$(list {1..5} | list_map lambda x . 'echo $(($x + 1))' | unlist)"
|
2018-02-13 18:11:27 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
testMapList_ifNoArgumentsInLambda() {
|
2020-12-14 10:08:36 -05:00
|
|
|
assertEquals "9 9 9 9 9" "$(list {1..5} | list_map lambda . 'echo 9' | unlist)"
|
2018-02-13 18:11:27 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
testMapList_ifManyArgumentsInLambda() {
|
2020-12-14 10:08:36 -05:00
|
|
|
list {1..5} | list_map lambda x y . 'echo $(($x + $y))' 2> /dev/null \
|
2018-02-13 18:11:27 -05:00
|
|
|
&& fail "There should be syntax error, because map is an one argument operation"
|
|
|
|
}
|
|
|
|
|
|
|
|
testFlatMap() {
|
2020-12-14 10:08:36 -05:00
|
|
|
assertEquals "1 2 3 2 3 3" "$(list {1..3} | list_map lambda x . 'seq $x 3' | unlist)"
|
|
|
|
assertEquals "d e h l l l o o r w" "$(list hello world | list_map lambda x . 'command fold -w 1 <<< $x' | sort | unlist)"
|
2019-08-30 19:52:16 -04:00
|
|
|
}
|
|
|
|
|
2018-02-13 18:11:27 -05:00
|
|
|
. ./shunit2-init.sh
|