journey-cli 0.9.11

A CLI-based journal application with automatic timestamping, vault management, and Obsidian integration
Documentation
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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
use journey::vault::Vault;
use journey::config::{VaultConfig, NoteFormat};
use journey::errors::JourneyError;
use std::collections::HashMap;
use tempfile::TempDir;
use chrono::{Local, NaiveDate, TimeZone};

fn create_test_vault() -> (Vault, TempDir) {
    let temp_dir = TempDir::new().unwrap();
    let config = VaultConfig::test_config("test", temp_dir.path().to_str().unwrap());
    (Vault::new(config), temp_dir)
}

#[test]
fn test_vault_creation() {
    let (vault, _temp_dir) = create_test_vault();
    assert_eq!(vault.config.name, "test");
    assert_eq!(vault.config.locale, "en-US");
}

#[test]
fn test_get_note_path() {
    let (vault, _temp_dir) = create_test_vault();
    let date = NaiveDate::from_ymd_opt(2025, 10, 24).unwrap();
    let path = vault.get_note_path(date);
    assert!(path.to_string_lossy().contains("2025-10-24.md"));
}

#[test]
fn test_add_note_new_file() {
    let (vault, _temp_dir) = create_test_vault();
    let date = NaiveDate::from_ymd_opt(2025, 10, 24).unwrap();
    let time = chrono::NaiveTime::from_hms_opt(14, 30, 0).unwrap();
    let timestamp = Local.from_local_datetime(&chrono::NaiveDateTime::new(date, time)).single().unwrap();
    
    vault.add_note("Test note", Some(timestamp)).unwrap();
    
    let note_path = vault.get_note_path(date);
    assert!(note_path.exists());
    
    let content = std::fs::read_to_string(&note_path).unwrap();
    assert!(content.contains("Test note"));
    assert!(content.contains("---"));
    assert!(content.contains("date: 2025-10-24"));
}

#[test]
fn test_add_note_existing_file() {
    let (vault, _temp_dir) = create_test_vault();
    let date = NaiveDate::from_ymd_opt(2025, 10, 24).unwrap();
    let time = chrono::NaiveTime::from_hms_opt(14, 30, 0).unwrap();
    let timestamp = Local.from_local_datetime(&chrono::NaiveDateTime::new(date, time)).single().unwrap();
    
    // Add first note
    vault.add_note("First note", Some(timestamp)).unwrap();
    
    // Add second note
    vault.add_note("Second note", Some(timestamp)).unwrap();
    
    let note_path = vault.get_note_path(date);
    let content = std::fs::read_to_string(&note_path).unwrap();
    
    assert!(content.contains("First note"));
    assert!(content.contains("Second note"));
    
    // Count the number of note entries
    let note_count = content.matches("- [").count();
    assert_eq!(note_count, 2);
}

#[test]
fn test_list_notes_empty() {
    let (vault, _temp_dir) = create_test_vault();
    let date = NaiveDate::from_ymd_opt(2025, 10, 24).unwrap();
    
    let notes = vault.list_notes(date).unwrap();
    assert!(notes.is_empty());
}

#[test]
fn test_list_notes_with_content() {
    let (vault, _temp_dir) = create_test_vault();
    let date = NaiveDate::from_ymd_opt(2025, 10, 24).unwrap();
    let time = chrono::NaiveTime::from_hms_opt(14, 30, 0).unwrap();
    let timestamp = Local.from_local_datetime(&chrono::NaiveDateTime::new(date, time)).single().unwrap();
    
    vault.add_note("Test note 1", Some(timestamp)).unwrap();
    vault.add_note("Test note 2", Some(timestamp)).unwrap();
    
    let notes = vault.list_notes(date).unwrap();
    assert_eq!(notes.len(), 2);
    assert!(notes[0].contains("Test note 1"));
    assert!(notes[1].contains("Test note 2"));
}

#[test]
fn test_get_editor_path() {
    let (vault, _temp_dir) = create_test_vault();
    let date = NaiveDate::from_ymd_opt(2025, 10, 24).unwrap();
    let path = vault.get_editor_path(date);
    assert!(path.to_string_lossy().contains("2025-10-24.md"));
}

#[test]
fn test_vault_with_section() {
    let temp_dir = TempDir::new().unwrap();
    let mut config = VaultConfig::test_config("test", temp_dir.path().to_str().unwrap());
    config.section_name = Some("Daily Notes".to_string());
    let vault = Vault::new(config);
    let date = NaiveDate::from_ymd_opt(2025, 10, 24).unwrap();
    let time = chrono::NaiveTime::from_hms_opt(14, 30, 0).unwrap();
    let timestamp = Local.from_local_datetime(&chrono::NaiveDateTime::new(date, time)).single().unwrap();
    
    vault.add_note("Test note with section", Some(timestamp)).unwrap();
    
    let note_path = vault.get_note_path(date);
    let content = std::fs::read_to_string(&note_path).unwrap();
    
    assert!(content.contains("# Daily Notes"));
    assert!(content.contains("Test note with section"));
}

#[test]
fn test_find_section() {
    let (vault, _temp_dir) = create_test_vault();
    
    let content = "---\ndate: 2025-10-24\n---\n\n# Daily Notes\n\n- [2025-10-24 10:00:00] Note 1\n";
    let section_start = vault.find_section(content, "Daily Notes");
    assert!(section_start.is_some());
    assert_eq!(section_start.unwrap(), 4); // Line 5 (0-indexed)
    
    let no_section = vault.find_section(content, "Non-existent Section");
    assert!(no_section.is_none());
}

#[test]
fn test_find_section_end() {
    let (vault, _temp_dir) = create_test_vault();
    
    let lines = vec![
        "# Section 1",
        "",
        "- [10:00] Note 1",
        "",
        "# Section 2",
        "",
        "- [11:00] Note 2"
    ];
    
    // Section 1 should end at line 4 (before Section 2)
    let section_end = vault.find_section_end(&lines, 0);
    assert_eq!(section_end, 4);
    
    // Section 2 should end at line 7 (end of file)
    let section_end = vault.find_section_end(&lines, 4);
    assert_eq!(section_end, 7);
}

#[test]
fn test_add_note_to_existing_section() {
    let temp_dir = TempDir::new().unwrap();
    let mut config = VaultConfig::test_config("test", temp_dir.path().to_str().unwrap());
    config.section_name = Some("Daily Notes".to_string());
    let vault = Vault::new(config);
    
    let date = NaiveDate::from_ymd_opt(2025, 10, 24).unwrap();
    
    // Create initial file with existing content
    let initial_content = "# Other Section\n\n- [09:00] Old note\n\n# Daily Notes\n\n- [10:00] First note\n\n# Another Section\n\n- [11:00] Other note";
    let note_path = vault.get_note_path(date);
    std::fs::create_dir_all(note_path.parent().unwrap()).unwrap();
    std::fs::write(&note_path, initial_content).unwrap();
    
    let time = chrono::NaiveTime::from_hms_opt(14, 30, 0).unwrap();
    let timestamp = Local.from_local_datetime(&chrono::NaiveDateTime::new(date, time)).single().unwrap();
    
    // Add a new note to the Daily Notes section
    vault.add_note("New note in section", Some(timestamp)).unwrap();
    
    let content = std::fs::read_to_string(&note_path).unwrap();
    
    // Verify the note was added to the correct section
    let lines: Vec<&str> = content.lines().collect();
    let daily_notes_start = vault.find_section(&content, "Daily Notes").unwrap();
    let daily_notes_end = vault.find_section_end(&lines, daily_notes_start);
    
    // The new note should be in the Daily Notes section (before Another Section)
    assert!(daily_notes_end < lines.len());
    assert!(content.contains("New note in section"));
    
    // Verify other sections are preserved
    assert!(content.contains("Old note"));
    assert!(content.contains("Other note"));
}

#[test]
fn test_add_note_create_missing_section() {
    let temp_dir = TempDir::new().unwrap();
    let mut config = VaultConfig::test_config("test", temp_dir.path().to_str().unwrap());
    config.section_name = Some("Daily Notes".to_string());
    let vault = Vault::new(config);
    
    let date = NaiveDate::from_ymd_opt(2025, 10, 24).unwrap();
    
    // Create initial file without the target section
    let initial_content = "# Other Section\n\n- [09:00] Old note\n\n# Another Section\n\n- [11:00] Other note";
    let note_path = vault.get_note_path(date);
    std::fs::create_dir_all(note_path.parent().unwrap()).unwrap();
    std::fs::write(&note_path, initial_content).unwrap();
    
    let time = chrono::NaiveTime::from_hms_opt(14, 30, 0).unwrap();
    let timestamp = Local.from_local_datetime(&chrono::NaiveDateTime::new(date, time)).single().unwrap();
    
    // Add a new note - should create the Daily Notes section
    vault.add_note("New note in new section", Some(timestamp)).unwrap();
    
    let content = std::fs::read_to_string(&note_path).unwrap();
    
    // Verify the section was created
    assert!(content.contains("# Daily Notes"));
    assert!(content.contains("New note in new section"));
    
    // Verify other sections are preserved
    assert!(content.contains("Old note"));
    assert!(content.contains("Other note"));
}

#[test]
fn test_add_note_to_section_new_file() {
    let temp_dir = TempDir::new().unwrap();
    let mut config = VaultConfig::test_config("test", temp_dir.path().to_str().unwrap());
    config.section_name = Some("Daily Notes".to_string());
    let vault = Vault::new(config);
    
    let date = NaiveDate::from_ymd_opt(2025, 10, 24).unwrap();
    let time = chrono::NaiveTime::from_hms_opt(14, 30, 0).unwrap();
    let timestamp = Local.from_local_datetime(&chrono::NaiveDateTime::new(date, time)).single().unwrap();
    
    // Add note to new file - should create section
    vault.add_note("First note in new file", Some(timestamp)).unwrap();
    
    let note_path = vault.get_note_path(date);
    let content = std::fs::read_to_string(&note_path).unwrap();
    
    // Verify the section was created
    assert!(content.contains("# Daily Notes"));
    assert!(content.contains("First note in new file"));
    assert!(content.contains("---"));
    assert!(content.contains("date: 2025-10-24"));
}

#[test]
fn test_add_note_with_template() {
    let temp_dir = TempDir::new().unwrap();
    
    // Create a template file
    let template_content = r#"---
date: {{date}}
time: {{time}}
---

# {{section_name}}

## Morning
{{note}}

## Afternoon
- [ ] Task 1
- [ ] Task 2

## Evening
- Reflection: 
"#;
    
    let template_path = temp_dir.path().join("template.md");
    std::fs::write(&template_path, template_content).unwrap();
    
    let mut config = VaultConfig::test_config("test", temp_dir.path().to_str().unwrap());
    config.section_name = Some("Daily Notes".to_string());
    config.template_file = Some(template_path.to_str().unwrap().to_string());
    let vault = Vault::new(config);
    
    let date = NaiveDate::from_ymd_opt(2025, 10, 24).unwrap();
    let time = chrono::NaiveTime::from_hms_opt(14, 30, 0).unwrap();
    let timestamp = Local.from_local_datetime(&chrono::NaiveDateTime::new(date, time)).single().unwrap();
    
    // Add note with template
    vault.add_note("Test note with template", Some(timestamp)).unwrap();
    
    let note_path = vault.get_note_path(date);
    let content = std::fs::read_to_string(&note_path).unwrap();
    
    // Verify template variables were replaced
    assert!(content.contains("date: 2025-10-24"));
    assert!(content.contains("time:"));
    assert!(content.contains("# Daily Notes"));
    assert!(content.contains("Test note with template"));
    assert!(content.contains("## Morning"));
    assert!(content.contains("## Afternoon"));
    assert!(content.contains("## Evening"));
}

#[test]
fn test_add_note_with_template_note_placeholder() {
    let temp_dir = TempDir::new().unwrap();
    
    // Create a template file with {{note}} placeholder
    let template_content = r#"---
date: {{date}}
---

# {{section_name}}

{{note}}

## Tasks
- [ ] Morning routine
- [ ] Work tasks
"#;
    
    let template_path = temp_dir.path().join("template.md");
    std::fs::write(&template_path, template_content).unwrap();
    
    let mut config = VaultConfig::test_config("test", temp_dir.path().to_str().unwrap());
    config.section_name = Some("Daily Notes".to_string());
    config.template_file = Some(template_path.to_str().unwrap().to_string());
    let vault = Vault::new(config);
    
    let date = NaiveDate::from_ymd_opt(2025, 10, 24).unwrap();
    let time = chrono::NaiveTime::from_hms_opt(14, 30, 0).unwrap();
    let timestamp = Local.from_local_datetime(&chrono::NaiveDateTime::new(date, time)).single().unwrap();
    
    // Add note with template
    vault.add_note("Test note in placeholder", Some(timestamp)).unwrap();
    
    let note_path = vault.get_note_path(date);
    let content = std::fs::read_to_string(&note_path).unwrap();
    
    // Verify template variables were replaced
    assert!(content.contains("date: 2025-10-24"));
    assert!(content.contains("# Daily Notes"));
    assert!(content.contains("Test note in placeholder"));
    assert!(content.contains("## Tasks"));
    assert!(content.contains("- [ ] Morning routine"));
}

#[test]
fn test_add_note_with_template_missing_file() {
    let temp_dir = TempDir::new().unwrap();
    
    let mut config = VaultConfig::test_config("test", temp_dir.path().to_str().unwrap());
    config.template_file = Some("/nonexistent/template.md".to_string());
    let vault = Vault::new(config);
    
    let date = NaiveDate::from_ymd_opt(2025, 10, 24).unwrap();
    let time = chrono::NaiveTime::from_hms_opt(14, 30, 0).unwrap();
    let timestamp = Local.from_local_datetime(&chrono::NaiveDateTime::new(date, time)).single().unwrap();
    
    // Should fail when template file doesn't exist
    let result = vault.add_note("Test note", Some(timestamp));
    assert!(result.is_err());
    
    if let Err(JourneyError::Io(io_error)) = result {
        let error_msg = format!("{}", io_error);
        assert!(error_msg.contains("Failed to read template file"));
        assert!(error_msg.contains("/nonexistent/template.md"));
    } else {
        panic!("Expected Io error");
    }
}

#[test]
fn test_add_note_with_template_different_date() {
    let temp_dir = TempDir::new().unwrap();
    
    // Create a template file
    let template_content = r#"---
date: {{date}}
time: {{time}}
datetime: {{datetime}}
---

# {{section_name}}

## Notes
{{note}}
"#;
    
    let template_path = temp_dir.path().join("template.md");
    std::fs::write(&template_path, template_content).unwrap();
    
    let mut config = VaultConfig::test_config("test", temp_dir.path().to_str().unwrap());
    config.section_name = Some("Daily Notes".to_string());
    config.template_file = Some(template_path.to_str().unwrap().to_string());
    let vault = Vault::new(config);
    
    // Add note to a specific date (not today)
    let specific_date = NaiveDate::from_ymd_opt(2025, 10, 20).unwrap();
    let specific_time = chrono::NaiveTime::from_hms_opt(14, 30, 0).unwrap();
    let specific_timestamp = chrono::Local.from_local_datetime(&chrono::NaiveDateTime::new(specific_date, specific_time)).single().unwrap();
    
    vault.add_note("Test note for specific date", Some(specific_timestamp)).unwrap();
    
    let note_path = vault.get_note_path(specific_date);
    let content = std::fs::read_to_string(&note_path).unwrap();
    
    // Verify template variables reflect the note's date/time, not current date/time
    assert!(content.contains("date: 2025-10-20"));
    assert!(content.contains("time: 14:30:00"));
    assert!(content.contains("datetime:"));
    assert!(content.contains("2025-10-20"));
    assert!(content.contains("14:30:00"));
    assert!(content.contains("# Daily Notes"));
    assert!(content.contains("Test note for specific date"));
}

#[test]
fn test_phrase_expansion() {
    let (vault, _temp_dir) = create_test_vault();
    
    // Add some phrases to the vault config
    let mut config = vault.config.clone();
    config.phrases.insert("@meeting".to_string(), "Meeting with team about project status".to_string());
    config.phrases.insert("@lunch".to_string(), "Had lunch at the usual place".to_string());
    config.phrases.insert("@work".to_string(), "Working on important tasks".to_string());
    
    let vault_with_phrases = Vault::new(config);
    
    let date = NaiveDate::from_ymd_opt(2025, 10, 24).unwrap();
    let time = chrono::NaiveTime::from_hms_opt(14, 30, 0).unwrap();
    let timestamp = Local.from_local_datetime(&chrono::NaiveDateTime::new(date, time)).single().unwrap();
    
    // Test phrase expansion
    vault_with_phrases.add_note("@meeting went well", Some(timestamp)).unwrap();
    vault_with_phrases.add_note("@lunch and then @work", Some(timestamp)).unwrap();
    let note_path = vault_with_phrases.get_note_path(date);
    let content = std::fs::read_to_string(&note_path).unwrap();
    
    // Verify phrases were expanded
    assert!(content.contains("Meeting with team about project status"));
    assert!(content.contains("Had lunch at the usual place"));
    assert!(content.contains("Working on important tasks"));
    
    // Verify original phrases are not in the content
    assert!(!content.contains("@meeting"));
    assert!(!content.contains("@lunch"));
    assert!(!content.contains("@work"));
}

#[test]
fn test_phrase_expansion_longest_first() {
    let (vault, _temp_dir) = create_test_vault();
    
    // Add phrases where one is a substring of another
    let mut config = vault.config.clone();
    config.phrases.insert("@work".to_string(), "Working".to_string());
    config.phrases.insert("@workout".to_string(), "Gym session completed".to_string());
    
    let vault_with_phrases = Vault::new(config);
    
    let date = NaiveDate::from_ymd_opt(2025, 10, 24).unwrap();
    let time = chrono::NaiveTime::from_hms_opt(14, 30, 0).unwrap();
    let timestamp = Local.from_local_datetime(&chrono::NaiveDateTime::new(date, time)).single().unwrap();
    
    // Test that longer phrase is matched first
    vault_with_phrases.add_note("Did @workout today", Some(timestamp)).unwrap();
    let note_path = vault_with_phrases.get_note_path(date);
    let content = std::fs::read_to_string(&note_path).unwrap();
    
    // Verify longer phrase was matched, not the shorter one
    assert!(content.contains("Gym session completed"));
    assert!(!content.contains("Working"));
}

#[test]
fn test_custom_file_path_format() {
    let temp_dir = TempDir::new().unwrap();
    let mut config = VaultConfig::test_config("test", temp_dir.path().to_str().unwrap());
    config.file_path_format = Some("work/{year}/{month}/{date}.md".to_string());
    let vault = Vault::new(config);
    
    let date = NaiveDate::from_ymd_opt(2025, 10, 24).unwrap();
    let note_path = vault.get_note_path(date);
    
    // Verify the path uses the custom format
    assert!(note_path.to_string_lossy().contains("work/2025/10/24.md"));
}

#[test]
fn test_custom_file_path_format_with_day() {
    let temp_dir = TempDir::new().unwrap();
    let mut config = VaultConfig::test_config("test", temp_dir.path().to_str().unwrap());
    config.file_path_format = Some("journals/{year}/{month:02}/{day:02}.md".to_string());
    let vault = Vault::new(config);
    
    let date = NaiveDate::from_ymd_opt(2025, 3, 5).unwrap();
    let note_path = vault.get_note_path(date);
    
    // Verify the path uses the custom format with zero-padded values
    assert!(note_path.to_string_lossy().contains("journals/2025/03/05.md"));
}

#[test]
fn test_custom_file_path_format_with_weekday() {
    let temp_dir = TempDir::new().unwrap();
    let mut config = VaultConfig::test_config("test", temp_dir.path().to_str().unwrap());
    config.file_path_format = Some("daily/{Weekday}/{year}-{month:02}-{date:02}.md".to_string());
    let vault = Vault::new(config);
    
    // Test with a known weekday (2025-10-24 is a Friday)
    let date = NaiveDate::from_ymd_opt(2025, 10, 24).unwrap();
    let note_path = vault.get_note_path(date);
    
    // Verify the path uses the custom format with weekday
    assert!(note_path.to_string_lossy().contains("daily/Friday/2025-10-24.md"));
}

#[test]
fn test_custom_file_path_format_with_short_weekday() {
    let temp_dir = TempDir::new().unwrap();
    let mut config = VaultConfig::test_config("test", temp_dir.path().to_str().unwrap());
    config.file_path_format = Some("notes/{Weekday_short}_{year}-{month:02}-{date:02}.md".to_string());
    let vault = Vault::new(config);
    
    // Test with a known weekday (2025-10-24 is a Friday)
    let date = NaiveDate::from_ymd_opt(2025, 10, 24).unwrap();
    let note_path = vault.get_note_path(date);
    
    // Verify the path uses the custom format with short weekday
    assert!(note_path.to_string_lossy().contains("notes/Fri_2025-10-24.md"));
}

#[test]
fn test_custom_file_path_format_case_sensitive_weekday() {
    let temp_dir = TempDir::new().unwrap();
    let mut config = VaultConfig::test_config("test", temp_dir.path().to_str().unwrap());
    config.file_path_format = Some("test_{Weekday}_{weekday}_{Weekday_short}_{weekday_short}.md".to_string());
    let vault = Vault::new(config);
    
    // Test with a known weekday (2025-10-24 is a Friday)
    let date = NaiveDate::from_ymd_opt(2025, 10, 24).unwrap();
    let note_path = vault.get_note_path(date);
    
    // Verify the path uses case-sensitive weekday formats
    assert!(note_path.to_string_lossy().contains("test_Friday_friday_Fri_fri.md"));
}

#[test]
fn test_custom_file_path_format_case_sensitive_month() {
    let temp_dir = TempDir::new().unwrap();
    let mut config = VaultConfig::test_config("test", temp_dir.path().to_str().unwrap());
    config.file_path_format = Some("test_{Month}_{month_name}_{Month_short}_{month_short}.md".to_string());
    let vault = Vault::new(config);
    
    // Test with October (month 10)
    let date = NaiveDate::from_ymd_opt(2025, 10, 24).unwrap();
    let note_path = vault.get_note_path(date);
    
    // Verify the path uses case-sensitive month formats
    assert!(note_path.to_string_lossy().contains("test_October_october_Oct_oct.md"));
}

#[test]
fn test_note_format_bullet_default() {
    let (vault, _temp_dir) = create_test_vault();
    let date = NaiveDate::from_ymd_opt(2025, 10, 24).unwrap();
    let time = chrono::NaiveTime::from_hms_opt(14, 30, 0).unwrap();
    let timestamp = Local.from_local_datetime(&chrono::NaiveDateTime::new(date, time)).single().unwrap();
    
    vault.add_note("Test bullet note", Some(timestamp)).unwrap();
    
    let note_path = vault.get_note_path(date);
    let content = std::fs::read_to_string(&note_path).unwrap();
    
    // Should use bullet format by default
    assert!(content.contains("- ["));
    assert!(content.contains("Test bullet note"));
}

#[test]
fn test_note_format_table() {
    let temp_dir = TempDir::new().unwrap();
    let mut config = VaultConfig::test_config("test", temp_dir.path().to_str().unwrap());
    config.note_format = Some(NoteFormat::Table);
    let vault = Vault::new(config);
    let date = NaiveDate::from_ymd_opt(2025, 10, 24).unwrap();
    let time = chrono::NaiveTime::from_hms_opt(14, 30, 0).unwrap();
    let timestamp = Local.from_local_datetime(&chrono::NaiveDateTime::new(date, time)).single().unwrap();
    
    vault.add_note("Test table note", Some(timestamp)).unwrap();
    
    let note_path = vault.get_note_path(date);
    let content = std::fs::read_to_string(&note_path).unwrap();
    
    // Should use table format
    assert!(content.contains("| Time | Content |"));
    assert!(content.contains("|------|----------|"));
    assert!(content.contains("|"));
    assert!(content.contains("Test table note"));
}

#[test]
fn test_note_format_conversion_bullet_to_table() {
    let temp_dir = TempDir::new().unwrap();
    
    // Create initial file with bullet format
    let initial_content = "---\ndate: 2025-10-24\n---\n\n- [10:00:00] First note\n- [11:00:00] Second note\n";
    let note_path = temp_dir.path().join("2025-10-24.md");
    std::fs::write(&note_path, initial_content).unwrap();
    
    let mut config = VaultConfig::test_config("test", temp_dir.path().to_str().unwrap());
    config.note_format = Some(NoteFormat::Table);
    let vault = Vault::new(config);
    let date = NaiveDate::from_ymd_opt(2025, 10, 24).unwrap();
    let time = chrono::NaiveTime::from_hms_opt(14, 30, 0).unwrap();
    let timestamp = Local.from_local_datetime(&chrono::NaiveDateTime::new(date, time)).single().unwrap();
    
    // Add a new note - should convert existing bullet notes to table format
    vault.add_note("Third note", Some(timestamp)).unwrap();
    
    let content = std::fs::read_to_string(&note_path).unwrap();
    
    // Should have table format
    assert!(content.contains("| Time | Content |"));
    assert!(content.contains("|------|----------|"));
    assert!(content.contains("| 10:00:00 | First note |"));
    assert!(content.contains("| 11:00:00 | Second note |"));
    assert!(content.contains("|"));
    assert!(content.contains("Third note"));
}

#[test]
fn test_note_format_conversion_table_to_bullet() {
    let temp_dir = TempDir::new().unwrap();
    
    // Create initial file with table format
    let initial_content = "---\ndate: 2025-10-24\n---\n\n| Time | Content |\n|------|----------|\n| 10:00:00 | First note |\n| 11:00:00 | Second note |\n";
    let note_path = temp_dir.path().join("2025-10-24.md");
    std::fs::write(&note_path, initial_content).unwrap();
    
    let mut config = VaultConfig::test_config("test", temp_dir.path().to_str().unwrap());
    config.note_format = Some(NoteFormat::Bullet);
    let vault = Vault::new(config);
    let date = NaiveDate::from_ymd_opt(2025, 10, 24).unwrap();
    let time = chrono::NaiveTime::from_hms_opt(14, 30, 0).unwrap();
    let timestamp = Local.from_local_datetime(&chrono::NaiveDateTime::new(date, time)).single().unwrap();
    
    // Add a new note - should convert existing table notes to bullet format
    vault.add_note("Third note", Some(timestamp)).unwrap();
    
    let content = std::fs::read_to_string(&note_path).unwrap();
    
    // Should have bullet format
    assert!(content.contains("- [10:00:00] First note"));
    assert!(content.contains("- [11:00:00] Second note"));
    assert!(content.contains("- ["));
    assert!(content.contains("Third note"));
}

#[test]
fn test_note_format_detection() {
    let (vault, _temp_dir) = create_test_vault();
    
    // Test bullet format detection
    let bullet_content = "- [10:00:00] Test note\n- [11:00:00] Another note\n";
    let detected_format = vault.detect_note_format(bullet_content);
    assert_eq!(detected_format, Some(NoteFormat::Bullet));
    
    // Test table format detection
    let table_content = "| Time | Content |\n|------|----------|\n| 10:00:00 | Test note |\n| 11:00:00 | Another note |\n";
    let detected_format = vault.detect_note_format(table_content);
    assert_eq!(detected_format, Some(NoteFormat::Table));
    
    // Test mixed format (should return None)
    let mixed_content = "- [10:00:00] Test note\n| 11:00:00 | Another note |\n";
    let detected_format = vault.detect_note_format(mixed_content);
    assert_eq!(detected_format, None);
    
    // Test no notes (should return None)
    let no_notes_content = "---\ndate: 2025-10-24\n---\n\n# Daily Notes\n\nSome other content\n";
    let detected_format = vault.detect_note_format(no_notes_content);
    assert_eq!(detected_format, None);
}

#[test]
fn test_list_notes_table_format() {
    let temp_dir = TempDir::new().unwrap();
    let mut config = VaultConfig::test_config("test", temp_dir.path().to_str().unwrap());
    config.note_format = Some(NoteFormat::Table);
    let vault = Vault::new(config);
    let date = NaiveDate::from_ymd_opt(2025, 10, 24).unwrap();
    let time = chrono::NaiveTime::from_hms_opt(14, 30, 0).unwrap();
    let timestamp = Local.from_local_datetime(&chrono::NaiveDateTime::new(date, time)).single().unwrap();
    
    vault.add_note("First table note", Some(timestamp)).unwrap();
    vault.add_note("Second table note", Some(timestamp)).unwrap();
    
    let notes = vault.list_notes(date).unwrap();
    assert_eq!(notes.len(), 2);
    
    // Notes should be in table format
    assert!(notes[0].contains("|"));
    assert!(notes[0].contains("First table note"));
    assert!(notes[1].contains("|"));
    assert!(notes[1].contains("Second table note"));
}

#[test]
fn test_note_format_with_section() {
    let temp_dir = TempDir::new().unwrap();
    let mut config = VaultConfig::test_config("test", temp_dir.path().to_str().unwrap());
    config.section_name = Some("Daily Notes".to_string());
    config.note_format = Some(NoteFormat::Table);
    let vault = Vault::new(config);
    let date = NaiveDate::from_ymd_opt(2025, 10, 24).unwrap();
    let time = chrono::NaiveTime::from_hms_opt(14, 30, 0).unwrap();
    let timestamp = Local.from_local_datetime(&chrono::NaiveDateTime::new(date, time)).single().unwrap();
    
    vault.add_note("Test note with section", Some(timestamp)).unwrap();
    
    let note_path = vault.get_note_path(date);
    let content = std::fs::read_to_string(&note_path).unwrap();
    
    // Should have section and table format
    assert!(content.contains("# Daily Notes"));
    assert!(content.contains("| Time | Content |"));
    assert!(content.contains("|------|----------|"));
    assert!(content.contains("|"));
    assert!(content.contains("Test note with section"));
}

#[test]
fn test_note_format_conversion_with_section() {
    let temp_dir = TempDir::new().unwrap();
    
    // Create initial file with bullet format in a section
    let initial_content = "---\ndate: 2025-10-24\n---\n\n# Daily Notes\n\n- [10:00:00] First note\n- [11:00:00] Second note\n\n# Other Section\n\n- [12:00:00] Other note\n";
    let note_path = temp_dir.path().join("2025-10-24.md");
    std::fs::write(&note_path, initial_content).unwrap();
    
    let mut config = VaultConfig::test_config("test", temp_dir.path().to_str().unwrap());
    config.section_name = Some("Daily Notes".to_string());
    config.note_format = Some(NoteFormat::Table);
    let vault = Vault::new(config);
    let date = NaiveDate::from_ymd_opt(2025, 10, 24).unwrap();
    let time = chrono::NaiveTime::from_hms_opt(14, 30, 0).unwrap();
    let timestamp = Local.from_local_datetime(&chrono::NaiveDateTime::new(date, time)).single().unwrap();
    
    // Add a new note - should convert only the Daily Notes section
    vault.add_note("Third note", Some(timestamp)).unwrap();
    
    let content = std::fs::read_to_string(&note_path).unwrap();
    
    // All notes should be converted to table format (global setting)
    assert!(content.contains("# Daily Notes"));
    assert!(content.contains("| 10:00:00 | First note |"));
    assert!(content.contains("| 11:00:00 | Second note |"));
    assert!(content.contains("|"));
    assert!(content.contains("Third note"));
    
    // Other section should also be converted to table format
    assert!(content.contains("# Other Section"));
    assert!(content.contains("| 12:00:00 | Other note |"));
}