Skip to content

Commit

Permalink
chore: add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ashishb committed Aug 18, 2024
1 parent 405d428 commit caa59fb
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions src/wp2hugo/internal/hugogenerator/hugopage/hugo_page_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,56 @@ package hugopage

import (
"github.com/stretchr/testify/assert"
"net/url"
"testing"
)

const (
_sampleHTMLInput1 = `
<!-- wp:paragraph -->
<p><a href="https://example.com">Hello world</a>. "<a href="https://example.com">Example 1</a>".</p>
<!-- /wp:paragraph -->
`
_sampleMarkdownOutput1 = `[Hello world](https://example.com). "[Example 1](https://example.com)".`
)

const (
_sampleHTMLInput2 = `Unlike <a href="https://some.com/link1">his</a> <a href="https://some.com/link2">other</a>, this book`
_sampleMarkdownOutput2 = `Unlike [his](https://some.com/link1) [other](https://some.com/link2), this book`
)

const (
_sampleHTMLInput3 = `<ol><li>First item</li><li>Second item</li></ol>`
_sampleMarkdownOutput3 = "1. First item\n1. Second item"
)

func TestMarkdownExtractorWithLink1(t *testing.T) {
testMarkdownExtractor(t, _sampleHTMLInput2, _sampleMarkdownOutput2)
}

func TestMarkdownExtractorWithLink2(t *testing.T) {
// Ref:
// 1. https://github.com/ashishb/wp2hugo/issues/11
// 2. https://github.com/JohannesKaufmann/html-to-markdown/issues/95
t.Skipf("This is failing due to a bug in the underlying library. Skipping for now.")
testMarkdownExtractor(t, _sampleHTMLInput1, _sampleMarkdownOutput1)
}

func TestListExtractor(t *testing.T) {
t.Skipf("This is failing due to how the underlying library works. Skipping for now.")
testMarkdownExtractor(t, _sampleHTMLInput3, _sampleMarkdownOutput3)
}

func testMarkdownExtractor(t *testing.T, htmlInput string, markdownOutput string) {
url1, err := url.Parse("https://example.com")
assert.Nil(t, err)
page, err := NewPage(nil, *url1, "author", "Title", nil, false, nil, nil, nil, htmlInput, nil)
assert.Nil(t, err)
md, err := page.getMarkdown(nil, htmlInput, nil)
assert.Nil(t, err)
assert.Equal(t, markdownOutput, *md)
}

func TestPreTagExtractor2(t *testing.T) {
const example1 = `<pre class="lang:js decode:true">document.querySelector("video").playbackRate = 2.0; // For 2X speed-up</pre>`
const example2 = `<pre class="theme:solarized-dark lang:sh decode:true">echo "whatever"</pre>`
Expand Down

0 comments on commit caa59fb

Please sign in to comment.