2017-11-20 00:10:04 -05:00
// Copyright 2017 Frédéric Guillot. All rights reserved.
// Use of this source code is governed by the Apache 2.0
// license that can be found in the LICENSE file.
package rewrite
import "testing"
func TestRewriteWithNoMatchingRule ( t * testing . T ) {
2017-12-12 01:16:32 -05:00
output := Rewriter ( "https://example.org/article" , ` Some text. ` , ` ` )
2017-11-20 00:10:04 -05:00
expected := ` Some text. `
if expected != output {
t . Errorf ( ` Not expected output: got "%s" instead of "%s" ` , output , expected )
}
}
func TestRewriteWithYoutubeLink ( t * testing . T ) {
2017-12-12 01:16:32 -05:00
output := Rewriter ( "https://www.youtube.com/watch?v=1234" , ` Video Description ` , ` ` )
2017-11-20 00:10:04 -05:00
expected := ` <iframe width="650" height="350" frameborder="0" src="https://www.youtube-nocookie.com/embed/1234" allowfullscreen></iframe><p>Video Description</p> `
if expected != output {
t . Errorf ( ` Not expected output: got "%s" instead of "%s" ` , output , expected )
}
}
2017-12-12 01:16:32 -05:00
func TestRewriteWithInexistingCustomRule ( t * testing . T ) {
output := Rewriter ( "https://www.youtube.com/watch?v=1234" , ` Video Description ` , ` some rule ` )
expected := ` Video Description `
if expected != output {
t . Errorf ( ` Not expected output: got "%s" instead of "%s" ` , output , expected )
}
}
2017-11-20 00:10:04 -05:00
func TestRewriteWithXkcdLink ( t * testing . T ) {
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." /> `
2017-12-12 01:16:32 -05:00
output := Rewriter ( "https://xkcd.com/1912/" , description , ` ` )
2017-11-20 00:10:04 -05:00
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> `
if expected != output {
t . Errorf ( ` Not expected output: got "%s" instead of "%s" ` , output , expected )
}
}
2017-12-12 01:16:32 -05:00
func TestRewriteWithXkcdLinkAndNoImage ( t * testing . T ) {
description := "test"
output := Rewriter ( "https://xkcd.com/1912/" , description , ` ` )
expected := description
if expected != output {
t . Errorf ( ` Not expected output: got "%s" instead of "%s" ` , output , expected )
}
}
func TestRewriteWithXkcdAndNoImage ( t * testing . T ) {
description := "test"
output := Rewriter ( "https://xkcd.com/1912/" , description , ` ` )
expected := description
if expected != output {
t . Errorf ( ` Not expected output: got "%s" instead of "%s" ` , output , expected )
}
}
2017-12-14 00:30:40 -05:00
func TestRewriteWithPDFLink ( t * testing . T ) {
description := "test"
output := Rewriter ( "https://example.org/document.pdf" , description , ` ` )
expected := ` <a href="https://example.org/document.pdf">PDF</a><br>test `
if expected != output {
t . Errorf ( ` Not expected output: got "%s" instead of "%s" ` , output , expected )
}
}