# encoding: UTF-8 require 'simplecov' require 'simplecov-rcov' SimpleCov.start SimpleCov.formatter = SimpleCov::Formatter::RcovFormatter require 'test_helper' require 'govspeak_test_helper' require 'ostruct' class GovspeakTest < Test::Unit::TestCase include GovspeakTestHelper test "simple smoke-test" do rendered = Govspeak::Document.new("*this is markdown*").to_html assert_equal "
this is markdown
\n", rendered end test "simple smoke-test for simplified API" do rendered = Govspeak::Document.to_html("*this is markdown*") assert_equal "this is markdown
\n", rendered end test "simple block extension" do rendered = Govspeak::Document.new("this \n{::reverse}\n*is*\n{:/reverse}\n markdown").to_html assert_equal "this
\n\nsi
\n\nmarkdown
\n", rendered end test "highlight-answer block extension" do rendered = Govspeak::Document.new("this \n{::highlight-answer}Lead in to *BIG TEXT*\n{:/highlight-answer}").to_html assert_equal %Q{this
\n\nLead in to BIG TEXT
\n\n123 Test Street
Testcase Cliffs
Teston
0123 456 7890 \n
I am very informational
The following is very informational
I am very informational
I am very informational
I am very important
The following is very important
I am very important
I am very helpful
The following is very helpful
I am very helpful
I am very helpful
I am very helpful
This is a link isn’t it?
' assert_text_output "This is a link isn’t it?" end test_given_govspeak "This is a [link with an at sign in it](http://www.gov.uk/@dg/@this) isn't it?" do assert_html_output 'This is a link with an at sign in it isn’t it?
' assert_text_output "This is a link with an at sign in it isn’t it?" end test_given_govspeak " HTML *[HTML]: Hyper Text Markup Language" do assert_html_output %{HTML
} assert_text_output "HTML" end test_given_govspeak "x[a link](http://rubyforge.org)x" do assert_html_output '' assert_text_output "a link" end test_given_govspeak "x[an xx link](http://x.com)x" do assert_html_output '' end test_given_govspeak "[internal link](http://www.gov.uk)" do assert_html_output '' end test_given_govspeak "[link with no host is assumed to be internal](/)" do assert_html_output 'link with no host is assumed to be internal
' end test_given_govspeak "[internal link with rel attribute keeps it](http://www.gov.uk){:rel='next'}" do assert_html_output 'internal link with rel attribute keeps it
' end test_given_govspeak "[external link without x markers](http://www.google.com)" do assert_html_output 'external link without x markers
' end test_given_govspeak "[external link with rel attribute](http://www.google.com){:rel='next'}" do assert_html_output 'external link with rel attribute
' end test_given_govspeak "Text before [an external link](http://www.google.com)" do assert_html_output 'Text before an external link
' end test_given_govspeak "[An external link](http://www.google.com) with text afterwards" do assert_html_output 'An external link with text afterwards
' end test_given_govspeak "Text before [an external link](http://www.google.com) and text afterwards" do assert_html_output 'Text before an external link and text afterwards
' end test "should be able to override default 'document_domains' option" do html = Govspeak::Document.new("[internal link](http://www.not-external.com)", document_domains: %w(www.not-external.com)).to_html refute html.include?('rel="external"'), "should not consider www.not-external.com as an external url" end test "should be able to supply multiple domains for 'document_domains' option" do html = Govspeak::Document.new("[internal link](http://www.not-external-either.com)", document_domains: %w(www.not-external.com www.not-external-either.com)).to_html refute html.include?('rel="external"'), "should not consider www.not-external-either.com as an external url" end test "should be able to override default 'input' option" do html = Govspeak::Document.new("[external link](http://www.external.com)", input: "kramdown").to_html refute html.include?('rel="external"'), "should not automatically add rel external attribute" end test "should be able to override default 'entity output' option" do html = Govspeak::Document.new("&", entity_output: :numeric).to_html assert html.include?("&") end test "should be assume link with invalid uri is internal" do html = Govspeak::Document.new("[link](:invalid-uri)").to_html refute html.include?('rel="external"') end test "should be assume link with invalid uri component is internal" do html = Govspeak::Document.new("[link](mailto://www.example.com)").to_html refute html.include?('rel="external"') end # Regression test - the surrounded_by helper doesn't require the closing x # so 'xaa' was getting picked up by the external link helper above # TODO: review whether we should require closing symbols for these extensions # need to check all existing content. test_given_govspeak "xaa" do assert_html_output 'xaa
' assert_text_output "xaa" end test_given_govspeak " $! rainbow $!" do assert_html_output %{rainbow
help, send cake
street
road
help
\ncan you tell me how to get to…
Click here to start the tool
Here is some text
Click here to start the tool
zippy
bungle
george
This section applies to Scotland
I am very devolved and very scottish
Message with a link