diff --git a/nb b/nb index 57b8c90c..e921b6e0 100755 --- a/nb +++ b/nb @@ -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}" diff --git a/test/helpers-selector-resolve-path.bats b/test/helpers-selector-resolve-path.bats index a6337b58..554e7b38 100644 --- a/test/helpers-selector-resolve-path.bats +++ b/test/helpers-selector-resolve-path.bats @@ -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" ]] +} diff --git a/test/todo-delete.bats b/test/todo-delete.bats index 64581223..15cc438a 100644 --- a/test/todo-delete.bats +++ b/test/todo-delete.bats @@ -176,3 +176,48 @@ load test_helper done git -C "${NB_DIR}/home" log | grep -v -q '\[nb\] Deleted' } + +#