// Copyright (C) 2025 wangyusong
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see
Bold and italic text
\n"), }, }, { Scenario: "Convert markdown with links to HTML", When: "converting markdown text with links to HTML", Then: "should return HTML with proper links", WhenDetail: whenDetail{ markdown: []byte("[Link](https://example.com)"), }, ThenExpected: thenExpected{ html: []byte("\n"), }, }, } for _, tt := range tests { t.Run(tt.Scenario, func(_ *testing.T) { // When. html, err := MarkdownToHTML(tt.WhenDetail.markdown) // Then. if tt.ThenExpected.err != "" { Expect(err).NotTo(BeNil()) Expect(err.Error()).To(ContainSubstring(tt.ThenExpected.err)) } else { Expect(err).To(BeNil()) Expect(html).To(Equal(tt.ThenExpected.html)) } }) } } func TestHTMLToMarkdown(t *testing.T) { RegisterTestingT(t) type givenDetail struct{} type whenDetail struct { html []byte } type thenExpected struct { markdown []byte err string } tests := []test.Case[givenDetail, whenDetail, thenExpected]{ { Scenario: "Convert simple HTML to markdown", When: "converting HTML text to markdown", Then: "should return correct markdown", WhenDetail: whenDetail{ html: []byte("Bold and italic text
"), }, ThenExpected: thenExpected{ markdown: []byte("**Bold** and _italic_ text"), }, }, { Scenario: "Convert HTML with links to markdown", When: "converting HTML text with links to markdown", Then: "should return markdown with proper links", WhenDetail: whenDetail{ html: []byte(""), }, ThenExpected: thenExpected{ markdown: []byte("[Link](https://example.com)"), }, }, } for _, tt := range tests { t.Run(tt.Scenario, func(_ *testing.T) { // When. markdown, err := HTMLToMarkdown(tt.WhenDetail.html) // Then. if tt.ThenExpected.err != "" { Expect(err).NotTo(BeNil()) Expect(err.Error()).To(ContainSubstring(tt.ThenExpected.err)) } else { Expect(err).To(BeNil()) Expect(markdown).To(Equal(tt.ThenExpected.markdown)) } }) } }