diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/unit/lib/redmine/wiki_formatting/common_mark/formatter_test.rb | 29 | ||||
-rw-r--r-- | test/unit/lib/redmine/wiki_formatting/common_mark/syntax_highlight_filter_test.rb | 22 |
2 files changed, 36 insertions, 15 deletions
diff --git a/test/unit/lib/redmine/wiki_formatting/common_mark/formatter_test.rb b/test/unit/lib/redmine/wiki_formatting/common_mark/formatter_test.rb index d121d5425..cd5e89931 100644 --- a/test/unit/lib/redmine/wiki_formatting/common_mark/formatter_test.rb +++ b/test/unit/lib/redmine/wiki_formatting/common_mark/formatter_test.rb @@ -94,24 +94,31 @@ class Redmine::WikiFormatting::CommonMark::FormatterTest < ActionView::TestCase end def test_should_support_syntax_highlight - text = <<-STR - ~~~ruby - def foo - end - ~~~ + text = <<~STR + ~~~ruby + def foo + end + ~~~ STR assert_select_in format(text), 'pre code.ruby.syntaxhl' do assert_select 'span.k', :text => 'def' + assert_select "[data-language='ruby']" end end - def test_should_not_allow_invalid_language_for_code_blocks - text = <<-STR - ~~~foo - test - ~~~ + def test_should_support_syntax_highlight_for_language_with_special_chars + text = <<~STR + ~~~c++ + int main() { + } + ~~~ STR - assert_equal "<pre>test\n</pre>", format(text) + + assert_select_in format(text), 'pre' do + assert_select 'code[class=?]', "c++ syntaxhl" + assert_select 'span.kt', :text => 'int' + assert_select "[data-language=?]", "c++" + end end def test_external_links_should_have_external_css_class diff --git a/test/unit/lib/redmine/wiki_formatting/common_mark/syntax_highlight_filter_test.rb b/test/unit/lib/redmine/wiki_formatting/common_mark/syntax_highlight_filter_test.rb index e7e782d53..586dbbe1e 100644 --- a/test/unit/lib/redmine/wiki_formatting/common_mark/syntax_highlight_filter_test.rb +++ b/test/unit/lib/redmine/wiki_formatting/common_mark/syntax_highlight_filter_test.rb @@ -38,7 +38,7 @@ if Object.const_defined?(:CommonMarker) </code></pre> HTML expected = <<~HTML - <pre><code class="ruby syntaxhl"> + <pre><code class="ruby syntaxhl" data-language="ruby"> <span class="k">def</span> <span class="nf">foo</span> <span class="k">end</span> </code></pre> @@ -46,7 +46,21 @@ if Object.const_defined?(:CommonMarker) assert_equal expected, filter(input) end - def test_should_strip_code_for_unknown_lang + def test_should_highlight_supported_language_with_special_chars + input = <<~HTML + <pre><code class="language-c-k&r"> + int i; + </code></pre> + HTML + expected = <<~HTML + <pre><code data-language="c-k&r"> + int i; + </code></pre> + HTML + assert_equal expected, filter(input) + end + + def test_should_strip_code_class_and_preserve_data_language_attr_for_unknown_language input = <<~HTML <pre><code class="language-foobar"> def foo @@ -54,10 +68,10 @@ if Object.const_defined?(:CommonMarker) </code></pre> HTML expected = <<~HTML - <pre> + <pre><code data-language="foobar"> def foo end - </pre> + </code></pre> HTML assert_equal expected, filter(input) end |