rewriter_test.go 1.6 KB

12345678910111213141516171819202122232425262728293031323334
  1. // Copyright 2017 Frédéric Guillot. All rights reserved.
  2. // Use of this source code is governed by the Apache 2.0
  3. // license that can be found in the LICENSE file.
  4. package rewrite
  5. import "testing"
  6. func TestRewriteWithNoMatchingRule(t *testing.T) {
  7. output := Rewriter("https://example.org/article", `Some text.`)
  8. expected := `Some text.`
  9. if expected != output {
  10. t.Errorf(`Not expected output: got "%s" instead of "%s"`, output, expected)
  11. }
  12. }
  13. func TestRewriteWithYoutubeLink(t *testing.T) {
  14. output := Rewriter("https://www.youtube.com/watch?v=1234", `Video Description`)
  15. expected := `<iframe width="650" height="350" frameborder="0" src="https://www.youtube-nocookie.com/embed/1234" allowfullscreen></iframe><p>Video Description</p>`
  16. if expected != output {
  17. t.Errorf(`Not expected output: got "%s" instead of "%s"`, output, expected)
  18. }
  19. }
  20. func TestRewriteWithXkcdLink(t *testing.T) {
  21. description := `<img src="https://imgs.xkcd.com/comics/thermostat.png" title="Your problem is so terrible, I worry that, if I help you, I risk drawing the attention of whatever god of technology inflicted it on you." alt="Your problem is so terrible, I worry that, if I help you, I risk drawing the attention of whatever god of technology inflicted it on you." />`
  22. output := Rewriter("https://xkcd.com/1912/", description)
  23. expected := description + `<blockquote cite="https://xkcd.com/1912/">Your problem is so terrible, I worry that, if I help you, I risk drawing the attention of whatever god of technology inflicted it on you.</blockquote>`
  24. if expected != output {
  25. t.Errorf(`Not expected output: got "%s" instead of "%s"`, output, expected)
  26. }
  27. }