Skip to content

Commit

Permalink
Match todo titles in _selector_resolve_path().
Browse files Browse the repository at this point in the history
refs gh-342
  • Loading branch information
xwmx committed Oct 10, 2024
1 parent 1a70d5d commit 358999f
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 2 deletions.
10 changes: 8 additions & 2 deletions nb
Original file line number Diff line number Diff line change
Expand Up @@ -3296,8 +3296,14 @@ _selector_resolve_path() {
_get_content "${_folder_path}/${__filename}" --title
)"

if [[ -n "${_title}" ]] &&
[[ "${_title}" == "${_maybe_title}" ]]
if [[ -n "${_title}" ]] &&
{
[[ "${_title}" == "${_maybe_title}" ]] ||
{
[[ "${__filename}" =~ todo\.md$ ]] &&
[[ "${_maybe_title}" == "${_title##*] }" ]]
}
}
then
local _full_path="${_folder_path}/${__filename}"

Expand Down
48 changes: 48 additions & 0 deletions test/helpers-selector-resolve-path.bats
Original file line number Diff line number Diff line change
Expand Up @@ -191,3 +191,51 @@ load test_helper
[[ "${status}" -eq 0 ]]
[[ "${output}" == "${NB_DIR}/home/Example Folder/Example File.md" ]]
}

@test "'_selector_resolve_path()' resolves selector with first-level folder id file path and todo title." {
{
"${_NB}" init
"${_NB}" add "A Folder" --type folder
"${_NB}" add "Example Folder/A Nested Folder" --type folder

"${_NB}" add "Example Folder/Example File.md" \
--content "# Example Title"

"${_NB}" add "Example Folder/Example Todo File.todo.md" \
--content "# [ ] Example Todo Description${_NEWLINE}${_NEWLINE}Example todo content."

[[ -f "${NB_DIR}/home/Example Folder/Example File.md" ]]
[[ -f "${NB_DIR}/home/Example Folder/Example Todo File.todo.md" ]]

[[ -d "${NB_DIR}/home/A Folder" ]]
[[ -d "${NB_DIR}/home/Example Folder" ]]
[[ -d "${NB_DIR}/home/Example Folder/A Nested Folder" ]]
}

run "${_NB}" helpers selector_resolve_path "2/Example Todo Description"

printf "\${status}: '%s'\\n" "${status}"
printf "\${output}: '%s'\\n" "${output}"

echo "---"
cat "${NB_DIR}/home/Example Folder/Example Todo File.todo.md"
echo "---"
"${_NB}" helpers selector_resolve_path "Example Folder/Example Todo File.todo.md"
echo "---"
"${_NB}" helpers content "${NB_DIR}/home/Example Folder/Example Todo File.todo.md"
echo "---"
"${_NB}" helpers content "${NB_DIR}/home/Example Folder/Example Todo File.todo.md" --title
echo "---"

[[ "${status}" -eq 0 ]]
[[ "${output}" == "Example Folder/Example Todo File.todo.md" ]]


run "${_NB}" helpers selector_resolve_path "2/Example Todo Description" --full

printf "\${status}: '%s'\\n" "${status}"
printf "\${output}: '%s'\\n" "${output}"

[[ "${status}" -eq 0 ]]
[[ "${output}" == "${NB_DIR}/home/Example Folder/Example Todo File.todo.md" ]]
}
45 changes: 45 additions & 0 deletions test/todo-delete.bats
Original file line number Diff line number Diff line change
Expand Up @@ -176,3 +176,48 @@ load test_helper
done
git -C "${NB_DIR}/home" log | grep -v -q '\[nb\] Deleted'
}

# <title> #####################################################################

@test "'delete folder/<title>' deletes properly without errors." {
{
"${_NB}" init
"${_NB}" add "Sample File.todo.md" \
--content "# [ ] Sample todo description."

"${_NB}" add "Example Folder/Example File.todo.md" \
--content "# [ ] Example todo description."

[[ -e "${NB_DIR}/home/Example Folder/Example File.todo.md" ]]
}

run "${_NB}" delete "Example Folder/Example todo description." --force

printf "\${status}: '%s'\\n" "${status}"
printf "\${output}: '%s'\\n" "${output}"

# Returns status 0:

[[ ${status} -eq 0 ]]

# Deletes file:

[[ ! -e "${NB_DIR}/home/Example Folder/Example File.todo.md" ]]

# Creates git commit:

cd "${NB_DIR}/home" || return 1
while [[ -n "$(git status --porcelain)" ]]
do
sleep 1
done
git log
git log | grep -q '\[nb\] Delete: .*Example Folder/Example File.todo.md'

# Prints output:

[[ "${output}" =~ Deleted: ]]
[[ "${output}" =~ Example\ Folder/1 ]]
[[ "${output}" =~ ✔️ ]]
[[ "${output}" =~ Example\ Folder/Example\ File.todo.md ]]
}

0 comments on commit 358999f

Please sign in to comment.