package note import ( "testing" ) func TestExtractTitle(t *testing.T) { cases := []struct { name string markdown string want string }{ { name: "first h1 becomes title", markdown: "# My Note\n\nSome content", want: "My Note", }, { name: "no h1 uses filename", markdown: "## Just h2\n\nContent", want: "", // or filename from context }, { name: "multiple h1s takes first", markdown: "# First\n\n# Second", want: "First", }, { name: "h1 with formatting", markdown: "# **Bold** and *italic* title", want: "Bold and italic title", }, { name: "empty file", markdown: "", want: "", }, } for _, tt := range cases { t.Run(tt.name, func(t *testing.T) { got := ExtractTitle(tt.markdown) if got != tt.want { t.Errorf("got %q, want %q", got, tt.want) } }) } } func TestGenerateNoteID(t *testing.T) { tests := []struct { name string path string want string // SHA-256 hash }{ { name: "consistent hashing", path: "notes/test.md", want: "110bab5b8f", }, { name: "different paths different ids", path: "notes/other.md", want: "858d15849b", }, { name: "root folder as 'current folder'", path: ".", want: "cdb4ee2aea", }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { got := GenerateNoteID(tt.path) if got != tt.want { t.Errorf("got %q, want %q", got, tt.want) } // Test consistency got2 := GenerateNoteID(tt.path) if got != got2 { t.Error("same path should produce same ID") } }) } }