require "spec_helper" RSpec.describe Asciidoctor::Standoc do it "processes the PlantUML macro" do expect(xmlpp(strip_guid(Asciidoctor.convert(<<~"INPUT", backend: :standoc, header_footer: true)).gsub(%r{plantuml/plantuml[^./]+\.}, "plantuml/_."))).to be_equivalent_to xmlpp(<<~"OUTPUT") #{ASCIIDOC_BLANK_HDR} [plantuml] .... @startuml Alice -> Bob: Authentication Request Bob --> Alice: Authentication Response Alice -> Bob: Another authentication Request Alice <-- Bob: another authentication Response @enduml .... [plantuml] .... Alice -> Bob: Authentication Request Bob --> Alice: Authentication Response Alice -> Bob: Another authentication Request Alice <-- Bob: another authentication Response .... [plantuml] .... @startuml filename Alice -> Bob: Authentication Request Bob --> Alice: Authentication Response Alice -> Bob: Another authentication Request Alice <-- Bob: another authentication Response @enduml .... INPUT #{BLANK_HDR}
OUTPUT end it "processes the PlantUML macro with imagesdir" do expect(xmlpp(strip_guid(Asciidoctor.convert(<<~"INPUT", backend: :standoc, header_footer: true)).gsub(%r{spec/assets/[^./]+\.}, "spec/assets/_."))).to be_equivalent_to xmlpp(<<~"OUTPUT") = Document title Author :docfile: test.adoc :nodoc: :novalid: :no-isobib: :imagesdir: spec/assets [plantuml] .... @startuml Alice -> Bob: Authentication Request Bob --> Alice: Authentication Response Alice -> Bob: Another authentication Request Alice <-- Bob: another authentication Response @enduml .... INPUT #{BLANK_HDR}
OUTPUT end context 'when lutaml_diagram' do let(:input) do <<~"OUTPUT" = Document title Author :docfile: test.adoc :nodoc: :novalid: :no-isobib: :imagesdir: spec/assets [lutaml_diagram] .... diagram MyView { fontname "Arial" title "my diagram" class Foo {} } .... OUTPUT end let(:output) do <<~"OUTPUT" #{BLANK_HDR}
OUTPUT end it "processes the lutaml_diagram" do expect( xmlpp( strip_guid(Asciidoctor.convert(input, backend: :standoc, header_footer: true)) .gsub(%r{".+spec\/assets\/lutaml\/[^.\/]+\.}, %q("spec/assets/_.)))) .to(be_equivalent_to xmlpp(output)) end end context 'when lutaml_uml_attributes_table' do let(:example_file) { fixtures_path("diagram_definitions.lutaml") } let(:input) do <<~"OUTPUT" = Document title Author :docfile: test.adoc :nodoc: :novalid: :no-isobib: :imagesdir: spec/assets [lutaml_uml_attributes_table,#{example_file},AttributeProfile] OUTPUT end let(:output) do <<~"OUTPUT" #{BLANK_HDR} AttributeProfile AttributeProfile attributes
Name Definition Mandatory/ Optional/ Conditional Max Occur Data Type
addressClassProfile TODO: enum ‘s definition O 1 CharacterString
imlicistAttributeProfile this is attribute definition with multiply lines O 1 CharacterString
OUTPUT end it "processes the lutaml_uml_attributes_table macro" do expect( xmlpp( strip_guid(Asciidoctor.convert(input, backend: :standoc, header_footer: true)))) .to(be_equivalent_to(xmlpp(output))) end end it "processes the PlantUML macro with PlantUML disabled" do mock_plantuml_disabled expect { Asciidoctor.convert(<<~"INPUT", backend: :standoc, header_footer: true) }.to output(%r{PlantUML not installed}).to_stderr #{ASCIIDOC_BLANK_HDR} [plantuml] .... @startuml Alice -> Bob: Authentication Request Bob --> Alice: Authentication Response Alice -> Bob: Another authentication Request Alice <-- Bob: another authentication Response @enduml .... INPUT mock_plantuml_disabled expect(xmlpp(strip_guid(Asciidoctor.convert(<<~"INPUT", backend: :standoc, header_footer: true)))).to be_equivalent_to xmlpp(<<~"OUTPUT") #{ASCIIDOC_BLANK_HDR} [plantuml] .... @startuml Alice -> Bob: Authentication Request Bob --> Alice: Authentication Response Alice -> Bob: Another authentication Request Alice <-- Bob: another authentication Response @enduml .... INPUT #{BLANK_HDR} @startuml Alice -> Bob: Authentication Request Bob --> Alice: Authentication Response Alice -> Bob: Another authentication Request Alice <-- Bob: another authentication Response @enduml OUTPUT end it "processes the PlantUML macro with localdir unwritable" do mock_localdir_unwritable expect { Asciidoctor.convert(<<~"INPUT", backend: :standoc, header_footer: true) }.to output(%r{not writable for PlantUML}).to_stderr #{ASCIIDOC_BLANK_HDR} [plantuml] .... @startuml Alice -> Bob: Authentication Request Bob --> Alice: Authentication Response Alice -> Bob: Another authentication Request Alice <-- Bob: another authentication Response @enduml .... INPUT mock_localdir_unwritable expect(xmlpp(strip_guid(Asciidoctor.convert(<<~"INPUT", backend: :standoc, header_footer: true)))).to be_equivalent_to xmlpp(<<~"OUTPUT") #{ASCIIDOC_BLANK_HDR} [plantuml] .... @startuml Alice -> Bob: Authentication Request Bob --> Alice: Authentication Response Alice -> Bob: Another authentication Request Alice <-- Bob: another authentication Response @enduml .... INPUT #{BLANK_HDR} @startuml Alice -> Bob: Authentication Request Bob --> Alice: Authentication Response Alice -> Bob: Another authentication Request Alice <-- Bob: another authentication Response @enduml OUTPUT end private def mock_plantuml_disabled expect(Asciidoctor::Standoc::PlantUMLBlockMacroBackend).to receive(:plantuml_installed?) do raise "PlantUML not installed" false end end def mock_localdir_unwritable expect(Asciidoctor::Standoc::Utils).to receive(:localdir) do "/" end.exactly(2).times end def mock_localdir_unwritable expect(File).to receive(:writable?) do false end end end