#!/usr/bin/env bats load test_helper @test 'batslib_mark() : marks the -th line of the input with ' { run bash -c "source '${TEST_MAIN_DIR}/load.bash' printf ' a\n b\n c\n' | batslib_mark '>' 0" [ "$status" -eq 0 ] [ "${#lines[@]}" -eq 3 ] [ "${lines[0]}" == '>a' ] [ "${lines[1]}" == ' b' ] [ "${lines[2]}" == ' c' ] } @test 'batslib_mark() : marks multiple lines when is in ascending order' { run bash -c "source '${TEST_MAIN_DIR}/load.bash' printf ' a\n b\n c\n' | batslib_mark '>' 1 2" [ "$status" -eq 0 ] [ "${#lines[@]}" -eq 3 ] [ "${lines[0]}" == ' a' ] [ "${lines[1]}" == '>b' ] [ "${lines[2]}" == '>c' ] } @test 'batslib_mark() : marks multiple lines when is in random order' { run bash -c "source '${TEST_MAIN_DIR}/load.bash' printf ' a\n b\n c\n d\n' | batslib_mark '>' 2 1 3" [ "$status" -eq 0 ] [ "${#lines[@]}" -eq 4 ] [ "${lines[0]}" == ' a' ] [ "${lines[1]}" == '>b' ] [ "${lines[2]}" == '>c' ] [ "${lines[3]}" == '>d' ] } @test 'batslib_mark() : ignores duplicate indices' { run bash -c "source '${TEST_MAIN_DIR}/load.bash' printf ' a\n b\n c\n' | batslib_mark '>' 1 2 1" [ "$status" -eq 0 ] [ "${#lines[@]}" -eq 3 ] [ "${lines[0]}" == ' a' ] [ "${lines[1]}" == '>b' ] [ "${lines[2]}" == '>c' ] } @test 'batslib_mark() : outputs the input untouched if is the empty string' { run bash -c "source '${TEST_MAIN_DIR}/load.bash' printf ' a\n b\n c\n' | batslib_mark '' 1" [ "$status" -eq 0 ] [ "${#lines[@]}" -eq 3 ] [ "${lines[0]}" == ' a' ] [ "${lines[1]}" == ' b' ] [ "${lines[2]}" == ' c' ] } @test 'batslib_mark() : marks the last line when it is not terminated by a newline' { run bash -c "source '${TEST_MAIN_DIR}/load.bash' printf ' a\n b\n c' | batslib_mark '>' 2" [ "$status" -eq 0 ] [ "${#lines[@]}" -eq 3 ] [ "${lines[0]}" == ' a' ] [ "${lines[1]}" == ' b' ] [ "${lines[2]}" == '>c' ] } @test 'batslib_mark() : does not truncate if it is longer than the marked line' { run bash -c "source '${TEST_MAIN_DIR}/load.bash' printf '\n' | batslib_mark '>' 0" [ "$status" -eq 0 ] [ "${#lines[@]}" -eq 1 ] [ "${lines[0]}" == '>' ] }