mirror of
https://github.com/denisidoro/navi
synced 2025-02-16 20:48:28 +00:00
parent
59362c0ec8
commit
02fc83991b
5 changed files with 26 additions and 7 deletions
|
@ -187,6 +187,9 @@ pub fn read_lines(
|
||||||
if !item.tags.is_empty() && !item.comment.is_empty() {}
|
if !item.tags.is_empty() && !item.comment.is_empty() {}
|
||||||
// blank
|
// blank
|
||||||
if line.is_empty() {
|
if line.is_empty() {
|
||||||
|
if !(&item.snippet).is_empty() {
|
||||||
|
item.snippet.push_str(writer::LINE_SEPARATOR);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// tag
|
// tag
|
||||||
else if line.starts_with('%') {
|
else if line.starts_with('%') {
|
||||||
|
|
|
@ -46,7 +46,7 @@ pub fn write(item: &Item) -> String {
|
||||||
tags = item.tags,
|
tags = item.tags,
|
||||||
comment = item.comment,
|
comment = item.comment,
|
||||||
delimiter = DELIMITER,
|
delimiter = DELIMITER,
|
||||||
snippet = &item.snippet,
|
snippet = &item.snippet.trim_end_matches(LINE_SEPARATOR),
|
||||||
file_index = item.file_index,
|
file_index = item.file_index,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,8 @@
|
||||||
|
|
||||||
source "${NAVI_HOME}/scripts/install"
|
source "${NAVI_HOME}/scripts/install"
|
||||||
|
|
||||||
|
NEWLINE_CHAR="\036"
|
||||||
|
|
||||||
PASSED=0
|
PASSED=0
|
||||||
FAILED=0
|
FAILED=0
|
||||||
SKIPPED=0
|
SKIPPED=0
|
||||||
|
@ -38,12 +40,17 @@ test::run() {
|
||||||
"$@" && test::success || test::fail
|
"$@" && test::success || test::fail
|
||||||
}
|
}
|
||||||
|
|
||||||
|
test::_escape() {
|
||||||
|
tr '\n' "$NEWLINE_CHAR" | sed -E "s/[\s$(printf "$NEWLINE_CHAR") ]+$//g"
|
||||||
|
}
|
||||||
|
|
||||||
test::equals() {
|
test::equals() {
|
||||||
local -r actual="$(cat)"
|
local -r actual="$(cat)"
|
||||||
local -r expected="$(echo "${1:-}")"
|
local -r expected="$(echo "${1:-}")"
|
||||||
|
|
||||||
local -r actual2="$(echo "$actual" | xargs | sed -E 's/\s/ /g')"
|
|
||||||
local -r expected2="$(echo "$expected" | xargs | sed -E 's/\s/ /g')"
|
local -r actual2="$(echo "$actual" | test::_escape)"
|
||||||
|
local -r expected2="$(echo "$expected" | test::_escape)"
|
||||||
|
|
||||||
if [[ "$actual2" != "$expected2" ]]; then
|
if [[ "$actual2" != "$expected2" ]]; then
|
||||||
log::error "Expected '${expected}' but got '${actual}'"
|
log::error "Expected '${expected}' but got '${actual}'"
|
||||||
|
|
|
@ -8,14 +8,23 @@ echo "foo"
|
||||||
# map -> "_foo_"
|
# map -> "_foo_"
|
||||||
echo "<map1>"
|
echo "<map1>"
|
||||||
|
|
||||||
|
# expand -> "foo"
|
||||||
|
echo "<expand1>"
|
||||||
|
|
||||||
# duplicated lines -> "foo\nlorem ipsum\nlorem ipsum\nbaz"
|
# duplicated lines -> "foo\nlorem ipsum\nlorem ipsum\nbaz"
|
||||||
echo foo
|
echo foo
|
||||||
echo lorem ipsum
|
echo lorem ipsum
|
||||||
echo lorem ipsum
|
echo lorem ipsum
|
||||||
echo baz
|
echo baz
|
||||||
|
|
||||||
# expand -> "foo"
|
# empty line -> "foo\n\n\nbar"
|
||||||
echo "<expand1>"
|
echo "$(cat <<EOF
|
||||||
|
foo
|
||||||
|
|
||||||
|
|
||||||
|
bar
|
||||||
|
EOF
|
||||||
|
)"
|
||||||
|
|
||||||
# sed with replacement -> "172.17.0.2"
|
# sed with replacement -> "172.17.0.2"
|
||||||
echo "8.8.8.8 via 172.17.0.1 dev eth0 src 172.17.0.2" | sed -E 's/.*src ([0-9.]+).*/\1/p' | head -n1
|
echo "8.8.8.8 via 172.17.0.1 dev eth0 src 172.17.0.2" | sed -E 's/.*src ([0-9.]+).*/\1/p' | head -n1
|
||||||
|
|
|
@ -36,7 +36,7 @@ _get_all_tests() {
|
||||||
cat "${TEST_CHEAT_PATH}/cases.cheat" \
|
cat "${TEST_CHEAT_PATH}/cases.cheat" \
|
||||||
| grep '^#' \
|
| grep '^#' \
|
||||||
| grep ' ->' \
|
| grep ' ->' \
|
||||||
| sed 's/\\n/ /g' \
|
| sed 's/\\n/'"$(printf "$NEWLINE_CHAR")"'/g' \
|
||||||
| sed -E 's/# (.*) -> "(.*)"/\1|\2/g'
|
| sed -E 's/# (.*) -> "(.*)"/\1|\2/g'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -144,7 +144,7 @@ IFS=$'\n'
|
||||||
for i in $(_get_tests "$filter"); do
|
for i in $(_get_tests "$filter"); do
|
||||||
IFS="$ifs"
|
IFS="$ifs"
|
||||||
query="$(echo "$i" | cut -d'|' -f1)"
|
query="$(echo "$i" | cut -d'|' -f1)"
|
||||||
expected="$(echo "$i" | cut -d'|' -f2)"
|
expected="$(echo "$i" | tr "$NEWLINE_CHAR" '\n' | cut -d'|' -f2)"
|
||||||
test::run "$query" _navi_cases_test "$query" "$expected"
|
test::run "$query" _navi_cases_test "$query" "$expected"
|
||||||
done
|
done
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue