From 5bf15964140c767b5011f1ee65d5a4f8e7a05231 Mon Sep 17 00:00:00 2001 From: Parker Moore Date: Tue, 14 Oct 2014 12:04:09 -0700 Subject: [PATCH] Refactor Highlight tag tests to use a helper method to create the tag. --- Gemfile | 1 + jekyll.gemspec | 2 +- test/test_tags.rb | 40 +++++++++++++++++++++++++++++----------- 3 files changed, 31 insertions(+), 12 deletions(-) diff --git a/Gemfile b/Gemfile index 25b40ed2..d680ef69 100644 --- a/Gemfile +++ b/Gemfile @@ -1,5 +1,6 @@ source 'https://rubygems.org' gemspec +gem "liquid", github: 'Shopify/liquid' if ENV['BENCHMARK'] gem 'rbtrace' diff --git a/jekyll.gemspec b/jekyll.gemspec index 4913951e..c9876c47 100644 --- a/jekyll.gemspec +++ b/jekyll.gemspec @@ -28,7 +28,7 @@ Gem::Specification.new do |s| s.rdoc_options = ['--charset=UTF-8'] s.extra_rdoc_files = %w[README.markdown LICENSE] - s.add_runtime_dependency('liquid', '~> 2.6.1') + #s.add_runtime_dependency('liquid', '') s.add_runtime_dependency('kramdown', '~> 1.3') s.add_runtime_dependency('mercenary', '~> 0.3.3') s.add_runtime_dependency('safe_yaml', '~> 1.0') diff --git a/test/test_tags.rb b/test/test_tags.rb index a47ca897..bc4b48cd 100644 --- a/test/test_tags.rb +++ b/test/test_tags.rb @@ -43,6 +43,10 @@ CONTENT create_post(content, override) end + def highlight_block_with_opts(options_string) + Jekyll::Tags::HighlightBlock.parse('highlight', options_string, ["test", "{% endhighlight %}", "\n"], {}) + end + context "language name" do should "match only the required set of chars" do r = Jekyll::Tags::HighlightBlock::SYNTAX @@ -59,37 +63,51 @@ CONTENT end end - context "initialized tag" do - should "set the correct options" do - tag = Jekyll::Tags::HighlightBlock.new('highlight', 'ruby ', ["test", "{% endhighlight %}", "\n"]) + context "highlight tag in unsafe mode" do + should "set the no options with just a language name" do + tag = highlight_block_with_opts('ruby ') assert_equal({}, tag.instance_variable_get(:@options)) + end - tag = Jekyll::Tags::HighlightBlock.new('highlight', 'ruby linenos ', ["test", "{% endhighlight %}", "\n"]) + should "set the linenos option as 'inline' if no linenos value" do + tag = highlight_block_with_opts('ruby linenos ') assert_equal({ :linenos => 'inline' }, tag.instance_variable_get(:@options)) + end - tag = Jekyll::Tags::HighlightBlock.new('highlight', 'ruby linenos=table ', ["test", "{% endhighlight %}", "\n"]) + should "set the linenos option to 'table' if the linenos key is given the table value" do + tag = highlight_block_with_opts('ruby linenos=table ') assert_equal({ :linenos => 'table' }, tag.instance_variable_get(:@options)) + end - tag = Jekyll::Tags::HighlightBlock.new('highlight', 'ruby linenos=table nowrap', ["test", "{% endhighlight %}", "\n"]) + should "recognize nowrap option with linenos set" do + tag = highlight_block_with_opts('ruby linenos=table nowrap ') assert_equal({ :linenos => 'table', :nowrap => true }, tag.instance_variable_get(:@options)) + end - tag = Jekyll::Tags::HighlightBlock.new('highlight', 'ruby linenos=table cssclass=hl', ["test", "{% endhighlight %}", "\n"]) + should "recognize the cssclass option" do + tag = highlight_block_with_opts('ruby linenos=table cssclass=hl ') assert_equal({ :cssclass => 'hl', :linenos => 'table' }, tag.instance_variable_get(:@options)) + end - tag = Jekyll::Tags::HighlightBlock.new('highlight', 'ruby linenos=table cssclass=hl hl_linenos=3', ["test", "{% endhighlight %}", "\n"]) + should "recognize the hl_linenos option and its value" do + tag = highlight_block_with_opts('ruby linenos=table cssclass=hl hl_linenos=3 ') assert_equal({ :cssclass => 'hl', :linenos => 'table', :hl_linenos => '3' }, tag.instance_variable_get(:@options)) + end - tag = Jekyll::Tags::HighlightBlock.new('highlight', 'ruby linenos=table cssclass=hl hl_linenos="3 5 6"', ["test", "{% endhighlight %}", "\n"]) + should "recognize multiple values of hl_linenos" do + tag = highlight_block_with_opts('ruby linenos=table cssclass=hl hl_linenos="3 5 6" ') assert_equal({ :cssclass => 'hl', :linenos => 'table', :hl_linenos => ['3', '5', '6'] }, tag.instance_variable_get(:@options)) + end - tag = Jekyll::Tags::HighlightBlock.new('highlight', 'Ruby ', ["test", "{% endhighlight %}", "\n"]) + should "treat language name as case insensitive" do + tag = highlight_block_with_opts('Ruby ') assert_equal "ruby", tag.instance_variable_get(:@lang), "lexers should be case insensitive" end end context "in safe mode" do setup do - @tag = Jekyll::Tags::HighlightBlock.new('highlight', 'text ', ["test", "{% endhighlight %}", "\n"]) + @tag = highlight_block_with_opts('text ') end should "allow linenos" do