diff --git a/spec/github_link_inline_macro_spec.rb b/spec/github_link_inline_macro_spec.rb new file mode 100644 index 0000000..b7f0a13 --- /dev/null +++ b/spec/github_link_inline_macro_spec.rb @@ -0,0 +1,108 @@ +# frozen_string_literal: true + +describe GitHubLinkInlineMacro do + it 'should create a GitHub link with the caption being the target' do + input = <<~INPUT + github:foo-dogsquared/foobarbazxyz[] + INPUT + + expected = <<~RESULT + foo-dogsquared/foobarbazxyz + RESULT + + actual = (Asciidoctor.convert input).tr_s '\n', '\n' + (expect actual).to include expected.chomp + end + + it 'should create a GitHub link to an account' do + input = 'github:foo-dogsquared[]' + + expected = <<~RESULT + foo-dogsquared + RESULT + + actual = (Asciidoctor.convert input).tr_s '\n', '\n' + (expect actual).to include expected.chomp + end + + it 'should create a GitHub link with only the repo as the caption' do + input = 'github:foo-dogsquared/foobarbazxyz[opts=repo]' + + expected = <<~RESULT + foobarbazxyz + RESULT + + actual = (Asciidoctor.convert input).tr_s '\n', '\n' + (expect actual).to include expected.chomp + end + + it 'should create a GitHub link with replaced caption' do + input = 'github:foo-dogsquared/foobarbazxyz[my XYZ project]' + + expected = <<~RESULT + my XYZ project + RESULT + + actual = (Asciidoctor.convert input).tr_s '\n', '\n' + (expect actual).to include expected.chomp + end + + it 'should create a GitHub link to Vale v2.3.0 README' do + input = 'github:errata-ai/vale[path=README.md, rev=v2.3.0]' + + expected = <<~RESULT + errata-ai/vale@v2.3.0 + RESULT + + actual = (Asciidoctor.convert input).tr_s '\n', '\n' + (expect actual).to include expected.chomp + end + + it 'should create a GitHub link to Vale v2.3.0 README with replaced caption' do + input = 'github:errata-ai/vale[Vale v2.3.0 README, path=README.md, rev=v2.3.0]' + + expected = <<~RESULT + Vale v2.3.0 README + RESULT + + actual = (Asciidoctor.convert input).tr_s '\n', '\n' + (expect actual).to include expected.chomp + end + + it %(should create a GitHub link to one of Neovim's issues) do + input = 'github:neovim/neovim[issue=614]' + + expected = <<~RESULT + neovim/neovim#614 + RESULT + + actual = (Asciidoctor.convert input).tr_s '\n', '\n' + (expect actual).to include expected.chomp + end + + it %(should create a GitHub link to one of Neovim's issues with a replaced caption) do + input = <<~INPUT + github:neovim/neovim[Neovim will not open large files properly, issue=614] + INPUT + + expected = <<~RESULT + Neovim will not open large files properly + RESULT + + actual = (Asciidoctor.convert input).tr_s '\n', '\n' + (expect actual).to include expected.chomp + end + + it %(should still link to one of Neovim's issues) do + input = <<~INPUT + github:neovim/neovim[Neovim will not open large files properly, issue=614, rev=master] + INPUT + + expected = <<~RESULT + Neovim will not open large files properly + RESULT + + actual = (Asciidoctor.convert input).tr_s '\n', '\n' + (expect actual).to include expected.chomp + end +end