forked from shellspec/shellspec
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path15.data_helper_spec.sh
85 lines (73 loc) · 1.9 KB
/
15.data_helper_spec.sh
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#shellcheck shell=sh disable=SC2016
# Data helper is easy way to input data from stdin for evaluation.
# Removes `#|` from the beginning of the each line in the Data helper,
# the rest is the input data.
Describe 'Data helper'
Example 'provide with Data helper block style'
Data
#|item1 123
#|item2 456
#|item3 789
End
When call awk '{total+=$2} END{print total}'
The output should eq 1368
End
Example 'provide string with Data helper'
Data '123 + 456 + 789'
When call bc
The output should eq 1368
End
Example 'provide from function with Data helper'
data() {
echo item1 123
echo item2 456
echo item3 789
}
Data data
When call awk '{total+=$2} END{print total}'
The output should eq 1368
End
Describe 'Data helper with filter'
Example 'from block'
Data | tr 'abc' 'ABC'
#|aaa
#|bbb
End
When call cat -
The first line of output should eq 'AAA'
The second line of output should eq 'BBB'
End
Example 'from function'
foo() { printf '%s\n' "$@"; }
Data foo a b c | tr 'abc' 'ABC' # comment
When call cat -
The first line of output should eq 'A'
The second line of output should eq 'B'
The third line of output should eq "C"
The lines of entire output should eq 3
End
Example 'from string'
Data 'abc'| tr 'abc' 'ABC' # comment
When call cat -
The output should eq ABC
End
End
Describe 'variable expansion'
Before 'item=123'
Example 'not expand variable (default)'
Data:raw
#|item $item
End
When call cat -
The output should eq 'item $item'
End
Example 'expand variable'
Data:expand
#|item $item
End
When call cat -
The output should eq 'item 123'
End
# variable expansion is supported by block style only.
End
End