Welcome to mirror list, hosted at ThFree Co, Russian Federation.

50-output-17-batslib_prefix.bats « test - github.com/bats-core/bats-support.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 817fd3340cec33bc263a650fb1507756baf1ae5f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/usr/bin/env bats

load test_helper

@test 'batslib_prefix() <prefix>: prefixes each line of the input with <prefix>' {
  run bash -c "source '${TEST_MAIN_DIR}/load.bash'
               printf 'a\nb\nc\n' | batslib_prefix '_'"
  [ "$status" -eq 0 ]
  [ "${#lines[@]}" -eq 3 ]
  [ "${lines[0]}" == '_a' ]
  [ "${lines[1]}" == '_b' ]
  [ "${lines[2]}" == '_c' ]
}

@test 'batslib_prefix() <prefix>: prefixes the last line when it is not terminated by a newline' {
  run bash -c "source '${TEST_MAIN_DIR}/load.bash'
               printf 'a\nb\nc' | batslib_prefix '_'"
  [ "$status" -eq 0 ]
  [ "${#lines[@]}" -eq 3 ]
  [ "${lines[0]}" == '_a' ]
  [ "${lines[1]}" == '_b' ]
  [ "${lines[2]}" == '_c' ]
}

@test 'batslib_prefix() <prefix>: prefixes empty lines' {
  run bash -c "source '${TEST_MAIN_DIR}/load.bash'
               printf '\n\n\n' | batslib_prefix '_'"
  [ "$status" -eq 0 ]
  [ "${#lines[@]}" -eq 3 ]
  [ "${lines[0]}" == '_' ]
  [ "${lines[1]}" == '_' ]
  [ "${lines[2]}" == '_' ]
}

@test 'batslib_prefix(): <prefix> default to two spaces' {
  run bash -c "source '${TEST_MAIN_DIR}/load.bash'
               printf 'a\nb\nc\n' | batslib_prefix"
  [ "$status" -eq 0 ]
  [ "${#lines[@]}" -eq 3 ]
  [ "${lines[0]}" == '  a' ]
  [ "${lines[1]}" == '  b' ]
  [ "${lines[2]}" == '  c' ]
}