From 76e800eb44c791316718dc57f6b4041c585fb96c Mon Sep 17 00:00:00 2001 From: Aaron Allen Date: Thu, 2 Apr 2026 19:13:45 -0500 Subject: [PATCH] refactor(cli): create shared test helper module to eliminate sample_ctx boilerplate Closes #396 --- src/cli.rs | 2 + src/cli/commands/cancel.rs | 139 ++++++++++++---------------------- src/cli/commands/finish.rs | 150 ++++++++++++++----------------------- src/cli/commands/mark.rs | 143 +++++++++++++---------------------- src/cli/commands/tag.rs | 149 ++++++++++++++---------------------- src/cli/commands/view.rs | 18 +---- src/cli/test_helpers.rs | 36 +++++++++ 7 files changed, 253 insertions(+), 384 deletions(-) create mode 100644 src/cli/test_helpers.rs diff --git a/src/cli.rs b/src/cli.rs index 0761c37..303e53c 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -4,6 +4,8 @@ pub mod editor; pub mod entry_location; pub mod interactive; pub mod pager; +#[cfg(test)] +pub mod test_helpers; pub mod title_note; use std::{ffi::OsString, io::IsTerminal, path::PathBuf}; diff --git a/src/cli/commands/cancel.rs b/src/cli/commands/cancel.rs index f8b63b5..4f35d18 100644 --- a/src/cli/commands/cancel.rs +++ b/src/cli/commands/cancel.rs @@ -169,12 +169,11 @@ impl Command { #[cfg(test)] mod test { - use std::fs; - use chrono::{Local, TimeZone}; - use doing_taskpaper::{Document, Entry, Note, Section, Tags}; + use doing_taskpaper::Tags; use super::*; + use crate::cli::test_helpers::{make_ctx_with_entries, make_ctx_with_file, make_entry}; fn default_cmd() -> Command { Command { @@ -195,95 +194,61 @@ mod test { } fn sample_ctx(dir: &std::path::Path) -> AppContext { - let path = dir.join("doing.md"); - fs::write(&path, "Currently:\n").unwrap(); - let mut doc = Document::new(); - let mut section = Section::new("Currently"); - section.add_entry(Entry::new( - Local.with_ymd_and_hms(2024, 3, 17, 14, 0, 0).unwrap(), - "Active task", - Tags::new(), - Note::new(), - "Currently", - None::, - )); - doc.add_section(section); - let mut ctx = AppContext::for_test(path); - ctx.document = doc; - ctx + make_ctx_with_entries( + dir, + vec![make_entry( + Local.with_ymd_and_hms(2024, 3, 17, 14, 0, 0).unwrap(), + "Active task", + Tags::new(), + )], + ) } fn sample_ctx_with_done(dir: &std::path::Path) -> AppContext { - let path = dir.join("doing.md"); - fs::write(&path, "Currently:\n").unwrap(); - let mut doc = Document::new(); - let mut section = Section::new("Currently"); - section.add_entry(Entry::new( - Local.with_ymd_and_hms(2024, 3, 17, 14, 0, 0).unwrap(), - "Already done", - Tags::from_iter(vec![Tag::new("done", Some("2024-03-17 15:00"))]), - Note::new(), - "Currently", - None::, - )); - doc.add_section(section); - let mut ctx = AppContext::for_test(path); - ctx.document = doc; - ctx + make_ctx_with_entries( + dir, + vec![make_entry( + Local.with_ymd_and_hms(2024, 3, 17, 14, 0, 0).unwrap(), + "Already done", + Tags::from_iter(vec![Tag::new("done", Some("2024-03-17 15:00"))]), + )], + ) } fn sample_ctx_with_multiple(dir: &std::path::Path) -> AppContext { - let path = dir.join("doing.md"); - fs::write(&path, "Currently:\n").unwrap(); - let mut doc = Document::new(); - let mut section = Section::new("Currently"); - section.add_entry(Entry::new( - Local.with_ymd_and_hms(2024, 3, 17, 13, 0, 0).unwrap(), - "First task", - Tags::new(), - Note::new(), - "Currently", - None::, - )); - section.add_entry(Entry::new( - Local.with_ymd_and_hms(2024, 3, 17, 14, 0, 0).unwrap(), - "Second task", - Tags::new(), - Note::new(), - "Currently", - None::, - )); - doc.add_section(section); - let mut ctx = AppContext::for_test(path); - ctx.document = doc; - ctx + make_ctx_with_entries( + dir, + vec![ + make_entry( + Local.with_ymd_and_hms(2024, 3, 17, 13, 0, 0).unwrap(), + "First task", + Tags::new(), + ), + make_entry( + Local.with_ymd_and_hms(2024, 3, 17, 14, 0, 0).unwrap(), + "Second task", + Tags::new(), + ), + ], + ) } fn sample_ctx_with_tagged(dir: &std::path::Path) -> AppContext { - let path = dir.join("doing.md"); - fs::write(&path, "Currently:\n").unwrap(); - let mut doc = Document::new(); - let mut section = Section::new("Currently"); - section.add_entry(Entry::new( - Local.with_ymd_and_hms(2024, 3, 17, 13, 0, 0).unwrap(), - "Project task", - Tags::from_iter(vec![Tag::new("project", None::)]), - Note::new(), - "Currently", - None::, - )); - section.add_entry(Entry::new( - Local.with_ymd_and_hms(2024, 3, 17, 14, 0, 0).unwrap(), - "Meeting task", - Tags::from_iter(vec![Tag::new("meeting", None::)]), - Note::new(), - "Currently", - None::, - )); - doc.add_section(section); - let mut ctx = AppContext::for_test(path); - ctx.document = doc; - ctx + make_ctx_with_entries( + dir, + vec![ + make_entry( + Local.with_ymd_and_hms(2024, 3, 17, 13, 0, 0).unwrap(), + "Project task", + Tags::from_iter(vec![Tag::new("project", None::)]), + ), + make_entry( + Local.with_ymd_and_hms(2024, 3, 17, 14, 0, 0).unwrap(), + "Meeting task", + Tags::from_iter(vec![Tag::new("meeting", None::)]), + ), + ], + ) } mod call { @@ -345,13 +310,7 @@ mod test { #[test] fn it_errors_on_empty_section() { let dir = tempfile::tempdir().unwrap(); - let path = dir.path().join("doing.md"); - fs::write(&path, "Currently:\n").unwrap(); - let mut ctx = { - let mut ctx = AppContext::for_test(path); - ctx.document = Document::parse("Currently:\n"); - ctx - }; + let mut ctx = make_ctx_with_file(dir.path(), "Currently:\n"); let cmd = default_cmd(); assert!(cmd.call(&mut ctx).is_err()); diff --git a/src/cli/commands/finish.rs b/src/cli/commands/finish.rs index 101177b..2f591ef 100644 --- a/src/cli/commands/finish.rs +++ b/src/cli/commands/finish.rs @@ -390,13 +390,12 @@ impl Command { #[cfg(test)] mod test { - use std::fs; - use chrono::{Local, TimeZone}; use doing_config::{Config, InteractionConfig}; - use doing_taskpaper::{Document, Note, Section, Tags}; + use doing_taskpaper::Tags; use super::*; + use crate::cli::test_helpers::{make_ctx_with_entries, make_ctx_with_file, make_entry}; fn default_cmd() -> Command { Command { @@ -435,106 +434,73 @@ mod test { } fn sample_ctx(dir: &std::path::Path) -> AppContext { - let path = dir.join("doing.md"); - fs::write(&path, "Currently:\n").unwrap(); - let mut doc = Document::new(); - let mut section = Section::new("Currently"); - section.add_entry(Entry::new( - Local.with_ymd_and_hms(2024, 3, 17, 14, 0, 0).unwrap(), - "Active task", - Tags::new(), - Note::new(), - "Currently", - None::, - )); - doc.add_section(section); - let mut ctx = AppContext::for_test(path); + let mut ctx = make_ctx_with_entries( + dir, + vec![make_entry( + Local.with_ymd_and_hms(2024, 3, 17, 14, 0, 0).unwrap(), + "Active task", + Tags::new(), + )], + ); ctx.config = test_config(); - ctx.document = doc; ctx } fn sample_ctx_with_done(dir: &std::path::Path) -> AppContext { - let path = dir.join("doing.md"); - fs::write(&path, "Currently:\n").unwrap(); - let mut doc = Document::new(); - let mut section = Section::new("Currently"); - section.add_entry(Entry::new( - Local.with_ymd_and_hms(2024, 3, 17, 14, 0, 0).unwrap(), - "Already done", - Tags::from_iter(vec![Tag::new("done", Some("2024-03-17 15:00"))]), - Note::new(), - "Currently", - None::, - )); - doc.add_section(section); - let mut ctx = AppContext::for_test(path); + let mut ctx = make_ctx_with_entries( + dir, + vec![make_entry( + Local.with_ymd_and_hms(2024, 3, 17, 14, 0, 0).unwrap(), + "Already done", + Tags::from_iter(vec![Tag::new("done", Some("2024-03-17 15:00"))]), + )], + ); ctx.config = test_config(); - ctx.document = doc; ctx } fn sample_ctx_with_multiple(dir: &std::path::Path) -> AppContext { - let path = dir.join("doing.md"); - fs::write(&path, "Currently:\n").unwrap(); - let mut doc = Document::new(); - let mut section = Section::new("Currently"); - section.add_entry(Entry::new( - Local.with_ymd_and_hms(2024, 3, 17, 13, 0, 0).unwrap(), - "First task", - Tags::new(), - Note::new(), - "Currently", - None::, - )); - section.add_entry(Entry::new( - Local.with_ymd_and_hms(2024, 3, 17, 14, 0, 0).unwrap(), - "Second task", - Tags::new(), - Note::new(), - "Currently", - None::, - )); - section.add_entry(Entry::new( - Local.with_ymd_and_hms(2024, 3, 17, 15, 0, 0).unwrap(), - "Third task", - Tags::new(), - Note::new(), - "Currently", - None::, - )); - doc.add_section(section); - let mut ctx = AppContext::for_test(path); + let mut ctx = make_ctx_with_entries( + dir, + vec![ + make_entry( + Local.with_ymd_and_hms(2024, 3, 17, 13, 0, 0).unwrap(), + "First task", + Tags::new(), + ), + make_entry( + Local.with_ymd_and_hms(2024, 3, 17, 14, 0, 0).unwrap(), + "Second task", + Tags::new(), + ), + make_entry( + Local.with_ymd_and_hms(2024, 3, 17, 15, 0, 0).unwrap(), + "Third task", + Tags::new(), + ), + ], + ); ctx.config = test_config(); - ctx.document = doc; ctx } fn sample_ctx_with_tagged(dir: &std::path::Path) -> AppContext { - let path = dir.join("doing.md"); - fs::write(&path, "Currently:\n").unwrap(); - let mut doc = Document::new(); - let mut section = Section::new("Currently"); - section.add_entry(Entry::new( - Local.with_ymd_and_hms(2024, 3, 17, 13, 0, 0).unwrap(), - "Project task", - Tags::from_iter(vec![Tag::new("project", None::)]), - Note::new(), - "Currently", - None::, - )); - section.add_entry(Entry::new( - Local.with_ymd_and_hms(2024, 3, 17, 14, 0, 0).unwrap(), - "Meeting task", - Tags::from_iter(vec![Tag::new("meeting", None::)]), - Note::new(), - "Currently", - None::, - )); - doc.add_section(section); - let mut ctx = AppContext::for_test(path); + let mut ctx = make_ctx_with_entries( + dir, + vec![ + make_entry( + Local.with_ymd_and_hms(2024, 3, 17, 13, 0, 0).unwrap(), + "Project task", + Tags::from_iter(vec![Tag::new("project", None::)]), + ), + make_entry( + Local.with_ymd_and_hms(2024, 3, 17, 14, 0, 0).unwrap(), + "Meeting task", + Tags::from_iter(vec![Tag::new("meeting", None::)]), + ), + ], + ); ctx.config = test_config(); - ctx.document = doc; ctx } @@ -563,14 +529,8 @@ mod test { #[test] fn it_errors_on_empty_section() { let dir = tempfile::tempdir().unwrap(); - let path = dir.path().join("doing.md"); - fs::write(&path, "Currently:\n").unwrap(); - let mut ctx = { - let mut ctx = AppContext::for_test(path); - ctx.config = test_config(); - ctx.document = Document::parse("Currently:\n"); - ctx - }; + let mut ctx = make_ctx_with_file(dir.path(), "Currently:\n"); + ctx.config = test_config(); let cmd = default_cmd(); assert!(cmd.call(&mut ctx).is_err()); diff --git a/src/cli/commands/mark.rs b/src/cli/commands/mark.rs index adf6264..43201ab 100644 --- a/src/cli/commands/mark.rs +++ b/src/cli/commands/mark.rs @@ -94,13 +94,14 @@ impl Command { #[cfg(test)] mod test { - use std::fs; - use chrono::{Local, TimeZone}; - use doing_taskpaper::{Document, Entry, Note, Section, Tags}; + use doing_taskpaper::Tags; use super::*; - use crate::cli::args::FilterArgs; + use crate::cli::{ + args::FilterArgs, + test_helpers::{make_ctx_with_entries, make_entry}, + }; fn default_cmd() -> Command { Command { @@ -115,95 +116,61 @@ mod test { } fn sample_ctx(dir: &std::path::Path) -> AppContext { - let path = dir.join("doing.md"); - fs::write(&path, "Currently:\n").unwrap(); - let mut doc = Document::new(); - let mut section = Section::new("Currently"); - section.add_entry(Entry::new( - Local.with_ymd_and_hms(2024, 3, 17, 14, 0, 0).unwrap(), - "Active task", - Tags::new(), - Note::new(), - "Currently", - None::, - )); - doc.add_section(section); - let mut ctx = AppContext::for_test(path); - ctx.document = doc; - ctx + make_ctx_with_entries( + dir, + vec![make_entry( + Local.with_ymd_and_hms(2024, 3, 17, 14, 0, 0).unwrap(), + "Active task", + Tags::new(), + )], + ) } fn sample_ctx_flagged(dir: &std::path::Path) -> AppContext { - let path = dir.join("doing.md"); - fs::write(&path, "Currently:\n").unwrap(); - let mut doc = Document::new(); - let mut section = Section::new("Currently"); - section.add_entry(Entry::new( - Local.with_ymd_and_hms(2024, 3, 17, 14, 0, 0).unwrap(), - "Flagged task", - Tags::from_iter(vec![Tag::new("flagged", None::)]), - Note::new(), - "Currently", - None::, - )); - doc.add_section(section); - let mut ctx = AppContext::for_test(path); - ctx.document = doc; - ctx + make_ctx_with_entries( + dir, + vec![make_entry( + Local.with_ymd_and_hms(2024, 3, 17, 14, 0, 0).unwrap(), + "Flagged task", + Tags::from_iter(vec![Tag::new("flagged", None::)]), + )], + ) } fn sample_ctx_with_done_entry(dir: &std::path::Path) -> AppContext { - let path = dir.join("doing.md"); - fs::write(&path, "Currently:\n").unwrap(); - let mut doc = Document::new(); - let mut section = Section::new("Currently"); - section.add_entry(Entry::new( - Local.with_ymd_and_hms(2024, 3, 17, 13, 0, 0).unwrap(), - "Active task", - Tags::new(), - Note::new(), - "Currently", - None::, - )); - section.add_entry(Entry::new( - Local.with_ymd_and_hms(2024, 3, 17, 14, 0, 0).unwrap(), - "Done task", - Tags::from_iter(vec![Tag::new("done", Some("2024-03-17 15:00"))]), - Note::new(), - "Currently", - None::, - )); - doc.add_section(section); - let mut ctx = AppContext::for_test(path); - ctx.document = doc; - ctx + make_ctx_with_entries( + dir, + vec![ + make_entry( + Local.with_ymd_and_hms(2024, 3, 17, 13, 0, 0).unwrap(), + "Active task", + Tags::new(), + ), + make_entry( + Local.with_ymd_and_hms(2024, 3, 17, 14, 0, 0).unwrap(), + "Done task", + Tags::from_iter(vec![Tag::new("done", Some("2024-03-17 15:00"))]), + ), + ], + ) } fn sample_ctx_with_multiple(dir: &std::path::Path) -> AppContext { - let path = dir.join("doing.md"); - fs::write(&path, "Currently:\n").unwrap(); - let mut doc = Document::new(); - let mut section = Section::new("Currently"); - section.add_entry(Entry::new( - Local.with_ymd_and_hms(2024, 3, 17, 13, 0, 0).unwrap(), - "First task", - Tags::new(), - Note::new(), - "Currently", - None::, - )); - section.add_entry(Entry::new( - Local.with_ymd_and_hms(2024, 3, 17, 14, 0, 0).unwrap(), - "Second task", - Tags::from_iter(vec![Tag::new("flagged", None::)]), - Note::new(), - "Currently", - None::, - )); - doc.add_section(section); - let mut ctx = AppContext::for_test(path); - ctx.document = doc; - ctx + make_ctx_with_entries( + dir, + vec![ + make_entry( + Local.with_ymd_and_hms(2024, 3, 17, 13, 0, 0).unwrap(), + "First task", + Tags::new(), + ), + make_entry( + Local.with_ymd_and_hms(2024, 3, 17, 14, 0, 0).unwrap(), + "Second task", + Tags::from_iter(vec![Tag::new("flagged", None::)]), + ), + ], + ) } mod call { @@ -247,13 +214,7 @@ mod test { #[test] fn it_errors_on_empty_section() { let dir = tempfile::tempdir().unwrap(); - let path = dir.path().join("doing.md"); - fs::write(&path, "Currently:\n").unwrap(); - let mut ctx = { - let mut ctx = AppContext::for_test(path); - ctx.document = Document::parse("Currently:\n"); - ctx - }; + let mut ctx = crate::cli::test_helpers::make_ctx_with_file(dir.path(), "Currently:\n"); let cmd = default_cmd(); assert!(cmd.call(&mut ctx).is_err()); diff --git a/src/cli/commands/tag.rs b/src/cli/commands/tag.rs index b6364de..1ed99c9 100644 --- a/src/cli/commands/tag.rs +++ b/src/cli/commands/tag.rs @@ -187,13 +187,14 @@ impl Command { #[cfg(test)] mod test { - use std::fs; - use chrono::{Local, TimeZone}; - use doing_taskpaper::{Document, Entry, Note, Section, Tags}; + use doing_taskpaper::Tags; use super::*; - use crate::cli::args::FilterArgs; + use crate::cli::{ + args::FilterArgs, + test_helpers::{make_ctx_with_entries, make_entry}, + }; fn default_cmd() -> Command { Command { @@ -212,98 +213,64 @@ mod test { } fn sample_ctx(dir: &std::path::Path) -> AppContext { - let path = dir.join("doing.md"); - fs::write(&path, "Currently:\n").unwrap(); - let mut doc = Document::new(); - let mut section = Section::new("Currently"); - section.add_entry(Entry::new( - Local.with_ymd_and_hms(2024, 3, 17, 14, 0, 0).unwrap(), - "Active task", - Tags::new(), - Note::new(), - "Currently", - None::, - )); - doc.add_section(section); - let mut ctx = AppContext::for_test(path); - ctx.document = doc; - ctx + make_ctx_with_entries( + dir, + vec![make_entry( + Local.with_ymd_and_hms(2024, 3, 17, 14, 0, 0).unwrap(), + "Active task", + Tags::new(), + )], + ) } fn sample_ctx_with_tags(dir: &std::path::Path) -> AppContext { - let path = dir.join("doing.md"); - fs::write(&path, "Currently:\n").unwrap(); - let mut doc = Document::new(); - let mut section = Section::new("Currently"); - section.add_entry(Entry::new( - Local.with_ymd_and_hms(2024, 3, 17, 14, 0, 0).unwrap(), - "Tagged task", - Tags::from_iter(vec![ - Tag::new("project", None::), - Tag::new("coding", None::), - ]), - Note::new(), - "Currently", - None::, - )); - doc.add_section(section); - let mut ctx = AppContext::for_test(path); - ctx.document = doc; - ctx + make_ctx_with_entries( + dir, + vec![make_entry( + Local.with_ymd_and_hms(2024, 3, 17, 14, 0, 0).unwrap(), + "Tagged task", + Tags::from_iter(vec![ + Tag::new("project", None::), + Tag::new("coding", None::), + ]), + )], + ) } fn sample_ctx_with_done_entry(dir: &std::path::Path) -> AppContext { - let path = dir.join("doing.md"); - fs::write(&path, "Currently:\n").unwrap(); - let mut doc = Document::new(); - let mut section = Section::new("Currently"); - section.add_entry(Entry::new( - Local.with_ymd_and_hms(2024, 3, 17, 13, 0, 0).unwrap(), - "Active task", - Tags::new(), - Note::new(), - "Currently", - None::, - )); - section.add_entry(Entry::new( - Local.with_ymd_and_hms(2024, 3, 17, 14, 0, 0).unwrap(), - "Done task", - Tags::from_iter(vec![Tag::new("done", Some("2024-03-17 15:00"))]), - Note::new(), - "Currently", - None::, - )); - doc.add_section(section); - let mut ctx = AppContext::for_test(path); - ctx.document = doc; - ctx + make_ctx_with_entries( + dir, + vec![ + make_entry( + Local.with_ymd_and_hms(2024, 3, 17, 13, 0, 0).unwrap(), + "Active task", + Tags::new(), + ), + make_entry( + Local.with_ymd_and_hms(2024, 3, 17, 14, 0, 0).unwrap(), + "Done task", + Tags::from_iter(vec![Tag::new("done", Some("2024-03-17 15:00"))]), + ), + ], + ) } fn sample_ctx_with_multiple(dir: &std::path::Path) -> AppContext { - let path = dir.join("doing.md"); - fs::write(&path, "Currently:\n").unwrap(); - let mut doc = Document::new(); - let mut section = Section::new("Currently"); - section.add_entry(Entry::new( - Local.with_ymd_and_hms(2024, 3, 17, 13, 0, 0).unwrap(), - "First task", - Tags::from_iter(vec![Tag::new("proj-a", None::)]), - Note::new(), - "Currently", - None::, - )); - section.add_entry(Entry::new( - Local.with_ymd_and_hms(2024, 3, 17, 14, 0, 0).unwrap(), - "Second task", - Tags::from_iter(vec![Tag::new("proj-b", None::)]), - Note::new(), - "Currently", - None::, - )); - doc.add_section(section); - let mut ctx = AppContext::for_test(path); - ctx.document = doc; - ctx + make_ctx_with_entries( + dir, + vec![ + make_entry( + Local.with_ymd_and_hms(2024, 3, 17, 13, 0, 0).unwrap(), + "First task", + Tags::from_iter(vec![Tag::new("proj-a", None::)]), + ), + make_entry( + Local.with_ymd_and_hms(2024, 3, 17, 14, 0, 0).unwrap(), + "Second task", + Tags::from_iter(vec![Tag::new("proj-b", None::)]), + ), + ], + ) } mod call { @@ -370,13 +337,7 @@ mod test { #[test] fn it_errors_on_empty_section() { let dir = tempfile::tempdir().unwrap(); - let path = dir.path().join("doing.md"); - fs::write(&path, "Currently:\n").unwrap(); - let mut ctx = { - let mut ctx = AppContext::for_test(path); - ctx.document = Document::parse("Currently:\n"); - ctx - }; + let mut ctx = crate::cli::test_helpers::make_ctx_with_file(dir.path(), "Currently:\n"); let cmd = Command { tags: vec!["coding".into()], ..default_cmd() diff --git a/src/cli/commands/view.rs b/src/cli/commands/view.rs index 9dce798..a4677e9 100644 --- a/src/cli/commands/view.rs +++ b/src/cli/commands/view.rs @@ -271,20 +271,10 @@ mod test { }, ); - AppContext { - config, - default_answer: false, - document: doc, - doing_file: std::path::PathBuf::from("/tmp/test_doing.md"), - include_notes: true, - no: false, - noauto: false, - quiet: false, - stdout: false, - use_color: false, - use_pager: false, - yes: false, - } + let mut ctx = AppContext::for_test("/tmp/test_doing.md"); + ctx.config = config; + ctx.document = doc; + ctx } mod build_filter_options { diff --git a/src/cli/test_helpers.rs b/src/cli/test_helpers.rs new file mode 100644 index 0000000..32a9fad --- /dev/null +++ b/src/cli/test_helpers.rs @@ -0,0 +1,36 @@ +use std::{fs, path::Path}; + +use chrono::{DateTime, Local}; +use doing_taskpaper::{Document, Entry, Note, Section, Tags}; + +use super::AppContext; + +/// Create an `AppContext` backed by a doing file on disk with the given entries in a "Currently" section. +pub fn make_ctx_with_entries(dir: &Path, entries: Vec) -> AppContext { + let path = dir.join("doing.md"); + fs::write(&path, "Currently:\n").unwrap(); + let mut doc = Document::new(); + let mut section = Section::new("Currently"); + for entry in entries { + section.add_entry(entry); + } + doc.add_section(section); + let mut ctx = AppContext::for_test(path); + ctx.document = doc; + ctx +} + +/// Create an `AppContext` backed by a doing file on disk with a "Currently" section containing +/// the given file content. +pub fn make_ctx_with_file(dir: &Path, content: &str) -> AppContext { + let path = dir.join("doing.md"); + fs::write(&path, content).unwrap(); + let mut ctx = AppContext::for_test(path); + ctx.document = Document::parse(content); + ctx +} + +/// Create an `Entry` in the "Currently" section with the given date, title, and tags. +pub fn make_entry(date: DateTime, title: &str, tags: Tags) -> Entry { + Entry::new(date, title, tags, Note::new(), "Currently", None::) +} -- knotmirror 0.0.1