-
-
Notifications
You must be signed in to change notification settings - Fork 189
/
plugin-backlink.bats
172 lines (125 loc) · 3.73 KB
/
plugin-backlink.bats
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
#!/usr/bin/env bats
load test_helper
# `backlink` ##################################################################
@test "'nb backlink' with links adds backlinks." {
if ! hash "note-link-janitor" 2>/dev/null
then
skip "note-link-janitor not installed."
fi
{
"${_NB}" init
run "${_NB}" plugins install "${NB_TEST_BASE_PATH}/../plugins/backlink.nb-plugin"
cat <<HEREDOC | "${_NB}" add 'first.md'
# one
Example content [[three]] apple pear.
HEREDOC
cat <<HEREDOC | "${_NB}" add 'second.md'
# two
Sample content [[three]] orange.
HEREDOC
cat <<HEREDOC | "${_NB}" add 'third.md'
# three
Demo content [[one]] apricot plum.
HEREDOC
[[ "${status}" == 0 ]]
}
run "${_NB}" backlink --force
printf "\${status}: '%s'\\n" "${status}"
printf "\${output}: '%s'\\n" "${output}"
cat "${NB_DIR}/home/first.md"
cat "${NB_DIR}/home/second.md"
cat "${NB_DIR}/home/third.md"
_first_content="# one
Example content [[three]] apple pear.
## Backlinks
* [[three]]
* Demo content [[one]] apricot plum.
"
_second_content="# two
Sample content [[three]] orange."
_third_content="# three
Demo content [[one]] apricot plum.
## Backlinks
* [[one]]
* Example content [[three]] apple pear.
* [[two]]
* Sample content [[three]] orange.
"
[[ "${status}" == 0 ]]
[[ "${output:-}" == "Backlinked!" ]]
diff <(cat "${NB_DIR}/home/first.md") <(echo "${_first_content}")
diff <(cat "${NB_DIR}/home/second.md") <(echo "${_second_content}")
diff <(cat "${NB_DIR}/home/third.md") <(echo "${_third_content}")
# Creates git commit
cd "${NB_DIR}/home" || return 1
while [[ -n "$(git status --porcelain)" ]]
do
sleep 1
done
git log | grep -q '\[nb\] Backlinked'
}
@test "'nb backlink' with no links does not add backlinks." {
if ! hash "note-link-janitor" 2>/dev/null
then
skip "note-link-janitor not installed."
fi
{
"${_NB}" init
run "${_NB}" plugins install "${NB_TEST_BASE_PATH}/../plugins/backlink.nb-plugin"
cat <<HEREDOC | "${_NB}" add 'first.md'
# one
Example content three apple pear.
HEREDOC
cat <<HEREDOC | "${_NB}" add 'second.md'
# two
Sample content three orange.
HEREDOC
cat <<HEREDOC | "${_NB}" add 'third.md'
# three
Demo content one apricot plum.
HEREDOC
[[ "${status}" == 0 ]]
}
run "${_NB}" backlink --force
printf "\${status}: '%s'\\n" "${status}"
printf "\${output}: '%s'\\n" "${output}"
cat "${NB_DIR}/home/first.md"
cat "${NB_DIR}/home/second.md"
cat "${NB_DIR}/home/third.md"
_first_content="# one
Example content three apple pear."
_second_content="# two
Sample content three orange."
_third_content="# three
Demo content one apricot plum."
[[ "${status}" == 0 ]]
[[ "${output:-}" == "No new links found." ]]
diff <(cat "${NB_DIR}/home/first.md") <(echo "${_first_content}")
diff <(cat "${NB_DIR}/home/second.md") <(echo "${_second_content}")
diff <(cat "${NB_DIR}/home/third.md") <(echo "${_third_content}")
# Does not create git commit
cd "${NB_DIR}/home" || return 1
if [[ -n "$(git status --porcelain)" ]]
then
sleep 1
fi
! git log | grep -q '\[nb\] Backlinked'
}
# help ########################################################################
@test "'help backlink' exits with status 0 and prints usage." {
if ! hash "note-link-janitor" 2>/dev//null
then
skip "note-link-janitor not installed."
fi
{
"${_NB}" init
run "${_NB}" plugins install "${NB_TEST_BASE_PATH}/../plugins/backlink.nb-plugin"
[[ "${status}" == 0 ]]
}
run "${_NB}" help backlink
printf "\${status}: '%s'\\n" "${status}"
printf "\${output}: '%s'\\n" "${output}"
[[ ${status} -eq 0 ]]
[[ "${lines[0]}" =~ Usage.*\: ]]
[[ "${lines[1]}" =~ nb\ backlink ]]
}