PageRenderTime 37ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 1ms

/spec/bluecloth/links_spec.rb

https://github.com/frenesim/bluecloth
Ruby | 165 lines | 127 code | 33 blank | 5 comment | 2 complexity | 1bd27a5401ac49f3c34a4fedce9932a6 MD5 | raw file
Possible License(s): BSD-3-Clause
  1. #!/usr/bin/env ruby
  2. # encoding: utf-8
  3. BEGIN {
  4. require 'pathname'
  5. basedir = Pathname.new( __FILE__ ).dirname.parent.parent
  6. libdir = basedir + 'lib'
  7. $LOAD_PATH.unshift( libdir ) unless $LOAD_PATH.include?( libdir )
  8. }
  9. require 'rspec'
  10. require 'bluecloth'
  11. require 'spec/lib/helpers'
  12. #####################################################################
  13. ### C O N T E X T S
  14. #####################################################################
  15. describe BlueCloth, "links" do
  16. it "supports inline links" do
  17. the_indented_markdown( <<-"---" ).should be_transformed_into(<<-"---").without_indentation
  18. An [example](http://url.com/).
  19. ---
  20. <p>An <a href="http://url.com/">example</a>.</p>
  21. ---
  22. end
  23. it "supports inline link with a title" do
  24. the_indented_markdown( <<-"---" ).should be_transformed_into(<<-"---").without_indentation
  25. An [example](http://url.com/ "Check out url.com!").
  26. ---
  27. <p>An <a href="http://url.com/" title="Check out url.com!">example</a>.</p>
  28. ---
  29. end
  30. it "supports reference-style links with no title" do
  31. the_indented_markdown( <<-"---" ).should be_transformed_into(<<-"---").without_indentation
  32. An [example][ex] reference-style link.
  33. [ex]: http://www.bluefi.com/
  34. ---
  35. <p>An <a href="http://www.bluefi.com/">example</a> reference-style link.</p>
  36. ---
  37. end
  38. it "supports indented (less than tabwidth) reference-style links" do
  39. the_indented_markdown( <<-"---" ).should be_transformed_into(<<-"---").without_indentation
  40. An [example][ex] reference-style link.
  41. [ex]: http://www.bluefi.com/
  42. ---
  43. <p>An <a href="http://www.bluefi.com/">example</a> reference-style link.</p>
  44. ---
  45. end
  46. it "supports reference-style links with quoted titles" do
  47. the_indented_markdown( <<-"---" ).should be_transformed_into(<<-"---").without_indentation
  48. An [example][ex] reference-style link.
  49. [ex]: http://www.bluefi.com/ "Check out our air."
  50. ---
  51. <p>An <a href="http://www.bluefi.com/" title="Check out our air.">example</a> reference-style link.</p>
  52. ---
  53. end
  54. it "supports reference-style links with paren titles" do
  55. the_indented_markdown( <<-"---" ).should be_transformed_into(<<-"---").without_indentation
  56. An [example][ex] reference-style link.
  57. [ex]: http://www.bluefi.com/ (Check out our air.)
  58. ---
  59. <p>An <a href="http://www.bluefi.com/" title="Check out our air.">example</a> reference-style link.</p>
  60. ---
  61. end
  62. it "supports reference-style links with intervening spaces" do
  63. the_indented_markdown( <<-"---" ).should be_transformed_into(<<-"---").without_indentation
  64. You can split the [linked part] [ex] from
  65. the reference part with a single space.
  66. [ex]: http://www.treefrog.com/ "for some reason"
  67. ---
  68. <p>You can split the <a href="http://www.treefrog.com/" title="for some reason">linked part</a> from
  69. the reference part with a single space.</p>
  70. ---
  71. end
  72. it "supports reference-style links with intervening spaces" do
  73. the_indented_markdown( <<-"---" ).should be_transformed_into(<<-"---").without_indentation
  74. You can split the [linked part]
  75. [ex] from the reference part
  76. with a newline in case your editor wraps it there, I guess.
  77. [ex]: http://www.treefrog.com/
  78. ---
  79. <p>You can split the <a href="http://www.treefrog.com/">linked part</a> from the reference part
  80. with a newline in case your editor wraps it there, I guess.</p>
  81. ---
  82. end
  83. it "supports reference-style anchors" do
  84. the_indented_markdown( <<-"---" ).should be_transformed_into(<<-"---").without_indentation
  85. I get 10 times more traffic from [Google] [1] than from
  86. [Yahoo] [2] or [MSN] [3].
  87. [1]: http://google.com/ "Google"
  88. [2]: http://search.yahoo.com/ "Yahoo Search"
  89. [3]: http://search.msn.com/ "MSN Search"
  90. ---
  91. <p>I get 10 times more traffic from <a href="http://google.com/" title="Google">Google</a> than from
  92. <a href="http://search.yahoo.com/" title="Yahoo Search">Yahoo</a> or <a href="http://search.msn.com/" title="MSN Search">MSN</a>.</p>
  93. ---
  94. end
  95. it "supports implicit name-link shortcut anchors" do
  96. the_indented_markdown( <<-"---" ).should be_transformed_into(<<-"---").without_indentation
  97. I get 10 times more traffic from [Google][] than from
  98. [Yahoo][] or [MSN][].
  99. [google]: http://google.com/ "Google"
  100. [yahoo]: http://search.yahoo.com/ "Yahoo Search"
  101. [msn]: http://search.msn.com/ "MSN Search"
  102. ---
  103. <p>I get 10 times more traffic from <a href="http://google.com/" title="Google">Google</a> than from
  104. <a href="http://search.yahoo.com/" title="Yahoo Search">Yahoo</a> or <a href="http://search.msn.com/" title="MSN Search">MSN</a>.</p>
  105. ---
  106. end
  107. it "supports inline anchors" do
  108. the_indented_markdown( <<-"---" ).should be_transformed_into(<<-"---").without_indentation
  109. I get 10 times more traffic from [Google](http://google.com/ "Google")
  110. than from [Yahoo](http://search.yahoo.com/ "Yahoo Search") or
  111. [MSN](http://search.msn.com/ "MSN Search").
  112. ---
  113. <p>I get 10 times more traffic from <a href="http://google.com/" title="Google">Google</a>
  114. than from <a href="http://search.yahoo.com/" title="Yahoo Search">Yahoo</a> or
  115. <a href="http://search.msn.com/" title="MSN Search">MSN</a>.</p>
  116. ---
  117. end
  118. it "fails gracefully for unclosed brackets (and bug #524)" do
  119. the_indented_markdown( <<-"---" ).should be_transformed_into(<<-"---").without_indentation
  120. This is just a [bracket opener; it should fail gracefully.
  121. ---
  122. <p>This is just a [bracket opener; it should fail gracefully.</p>
  123. ---
  124. end
  125. it "fails gracefully for unresolved reference-style links (Bug #620)" do
  126. the_indented_markdown( <<-"---" ).should be_transformed_into(<<-"---").without_indentation
  127. This is an unresolved [url][1].
  128. ---
  129. <p>This is an unresolved [url][1].</p>
  130. ---
  131. end
  132. end