# encoding: UTF-8 require 'simplecov' require 'simplecov-rcov' SimpleCov.start SimpleCov.formatter = SimpleCov::Formatter::RcovFormatter require 'test_helper' class GovspeakTest < Test::Unit::TestCase 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\n

si

\n\n

markdown

\n", rendered end test "extracts headers with text, level and generated id" do document = Govspeak::Document.new %{ # Big title ### Small subtitle ## Medium title } assert_equal [ Govspeak::Header.new('Big title', 1, 'big-title'), Govspeak::Header.new('Small subtitle', 3, 'small-subtitle'), Govspeak::Header.new('Medium title', 2, 'medium-title') ], document.headers end test "extracts different ids for duplicate headers" do document = Govspeak::Document.new("## Duplicate header\n\n## Duplicate header") assert_equal [ Govspeak::Header.new('Duplicate header', 2, 'duplicate-header'), Govspeak::Header.new('Duplicate header', 2, 'duplicate-header-1') ], document.headers end test "extracts text with no HTML and normalised spacing" do input = "# foo\n\nbar baz " doc = Govspeak::Document.new(input) assert_equal "foo bar baz", doc.to_text end test "govspark extensions" do markdown_regression_tests = [ { input: "^ I am very informational ^", output: %{

I am very informational

}, text: "I am very informational" }, { input: "The following is very informational\n^ I am very informational ^", output: %{

The following is very informational

I am very informational

}, text: "The following is very informational I am very informational" }, { input: "^ I am very informational", output: %{

I am very informational

}, text: "I am very informational" }, { input: "@ I am very important @", output: %{

I am very important

}, text: "I am very important" }, { input: "The following is very important @ I am very important @", output: %{

The following is very important

I am very important

}, text: "The following is very important I am very important" }, { input: "% I am very helpful %", output: %{

I am very helpful

}, text: "I am very helpful" }, { input: "The following is very helpful\n% I am very helpful %", output: %{

The following is very helpful

I am very helpful

}, text: "The following is very helpful I am very helpful" }, { input: "## Hello ##\n\n% I am very helpful %\r\n### Young Workers ###\n\n", output: %{

Hello

I am very helpful

Young Workers

}, text: "Hello I am very helpful Young Workers" }, { input: "% I am very helpful", output: %{

I am very helpful

}, text: "I am very helpful" }, { input: "This is a [link](http://www.google.com) isn't it?", output: '

This is a link isn’t it?

', text: "This is a link isn’t it?" }, { input: "This is a [link with an at sign in it](http://www.google.com/@dg/@this) isn't it?", output: '

This is a link with an at sign in it isn’t it?

', text: "This is a link with an at sign in it isn’t it?" }, { input: "HTML *[HTML]: Hyper Text Markup Language", output: %{

HTML

}, text: "HTML" }, { input: "x[a link](http://rubyforge.org)x", output: '

a link

', text: "a link" }, { input: "$! rainbow $!", output: %{

rainbow

}, text: "rainbow" }, { input: "$C help, send cake $C", output: %{

help, send cake

}, text: "help, send cake" }, { input: "$A street road $A", output: %{

street
road

}, text: "street road" }, { input: "$P $I help $I $P", output: %{
\n
\n

help

\n
\n
}, text: "help" }, { input: "$D can you tell me how to get to... $D", output: %{

can you tell me how to get to…

}, text: "can you tell me how to get to…" }, { input: "1. rod 2. jane 3. freddy", output: "
    \n
  1. rod
  2. \n
  3. jane
  4. \n
  5. freddy
  6. \n
", text: "rod jane freddy" }, { input: " ((http://maps.google.co.uk/maps?q=Winkfield+Rd,+Windsor,+Berkshire+SL4+4AY&hl=en&sll=53.800651,-4.064941&sspn=17.759517,42.055664&vpsrc=0&z=14)) ", output: %{

View Larger Map
}, text: "View Larger Map" }, { input: "s1. zippy s2. bungle s3. george ", output: %{
  1. zippy

    \n
  2. bungle

    \n
  3. george

    \n
}, text: "zippy bungle george" } ] markdown_regression_tests.each do |t| doc = Govspeak::Document.new(t[:input]) assert_equal t[:output].strip, doc.to_html.strip assert_equal t[:text], doc.to_text end end test "devolved markdown sections" do input = ":scotland: I am very devolved\n and very scottish \n:scotland:" output = '

This section applies to Scotland

I am very devolved and very scottish

' assert_equal output, Govspeak::Document.new(input).to_html end test "links inside markdown boxes" do input = "@ Message with [a link](http://foo.bar/)@" output = %{

Message with a link

} assert_equal output, Govspeak::Document.new(input).to_html end end