Skip to content

Commit

Permalink
Improve a test case for extra div tag replacer
Browse files Browse the repository at this point in the history
  • Loading branch information
wormi4ok committed Dec 8, 2022
1 parent a44e42e commit 8019f23
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 4 deletions.
19 changes: 18 additions & 1 deletion internal/convert_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,24 @@ func TestConvert(t *testing.T) {
if !bytes.Equal(got.Content, tt.want.Content) {
dmp := diffmatchpatch.New()
diffs := dmp.DiffMain(string(tt.want.Content), string(got.Content), true)
t.Error(dmp.DiffPrettyText(diffs))
var buff bytes.Buffer
for _, diff := range diffs {
text := diff.Text

switch diff.Type {
case diffmatchpatch.DiffInsert:
_, _ = buff.WriteString("<INS>")
_, _ = buff.WriteString(text)
_, _ = buff.WriteString("</INS>")
case diffmatchpatch.DiffDelete:
_, _ = buff.WriteString("<DEL>")
_, _ = buff.WriteString(text)
_, _ = buff.WriteString("</DEL>")
case diffmatchpatch.DiffEqual:
_, _ = buff.WriteString(text)
}
}
t.Error(buff.String())
} else {
t.Errorf("Convert() = %s, want %+v", got.Media["c9e6c70ea74388346ffa16ff8edbdf58"].Content, tt.want)
}
Expand Down
2 changes: 1 addition & 1 deletion internal/testdata/evernote.html
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<p>abc <span style="background-color: rgb(255, 250, 165);-evernote-highlight:true;">highlighted text</span></p><p>Some <span style="font-style: italic">italic text</span></p><p>Some <span style="font-weight: bold">bold text</span></p></p><a href="https://petrashov.ru"></a><en-media type="image/jpeg" hash="c9e6c70ea74388346ffa16ff8edbdf58"/><en-media type="image/jpeg" hash="1sdb49hgt574388346ffa19kh3edbdf09"/><div style="box-sizing: border-box; padding: 8px; font-family: Monaco, Menlo, Consolas, &quot;Courier New&quot;, monospace; font-size: 12px; color: rgb(51, 51, 51); border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-right-radius: 4px; border-bottom-left-radius: 4px; background-color: rgb(251, 250, 248); border: 1px solid rgba(0, 0, 0, 0.14902);-en-codeblock:true;"><div> //This is a code block</div><div>    fmt.Println("hello world")</div></div><ul><li><div>First item</div></li><li><div><span>Second item</span></div></li><ul><li>Nested item</li></ul></ul><ul style=""><li><div><en-todo checked="true"/>Collect underpants</div></li><li style=""><div><en-todo checked="false"/>???</div></li><ul style=""><li style=""><div><en-todo checked="false"/>Profit</div></li></ul></ul><div><br/></div><table style="border-collapse: collapse; min-width: 100%;"><colgroup><col style="width: 130px;"/><col style="width: 130px;"/><col style="width: 130px;"/></colgroup><tbody><tr><td style="width: 130px; padding: 8px; border: 1px solid;"><div>Header 1</div></td><td style="width: 130px; padding: 8px; border: 1px solid;"><div>Middle column</div></td><td style="width: 130px; padding: 8px; border: 1px solid;"><div>Last column title</div></td></tr><tr><td style="width: 130px; padding: 8px; border: 1px solid;"><div>Short text</div></td><td style="width: 130px; padding: 8px; border: 1px solid;"><div>Verylongunbreakabletext</div></td><td style="width: 130px; padding: 8px; border: 1px solid;"><div>Something here</div></td></tr><tr><td style="width: 130px; padding: 8px; border: 1px solid;"><div>Half empty row</div></td><td style="width: 130px; padding: 8px; border: 1px solid;"><div><br/></div></td><td style="width: 130px; padding: 8px; border: 1px solid;"><div><br/></div></td></tr></tbody></table><div style="-en-codeblock:true"><div style="-en-codeblock:true"></div></div>
<p>abc <span style="background-color: rgb(255, 250, 165);-evernote-highlight:true;">highlighted text</span></p><p>Some <span style="font-style: italic">italic text</span></p><p>Some <span style="font-weight: bold">bold text</span></p></p><a href="https://petrashov.ru"></a><en-media type="image/jpeg" hash="c9e6c70ea74388346ffa16ff8edbdf58"/><en-media type="image/jpeg" hash="1sdb49hgt574388346ffa19kh3edbdf09"/><div style="box-sizing: border-box; padding: 8px; font-family: Monaco, Menlo, Consolas, &quot;Courier New&quot;, monospace; font-size: 12px; color: rgb(51, 51, 51); border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-right-radius: 4px; border-bottom-left-radius: 4px; background-color: rgb(251, 250, 248); border: 1px solid rgba(0, 0, 0, 0.14902);-en-codeblock:true;"><div> //This is a code block</div><div>    fmt.Println("hello world")</div></div><ul><li><div>First item</div></li><li><div><span>Second</span> <i>item</i></div></li><ul><li>Nested item</li></ul></ul><ul style=""><li><div><en-todo checked="true"/>Collect underpants</div></li><li style=""><div><en-todo checked="false"/>???</div></li><ul style=""><li style=""><div><en-todo checked="false"/>Profit</div></li></ul></ul><div><br/></div><table style="border-collapse: collapse; min-width: 100%;"><colgroup><col style="width: 130px;"/><col style="width: 130px;"/><col style="width: 130px;"/></colgroup><tbody><tr><td style="width: 130px; padding: 8px; border: 1px solid;"><div>Header 1</div></td><td style="width: 130px; padding: 8px; border: 1px solid;"><div>Middle column</div></td><td style="width: 130px; padding: 8px; border: 1px solid;"><div>Last column title</div></td></tr><tr><td style="width: 130px; padding: 8px; border: 1px solid;"><div>Short text</div></td><td style="width: 130px; padding: 8px; border: 1px solid;"><div>Verylongunbreakabletext</div></td><td style="width: 130px; padding: 8px; border: 1px solid;"><div>Something here</div></td></tr><tr><td style="width: 130px; padding: 8px; border: 1px solid;"><div>Half empty row</div></td><td style="width: 130px; padding: 8px; border: 1px solid;"><div><br/></div></td><td style="width: 130px; padding: 8px; border: 1px solid;"><div><br/></div></td></tr></tbody></table><div style="-en-codeblock:true"><div style="-en-codeblock:true"></div></div>
2 changes: 1 addition & 1 deletion internal/testdata/golden-frontmatter.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Some **bold text**
```

- First item
- Second item
- Second _item_
- Nested item

- [x] Collect underpants
Expand Down
2 changes: 1 addition & 1 deletion internal/testdata/golden.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Some **bold text**
```

- First item
- Second item
- Second _item_
- Nested item

- [x] Collect underpants
Expand Down

0 comments on commit 8019f23

Please sign in to comment.