# encoding: UTF-8
unless defined? ASCIIDOCTOR_PROJECT_DIR
$: << File.dirname(__FILE__); $:.uniq!
require 'test_helper'
end
# TODO
# - test negatives
# - test role on every quote type
context 'Substitutions' do
context 'Dispatcher' do
test 'apply normal substitutions' do
para = block_from_string("[blue]_http://asciidoc.org[AsciiDoc]_ & [red]*Ruby*\n§ Making +++documentation+++ together +\nsince (C) {inception_year}.")
para.document.attributes['inception_year'] = '2012'
result = para.apply_normal_subs(para.lines)
assert_equal %{AsciiDoc & Ruby\n§ Making documentation together
\nsince © 2012.}, result
end
end
context 'Quotes' do
BACKSLASH = '\\'
test 'single-line double-quoted string' do
para = block_from_string(%q{``a few quoted words''}, :attributes => {'compat-mode' => ''})
assert_equal '“a few quoted words”', para.sub_quotes(para.source)
para = block_from_string(%q{"`a few quoted words`"})
assert_equal '“a few quoted words”', para.sub_quotes(para.source)
end
test 'escaped single-line double-quoted string' do
para = block_from_string %(#{BACKSLASH}``a few quoted words''), :attributes => {'compat-mode' => ''}
assert_equal %q(‘`a few quoted words’'), para.sub_quotes(para.source)
para = block_from_string %(#{BACKSLASH * 2}``a few quoted words''), :attributes => {'compat-mode' => ''}
assert_equal %q(``a few quoted words''), para.sub_quotes(para.source)
para = block_from_string(%(#{BACKSLASH}"`a few quoted words`"))
assert_equal %q("`a few quoted words`"), para.sub_quotes(para.source)
para = block_from_string(%(#{BACKSLASH * 2}"`a few quoted words`"))
assert_equal %(#{BACKSLASH}"`a few quoted words`"), para.sub_quotes(para.source)
end
test 'multi-line double-quoted string' do
para = block_from_string(%Q{``a few\nquoted words''}, :attributes => {'compat-mode' => ''})
assert_equal "“a few\nquoted words”", para.sub_quotes(para.source)
para = block_from_string(%Q{"`a few\nquoted words`"})
assert_equal "“a few\nquoted words”", para.sub_quotes(para.source)
end
test 'double-quoted string with inline single quote' do
para = block_from_string(%q{``Here's Johnny!''}, :attributes => {'compat-mode' => ''})
assert_equal %q{“Here's Johnny!”}, para.sub_quotes(para.source)
para = block_from_string(%q{"`Here's Johnny!`"})
assert_equal %q{“Here's Johnny!”}, para.sub_quotes(para.source)
end
test 'double-quoted string with inline backquote' do
para = block_from_string(%q{``Here`s Johnny!''}, :attributes => {'compat-mode' => ''})
assert_equal %q{“Here`s Johnny!”}, para.sub_quotes(para.source)
para = block_from_string(%q{"`Here`s Johnny!`"})
assert_equal %q{“Here`s Johnny!”}, para.sub_quotes(para.source)
end
test 'double-quoted string around monospaced text' do
para = block_from_string(%q("``E=mc^2^` is the solution!`"))
assert_equal %q(“`E=mc2` is the solution!”), para.apply_subs(para.source);
para = block_from_string(%q("```E=mc^2^`` is the solution!`"))
assert_equal %q(“E=mc2
is the solution!”), para.apply_subs(para.source);
end
test 'single-line single-quoted string' do
para = block_from_string(%q{`a few quoted words'}, :attributes => {'compat-mode' => ''})
assert_equal '‘a few quoted words’', para.sub_quotes(para.source)
para = block_from_string(%q{'`a few quoted words`'})
assert_equal '‘a few quoted words’', para.sub_quotes(para.source)
end
test 'escaped single-line single-quoted string' do
para = block_from_string(%(#{BACKSLASH}`a few quoted words'), :attributes => {'compat-mode' => ''})
assert_equal %(`a few quoted words'), para.sub_quotes(para.source)
para = block_from_string(%(#{BACKSLASH}'`a few quoted words`'))
assert_equal %('`a few quoted words`'), para.sub_quotes(para.source)
end
test 'multi-line single-quoted string' do
para = block_from_string(%Q{`a few\nquoted words'}, :attributes => {'compat-mode' => ''})
assert_equal "‘a few\nquoted words’", para.sub_quotes(para.source)
para = block_from_string(%Q{'`a few\nquoted words`'})
assert_equal "‘a few\nquoted words’", para.sub_quotes(para.source)
end
test 'single-quoted string with inline single quote' do
para = block_from_string(%q{`That isn't what I did.'}, :attributes => {'compat-mode' => ''})
assert_equal %q{‘That isn't what I did.’}, para.sub_quotes(para.source)
para = block_from_string(%q{'`That isn't what I did.`'})
assert_equal %q{‘That isn't what I did.’}, para.sub_quotes(para.source)
end
test 'single-quoted string with inline backquote' do
para = block_from_string(%q{`Here`s Johnny!'}, :attributes => {'compat-mode' => ''})
assert_equal %q{‘Here`s Johnny!’}, para.sub_quotes(para.source)
para = block_from_string(%q{'`Here`s Johnny!`'})
assert_equal %q{‘Here`s Johnny!’}, para.sub_quotes(para.source)
end
test 'single-line constrained marked string' do
#para = block_from_string(%q{#a few words#}, :attributes => {'compat-mode' => ''})
#assert_equal 'a few words', para.sub_quotes(para.source)
para = block_from_string(%q{#a few words#})
assert_equal 'a few words', para.sub_quotes(para.source)
end
test 'escaped single-line constrained marked string' do
para = block_from_string(%(#{BACKSLASH}#a few words#))
assert_equal '#a few words#', para.sub_quotes(para.source)
end
test 'multi-line constrained marked string' do
#para = block_from_string(%Q{#a few\nwords#}, :attributes => {'compat-mode' => ''})
#assert_equal "a few\nwords", para.sub_quotes(para.source)
para = block_from_string(%Q{#a few\nwords#})
assert_equal "a few\nwords", para.sub_quotes(para.source)
end
test 'constrained marked string should not match entity references' do
para = block_from_string('111 #mark a# 222 "`quote a`" 333 #mark b# 444')
assert_equal %(111 mark a 222 “quote a” 333 mark b 444), para.sub_quotes(para.source)
end
test 'single-line unconstrained marked string' do
#para = block_from_string(%q{##--anything goes ##}, :attributes => {'compat-mode' => ''})
#assert_equal '--anything goes ', para.sub_quotes(para.source)
para = block_from_string(%q{##--anything goes ##})
assert_equal '--anything goes ', para.sub_quotes(para.source)
end
test 'escaped single-line unconstrained marked string' do
para = block_from_string(%(#{BACKSLASH}#{BACKSLASH}##--anything goes ##))
assert_equal '##--anything goes ##', para.sub_quotes(para.source)
end
test 'multi-line unconstrained marked string' do
#para = block_from_string(%Q{##--anything\ngoes ##}, :attributes => {'compat-mode' => ''})
#assert_equal "--anything\ngoes ", para.sub_quotes(para.source)
para = block_from_string(%Q{##--anything\ngoes ##})
assert_equal "--anything\ngoes ", para.sub_quotes(para.source)
end
test 'single-line constrained marked string with role' do
para = block_from_string(%q{[statement]#a few words#})
assert_equal 'a few words', para.sub_quotes(para.source)
end
test 'single-line constrained strong string' do
para = block_from_string(%q{*a few strong words*})
assert_equal 'a few strong words', para.sub_quotes(para.source)
end
test 'escaped single-line constrained strong string' do
para = block_from_string(%(#{BACKSLASH}*a few strong words*))
assert_equal '*a few strong words*', para.sub_quotes(para.source)
end
test 'multi-line constrained strong string' do
para = block_from_string(%Q{*a few\nstrong words*})
assert_equal "a few\nstrong words", para.sub_quotes(para.source)
end
test 'constrained strong string containing an asterisk' do
para = block_from_string(%q{*bl*ck*-eye})
assert_equal 'bl*ck-eye', para.sub_quotes(para.source)
end
test 'constrained strong string containing an asterisk and multibyte word chars' do
para = block_from_string(%q{*黑*眼圈*})
assert_equal '黑*眼圈', para.sub_quotes(para.source)
end if ::RUBY_MIN_VERSION_1_9
test 'single-line constrained quote variation emphasized string' do
para = block_from_string(%q{_a few emphasized words_})
assert_equal 'a few emphasized words', para.sub_quotes(para.source)
end
test 'escaped single-line constrained quote variation emphasized string' do
para = block_from_string(%(#{BACKSLASH}_a few emphasized words_))
assert_equal %q(_a few emphasized words_), para.sub_quotes(para.source)
end
test 'escaped single quoted string' do
para = block_from_string(%(#{BACKSLASH}'a few emphasized words'))
# NOTE the \' is replaced with ' by the :replacements substitution, later in the substitution pipeline
assert_equal %(#{BACKSLASH}'a few emphasized words'), para.sub_quotes(para.source)
end
test 'multi-line constrained emphasized quote variation string' do
para = block_from_string(%Q{_a few\nemphasized words_})
assert_equal "a few\nemphasized words", para.sub_quotes(para.source)
end
test 'single-quoted string containing an emphasized phrase' do
para = block_from_string(%q{`I told him, 'Just go for it!''}, :attributes => {'compat-mode' => ''})
assert_equal '‘I told him, Just go for it!’', para.sub_quotes(para.source)
para = block_from_string(%q{'`I told him, 'Just go for it!'`'})
assert_equal %q(‘I told him, 'Just go for it!'’), para.sub_quotes(para.source)
end
test 'escaped single-quotes inside emphasized words are restored' do
para = block_from_string(%('Here#{BACKSLASH}'s Johnny!'), :attributes => {'compat-mode' => ''})
assert_equal %q(Here's Johnny!), para.apply_normal_subs(para.lines)
para = block_from_string(%('Here#{BACKSLASH}'s Johnny!'))
assert_equal %q('Here's Johnny!'), para.apply_normal_subs(para.lines)
end
test 'single-line constrained emphasized underline variation string' do
para = block_from_string(%q{_a few emphasized words_})
assert_equal 'a few emphasized words', para.sub_quotes(para.source)
end
test 'escaped single-line constrained emphasized underline variation string' do
para = block_from_string(%(#{BACKSLASH}_a few emphasized words_))
assert_equal '_a few emphasized words_', para.sub_quotes(para.source)
end
test 'multi-line constrained emphasized underline variation string' do
para = block_from_string(%Q{_a few\nemphasized words_})
assert_equal "a few\nemphasized words", para.sub_quotes(para.source)
end
# NOTE must use apply_normal_subs because constrained monospaced is handled as a passthrough
test 'single-line constrained monospaced string' do
para = block_from_string(%(`a few <{monospaced}> words`), :attributes => {'monospaced' => 'monospaced', 'compat-mode' => ''})
assert_equal 'a few <{monospaced}> words
', para.apply_normal_subs(para.lines)
para = block_from_string(%(`a few <{monospaced}> words`), :attributes => {'monospaced' => 'monospaced'})
assert_equal 'a few <monospaced> words
', para.apply_normal_subs(para.lines)
end
# NOTE must use apply_normal_subs because constrained monospaced is handled as a passthrough
test 'single-line constrained monospaced string with role' do
para = block_from_string(%([input]`a few <{monospaced}> words`), :attributes => {'monospaced' => 'monospaced', 'compat-mode' => ''})
assert_equal 'a few <{monospaced}> words
', para.apply_normal_subs(para.lines)
para = block_from_string(%([input]`a few <{monospaced}> words`), :attributes => {'monospaced' => 'monospaced'})
assert_equal 'a few <monospaced> words
', para.apply_normal_subs(para.lines)
end
# NOTE must use apply_normal_subs because constrained monospaced is handled as a passthrough
test 'escaped single-line constrained monospaced string' do
para = block_from_string(%(#{BACKSLASH}`a few words`), :attributes => {'compat-mode' => ''})
assert_equal '`a few <monospaced> words`', para.apply_normal_subs(para.lines)
para = block_from_string(%(#{BACKSLASH}`a few words`))
assert_equal '`a few <monospaced> words`', para.apply_normal_subs(para.lines)
end
# NOTE must use apply_normal_subs because constrained monospaced is handled as a passthrough
test 'escaped single-line constrained monospaced string with role' do
para = block_from_string(%([input]#{BACKSLASH}`a few words`), :attributes => {'compat-mode' => ''})
assert_equal '[input]`a few <monospaced> words`', para.apply_normal_subs(para.lines)
para = block_from_string(%([input]#{BACKSLASH}`a few words`))
assert_equal '[input]`a few <monospaced> words`', para.apply_normal_subs(para.lines)
end
# NOTE must use apply_normal_subs because constrained monospaced is handled as a passthrough
test 'escaped role on single-line constrained monospaced string' do
para = block_from_string(%(#{BACKSLASH}[input]`a few words`), :attributes => {'compat-mode' => ''})
assert_equal '[input]a few <monospaced> words
', para.apply_normal_subs(para.lines)
para = block_from_string(%(#{BACKSLASH}[input]`a few words`))
assert_equal '[input]a few <monospaced> words
', para.apply_normal_subs(para.lines)
end
# NOTE must use apply_normal_subs because constrained monospaced is handled as a passthrough
test 'escaped role on escaped single-line constrained monospaced string' do
para = block_from_string(%(#{BACKSLASH}[input]#{BACKSLASH}`a few words`), :attributes => {'compat-mode' => ''})
assert_equal %(#{BACKSLASH}[input]`a few <monospaced> words`), para.apply_normal_subs(para.lines)
para = block_from_string(%(#{BACKSLASH}[input]#{BACKSLASH}`a few words`))
assert_equal %(#{BACKSLASH}[input]`a few <monospaced> words`), para.apply_normal_subs(para.lines)
end
# NOTE must use apply_normal_subs because constrained monospaced is handled as a passthrough
test 'multi-line constrained monospaced string' do
para = block_from_string(%(`a few\n<{monospaced}> words`), :attributes => {'monospaced' => 'monospaced', 'compat-mode' => ''})
assert_equal "a few\n<{monospaced}> words
", para.apply_normal_subs(para.lines)
para = block_from_string(%(`a few\n<{monospaced}> words`), :attributes => {'monospaced' => 'monospaced'})
assert_equal "a few\n<monospaced> words
", para.apply_normal_subs(para.lines)
end
test 'single-line unconstrained strong chars' do
para = block_from_string(%q{**Git**Hub})
assert_equal 'GitHub', para.sub_quotes(para.source)
end
test 'escaped single-line unconstrained strong chars' do
para = block_from_string(%(#{BACKSLASH}**Git**Hub))
assert_equal '*Git*Hub', para.sub_quotes(para.source)
end
test 'multi-line unconstrained strong chars' do
para = block_from_string(%Q{**G\ni\nt\n**Hub})
assert_equal "G\ni\nt\nHub", para.sub_quotes(para.source)
end
test 'unconstrained strong chars with inline asterisk' do
para = block_from_string(%q{**bl*ck**-eye})
assert_equal 'bl*ck-eye', para.sub_quotes(para.source)
end
test 'unconstrained strong chars with role' do
para = block_from_string(%q{Git[blue]**Hub**})
assert_equal %q{GitHub}, para.sub_quotes(para.source)
end
# TODO this is not the same result as AsciiDoc, though I don't understand why AsciiDoc gets what it gets
test 'escaped unconstrained strong chars with role' do
para = block_from_string(%(Git#{BACKSLASH}[blue]**Hub**))
assert_equal %q{Git[blue]*Hub*}, para.sub_quotes(para.source)
end
test 'single-line unconstrained emphasized chars' do
para = block_from_string(%q{__Git__Hub})
assert_equal 'GitHub', para.sub_quotes(para.source)
end
test 'escaped single-line unconstrained emphasized chars' do
para = block_from_string(%(#{BACKSLASH}__Git__Hub))
assert_equal '__Git__Hub', para.sub_quotes(para.source)
end
test 'escaped single-line unconstrained emphasized chars around word' do
para = block_from_string(%(#{BACKSLASH}#{BACKSLASH}__GitHub__))
assert_equal '__GitHub__', para.sub_quotes(para.source)
end
test 'multi-line unconstrained emphasized chars' do
para = block_from_string(%Q{__G\ni\nt\n__Hub})
assert_equal "G\ni\nt\nHub", para.sub_quotes(para.source)
end
test 'unconstrained emphasis chars with role' do
para = block_from_string(%q{[gray]__Git__Hub})
assert_equal %q{GitHub}, para.sub_quotes(para.source)
end
test 'escaped unconstrained emphasis chars with role' do
para = block_from_string(%(#{BACKSLASH}[gray]__Git__Hub))
assert_equal %q{[gray]__Git__Hub}, para.sub_quotes(para.source)
end
test 'single-line constrained monospaced chars' do
para = block_from_string(%q{call +save()+ to persist the changes}, :attributes => {'compat-mode' => ''})
assert_equal 'call save()
to persist the changes', para.sub_quotes(para.source)
para = block_from_string(%q{call [x-]+save()+ to persist the changes})
assert_equal 'call save()
to persist the changes', para.apply_subs(para.source)
para = block_from_string(%q{call `save()` to persist the changes})
assert_equal 'call save()
to persist the changes', para.sub_quotes(para.source)
end
test 'single-line constrained monospaced chars with role' do
para = block_from_string(%q{call [method]+save()+ to persist the changes}, :attributes => {'compat-mode' => ''})
assert_equal 'call save()
to persist the changes', para.sub_quotes(para.source)
para = block_from_string(%q{call [method x-]+save()+ to persist the changes})
assert_equal 'call save()
to persist the changes', para.apply_subs(para.source)
para = block_from_string(%q{call [method]`save()` to persist the changes})
assert_equal 'call save()
to persist the changes', para.sub_quotes(para.source)
end
test 'escaped single-line constrained monospaced chars' do
para = block_from_string(%(call #{BACKSLASH}+save()+ to persist the changes), :attributes => {'compat-mode' => ''})
assert_equal 'call +save()+ to persist the changes', para.sub_quotes(para.source)
para = block_from_string(%(call #{BACKSLASH}`save()` to persist the changes))
assert_equal 'call `save()` to persist the changes', para.sub_quotes(para.source)
end
test 'escaped single-line constrained monospaced chars with role' do
para = block_from_string(%(call [method]#{BACKSLASH}+save()+ to persist the changes), :attributes => {'compat-mode' => ''})
assert_equal 'call [method]+save()+ to persist the changes', para.sub_quotes(para.source)
para = block_from_string(%(call [method]#{BACKSLASH}`save()` to persist the changes))
assert_equal 'call [method]`save()` to persist the changes', para.sub_quotes(para.source)
end
test 'escaped role on single-line constrained monospaced chars' do
para = block_from_string(%(call #{BACKSLASH}[method]+save()+ to persist the changes), :attributes => {'compat-mode' => ''})
assert_equal 'call [method]save()
to persist the changes', para.sub_quotes(para.source)
para = block_from_string(%(call #{BACKSLASH}[method]`save()` to persist the changes))
assert_equal 'call [method]save()
to persist the changes', para.sub_quotes(para.source)
end
test 'escaped role on escaped single-line constrained monospaced chars' do
para = block_from_string(%(call #{BACKSLASH}[method]#{BACKSLASH}+save()+ to persist the changes), :attributes => {'compat-mode' => ''})
assert_equal %(call #{BACKSLASH}[method]+save()+ to persist the changes), para.sub_quotes(para.source)
para = block_from_string(%(call #{BACKSLASH}[method]#{BACKSLASH}`save()` to persist the changes))
assert_equal %(call #{BACKSLASH}[method]`save()` to persist the changes), para.sub_quotes(para.source)
end
test 'single-line unconstrained monospaced chars' do
para = block_from_string(%q{Git++Hub++}, :attributes => {'compat-mode' => ''})
assert_equal 'GitHub
', para.sub_quotes(para.source)
para = block_from_string(%q{Git[x-]++Hub++})
assert_equal 'GitHub
', para.apply_subs(para.source)
para = block_from_string(%q{Git``Hub``})
assert_equal 'GitHub
', para.sub_quotes(para.source)
end
test 'escaped single-line unconstrained monospaced chars' do
para = block_from_string(%(Git#{BACKSLASH}++Hub++), :attributes => {'compat-mode' => ''})
assert_equal 'Git+Hub
+', para.sub_quotes(para.source)
para = block_from_string(%(Git#{BACKSLASH * 2}++Hub++), :attributes => {'compat-mode' => ''})
assert_equal 'Git++Hub++', para.sub_quotes(para.source)
para = block_from_string(%(Git#{BACKSLASH}``Hub``))
assert_equal 'Git``Hub``', para.sub_quotes(para.source)
end
test 'multi-line unconstrained monospaced chars' do
para = block_from_string(%Q{Git++\nH\nu\nb++}, :attributes => {'compat-mode' => ''})
assert_equal "Git\nH\nu\nb
", para.sub_quotes(para.source)
para = block_from_string(%Q{Git[x-]++\nH\nu\nb++})
assert_equal %(Git\nH\nu\nb
), para.apply_subs(para.source)
para = block_from_string(%Q{Git``\nH\nu\nb``})
assert_equal "Git\nH\nu\nb
", para.sub_quotes(para.source)
end
test 'single-line superscript chars' do
para = block_from_string(%(x^2^ = x * x, e = mc^2^, there's a 1^st^ time for everything))
assert_equal %(x2 = x * x, e = mc2, there\'s a 1st time for everything), para.sub_quotes(para.source)
end
test 'escaped single-line superscript chars' do
para = block_from_string(%(x#{BACKSLASH}^2^ = x * x))
assert_equal 'x^2^ = x * x', para.sub_quotes(para.source)
end
test 'does not match superscript across whitespace' do
para = block_from_string(%Q{x^(n\n-\n1)^})
assert_equal para.source, para.sub_quotes(para.source)
end
test 'does not match adjacent superscript chars' do
para = block_from_string 'a ^^ b'
assert_equal 'a ^^ b', para.sub_quotes(para.source)
end
test 'does not confuse superscript and links with blank window shorthand' do
para = block_from_string(%Q{http://localhost[Text^] on the 21^st^ and 22^nd^})
assert_equal 'Text on the 21st and 22nd', para.content
end
test 'single-line subscript chars' do
para = block_from_string(%q{H~2~O})
assert_equal 'H2O', para.sub_quotes(para.source)
end
test 'escaped single-line subscript chars' do
para = block_from_string(%(H#{BACKSLASH}~2~O))
assert_equal 'H~2~O', para.sub_quotes(para.source)
end
test 'does not match subscript across whitespace' do
para = block_from_string(%Q{project~ view\non\nGitHub~})
assert_equal para.source, para.sub_quotes(para.source)
end
test 'does not match adjacent subscript chars' do
para = block_from_string 'a ~~ b'
assert_equal 'a ~~ b', para.sub_quotes(para.source)
end
test 'does not match subscript across distinct URLs' do
para = block_from_string(%Q{http://www.abc.com/~def[DEF] and http://www.abc.com/~ghi[GHI]})
assert_equal para.source, para.sub_quotes(para.source)
end
test 'quoted text with role shorthand' do
para = block_from_string(%q{[.white.red-background]#alert#})
assert_equal 'alert', para.sub_quotes(para.source)
end
test 'quoted text with id shorthand' do
para = block_from_string(%q{[#bond]#007#})
assert_equal '007', para.sub_quotes(para.source)
end
test 'quoted text with id and role shorthand' do
para = block_from_string(%q{[#bond.white.red-background]#007#})
assert_equal '007', para.sub_quotes(para.source)
end
test 'quoted text with id and role shorthand using docbook backend' do
para = block_from_string(%q{[#bond.white.red-background]#007#}, :backend => 'docbook45')
assert_equal '007', para.sub_quotes(para.source)
end
test 'should ignore attributes after comma' do
para = block_from_string(%q{[red, foobar]#alert#})
assert_equal 'alert', para.sub_quotes(para.source)
end
test 'should assign role attribute when shorthand style contains a role' do
para = block_from_string 'blah'
result = para.parse_quoted_text_attributes '.red#idref'
expect = {'id' => 'idref', 'role' => 'red'}
assert_equal expect, result
end
test 'should not assign role attribute if shorthand style has no roles' do
para = block_from_string 'blah'
result = para.parse_quoted_text_attributes '#idref'
expect = {'id' => 'idref'}
assert_equal expect, result
end
end
context 'Macros' do
test 'a single-line link macro should be interpreted as a link' do
para = block_from_string('link:/home.html[]')
assert_equal %q{/home.html}, para.sub_macros(para.source)
end
test 'a single-line link macro with text should be interpreted as a link' do
para = block_from_string('link:/home.html[Home]')
assert_equal %q{Home}, para.sub_macros(para.source)
end
test 'a mailto macro should be interpreted as a mailto link' do
para = block_from_string('mailto:doc.writer@asciidoc.org[]')
assert_equal %q{doc.writer@asciidoc.org}, para.sub_macros(para.source)
end
test 'a mailto macro with text should be interpreted as a mailto link' do
para = block_from_string('mailto:doc.writer@asciidoc.org[Doc Writer]')
assert_equal %q{Doc Writer}, para.sub_macros(para.source)
end
test 'a mailto macro with text and subject should be interpreted as a mailto link' do
para = block_from_string('mailto:doc.writer@asciidoc.org[Doc Writer, Pull request]', :attributes => {'linkattrs' => ''})
assert_equal %q{Doc Writer}, para.sub_macros(para.source)
end
test 'a mailto macro with text, subject and body should be interpreted as a mailto link' do
para = block_from_string('mailto:doc.writer@asciidoc.org[Doc Writer, Pull request, Please accept my pull request]', :attributes => {'linkattrs' => ''})
assert_equal %q{Doc Writer}, para.sub_macros(para.source)
end
test 'should recognize inline email addresses' do
para = block_from_string('doc.writer@asciidoc.org')
assert_equal %q{doc.writer@asciidoc.org}, para.sub_macros(para.source)
para = block_from_string('')
assert_equal %q{<doc.writer@asciidoc.org>}, para.apply_normal_subs(para.lines)
para = block_from_string('author+website@4fs.no')
assert_equal %q{author+website@4fs.no}, para.sub_macros(para.source)
para = block_from_string('john@domain.uk.co')
assert_equal %q{john@domain.uk.co}, para.sub_macros(para.source)
end
test 'should ignore escaped inline email address' do
para = block_from_string(%(#{BACKSLASH}doc.writer@asciidoc.org))
assert_equal %q{doc.writer@asciidoc.org}, para.sub_macros(para.source)
end
test 'a single-line raw url should be interpreted as a link' do
para = block_from_string('http://google.com')
assert_equal %q{http://google.com}, para.sub_macros(para.source)
end
test 'a single-line raw url with text should be interpreted as a link' do
para = block_from_string('http://google.com[Google]')
assert_equal %q{Google}, para.sub_macros(para.source)
end
test 'a multi-line raw url with text should be interpreted as a link' do
para = block_from_string("http://google.com[Google\nHomepage]")
assert_equal %{Google\nHomepage}, para.sub_macros(para.source)
end
test 'a multi-line raw url with attribute as text should be interpreted as a link with resolved attribute' do
para = block_from_string("http://google.com[{google_homepage}]")
para.document.attributes['google_homepage'] = 'Google Homepage'
assert_equal %q{Google Homepage}, para.sub_macros(para.source)
end
test 'a single-line escaped raw url should not be interpreted as a link' do
para = block_from_string(%(#{BACKSLASH}http://google.com))
assert_equal %q{http://google.com}, para.sub_macros(para.source)
end
test 'a comma separated list of links should not include commas in links' do
para = block_from_string('http://foo.com, http://bar.com, http://example.org')
assert_equal %q{http://foo.com, http://bar.com, http://example.org}, para.sub_macros(para.source)
end
test 'a single-line image macro should be interpreted as an image' do
para = block_from_string('image:tiger.png[]')
assert_equal %{}, para.sub_macros(para.source).gsub(/>\s+, '><')
end
test 'should replace underscore and hyphen with space in generated alt text for an inline image' do
para = block_from_string('image:tiger-with-family_1.png[]')
assert_equal %{}, para.sub_macros(para.source).gsub(/>\s+, '><')
end
test 'a single-line image macro with text should be interpreted as an image with alt text' do
para = block_from_string('image:tiger.png[Tiger]')
assert_equal %{}, para.sub_macros(para.source).gsub(/>\s+, '><')
end
test 'an image macro with SVG image and text should be interpreted as an image with alt text' do
para = block_from_string('image:tiger.svg[Tiger]')
assert_equal %{}, para.sub_macros(para.source).gsub(/>\s+, '><')
end
test 'an image macro with an interactive SVG image and alt text should be converted to an object element' do
para = block_from_string('image:tiger.svg[Tiger,opts=interactive]', :safe => Asciidoctor::SafeMode::SERVER, :attributes => { 'imagesdir' => 'images' })
assert_equal %{}, para.sub_macros(para.source).gsub(/>\s+, '><')
end
test 'an image macro with an interactive SVG image, fallback and alt text should be converted to an object element' do
para = block_from_string('image:tiger.svg[Tiger,fallback=tiger.png,opts=interactive]', :safe => Asciidoctor::SafeMode::SERVER, :attributes => { 'imagesdir' => 'images' })
assert_equal %{}, para.sub_macros(para.source).gsub(/>\s+, '><')
end
test 'an image macro with an inline SVG image should be converted to an svg element' do
para = block_from_string('image:circle.svg[Tiger,100,opts=inline]', :safe => Asciidoctor::SafeMode::SERVER, :attributes => { 'imagesdir' => 'fixtures', 'docdir' => ::File.dirname(__FILE__) })
result = para.sub_macros(para.source).gsub(/>\s+, '><')
assert_match(/