require "spec_helper" RSpec.describe Metanorma::Standoc do it "processes the Metanorma::Standoc concept and related macros" do input = <<~INPUT #{ASCIIDOC_BLANK_HDR} {{clause1}} term:[clause1] {{clause1,w\[o\]rd}} term:[clause1,w[o]rd] {{clause1,w\[o\]rd,term}} {{blah}} term:[blah] {{blah,word}} term:[blah,word] {{blah,term,word}} {{blah,term,word,xref}} {{blah,term,word,xref,options="noital,noref,nolinkmention,nolinkref"}} {{blah,term,word,xref,options="ital,ref,linkmention,linkref"}} related:contrast[blah] [[clause1]] == Clause Terms are defined here INPUT output = <<~OUTPUT #{BLANK_HDR} Foreword

term clause1 not resolved via ID clause1 term clause1 not resolved via ID clause1 term clause1, display w[o]rd not resolved via ID clause1 term clause1, display w[o]rd not resolved via ID clause1 term clause1, display w[o]rd not resolved via ID clause1 term blah not resolved via ID blah term blah not resolved via ID blah term blah , display word not resolved via ID blah term blah , display word not resolved via ID blah term blah , display term not resolved via ID blah term blah , display term not resolved via ID blah term blah , display term not resolved via ID blah term blah , display term not resolved via ID blah

term blah not resolved via ID blah
Clause

Terms are defined here

OUTPUT expect(xmlpp(strip_guid(Asciidoctor.convert(input, *OPTIONS)))) .to be_equivalent_to xmlpp(output) end it "processes the Metanorma::Standoc concept macros for acronyms" do input = <<~INPUT #{ASCIIDOC_BLANK_HDR} {{Clause1}} {{Clause1,Clause 1}} {{Clause 2}} {{Clause 2,Clause 1}} {{<>,Clause 2}} symbol:[Clause1] symbol:[Clause1,word] symbol:[Clause 2] symbol:[Clause 2,word] {{<>,word}} {{<>,word,term}} {{<>,word,term,xref}} {{<>,word,term,xref,options="noital,noref,nolinkmention,nolinkref"}} {{<>,word,term,xref,options="ital,ref,linkmention,linkref"}} == Terms and definitions === Clause1 == Symbols and Abbreviated Terms Clause1:: A [[Clause2]]Clause 2:: C INPUT output = <<~OUTPUT #{BLANK_HDR} Foreword

Clause1 Clause1 Clause1 Clause 1 Clause 2 Clause 2 Clause 2 Clause 1 Clause 2 Clause 2

Clause1 Clause1 Clause1 word Clause 2 Clause 2 Clause 2 word

word word word term word term xref word term xref word term xref

Terms and definitions

For the purposes of this document, the following terms and definitions apply.

Clause1
Symbols and abbreviated terms
Clause1

A

Clause 2

C

OUTPUT expect(xmlpp(strip_guid(Asciidoctor.convert(input, *OPTIONS)))) .to be_equivalent_to xmlpp(output) end it "processes the concept and related macros with xrefs" do input = <<~INPUT #{ASCIIDOC_BLANK_HDR} {{<>}} {{<>,w\[o\]rd}} {{<>,term,w\[o\]rd}} {{<>,term,w\[o\]rd,Clause #1}} related:supersedes[<>,term] [[clause1]] == Clause Terms are defined here INPUT output = <<~OUTPUT #{BLANK_HDR} Foreword

w[o]rd w[o]rd term w[o]rd term w[o]rd Clause #1

term
Clause

Terms are defined here

OUTPUT expect(xmlpp(strip_guid(Asciidoctor.convert(input, *OPTIONS)))) .to be_equivalent_to xmlpp(output) end it "processes the concept and related macros with erefs" do input = <<~INPUT #{ASCIIDOC_BLANK_HDR} {{<>}} {{<>,word}} {{<>,term,word}} {{<>,term,word,Clause #1}} {{<>}} {{<>,word}} {{<>,term,word}} {{<>}} {{<>,word}} {{<>,term,word,Clause #1}} related:narrower[<>,term] [bibliography] == Bibliography * [[[blah,blah]]] _Blah_ INPUT output = <<~OUTPUT #{BLANK_HDR} Foreword

word word term word term word Clause #1 3.1 word word 3.1 term word 3.1 3.1 a word word 3.1 a term word 3.1 a Clause #1

term 3.1 a
Bibliography Blah blah OUTPUT expect(xmlpp(strip_guid(Asciidoctor.convert(input, *OPTIONS)))) .to be_equivalent_to xmlpp(output) end it "processes the concept and related macros with termbase" do input = <<~INPUT #{ASCIIDOC_BLANK_HDR} {{<>}} {{<>,word}} {{<>,term,word}} {{<>,term,word,Clause #1}} related:see[<>,term] INPUT output = <<~OUTPUT #{BLANK_HDR}

word word term word term word Clause #1

term
OUTPUT expect(xmlpp(strip_guid(Asciidoctor.convert(input, *OPTIONS)))) .to be_equivalent_to xmlpp(output) end it "processes the concept macros with disambiguation for math symbols" do input = <<~INPUT #{ASCIIDOC_BLANK_HDR} [[clause1]] == Symbols and Abbreviated Terms stem:[|~ x ~|]:: A function that returns the smallest integer greater than or equal to stem:[x]; also known as the _ceiling_ function. stem:[|__ x __|]:: A function that returns the largest integer less than or equal to stem:[x]; also known as the _floor_ function. INPUT output = <<~OUTPUT #{BLANK_HDR} Symbols and abbreviated terms
x

A function that returns the largest integer less than or equal to x ; also known as the floor function.

x

A function that returns the smallest integer greater than or equal to x ; also known as the ceiling function.

OUTPUT expect(xmlpp(strip_guid(Asciidoctor.convert(input, *OPTIONS)))) .to be_equivalent_to xmlpp(output) end describe "term inline macros" do subject(:convert) do xmlpp( strip_guid( Asciidoctor.convert( input, *OPTIONS ), ), ) end let(:input) do <<~XML #{ASCIIDOC_BLANK_HDR} == Terms and Definitions === name == Main term:[name,name2] is a term {{name,name2}} is a term related:equivalent[name] XML end let(:output) do <<~XML #{BLANK_HDR} Terms and definitions

For the purposes of this document, the following terms and definitions apply.

name
Main

name name2 is a term

name name2 is a term

name name
XML end it "converts macro into the correct xml" do expect(convert).to(be_equivalent_to(xmlpp(output))) end context "default params" do let(:input) do <<~XML #{ASCIIDOC_BLANK_HDR} == Terms and Definitions === name == Main term:[name] is a term {{name}} is a term XML end let(:output) do <<~XML #{BLANK_HDR} Terms and definitions

For the purposes of this document, the following terms and definitions apply.

name
Main

name name is a term

name name is a term

XML end it "uses `name` as termref name" do expect(convert).to(be_equivalent_to(xmlpp(output))) end end context "terms with index terms" do let(:input) do <<~XML #{ASCIIDOC_BLANK_HDR} == Terms and Definitions === name(((name))) == Main term:[name] is a term {{name}} is a term XML end let(:output) do <<~XML #{BLANK_HDR} Terms and definitions

For the purposes of this document, the following terms and definitions apply.

name name
Main

name name is a term

name name is a term

XML end it "strips index terms in terms anchors" do expect(convert).to(be_equivalent_to(xmlpp(output))) end end context "multiply exising ids in document" do let(:input) do <<~XML #{ASCIIDOC_BLANK_HDR} == Terms and Definitions === name === name2 [[term-name]] == Main paragraph [[term-name2]] == Second term:[name] is a term term:[name2] is a term {{name}} is a term {{name2}} is a term XML end let(:output) do <<~XML #{BLANK_HDR} Terms and definitions

For the purposes of this document, the following terms and definitions apply.

name name2
Main

paragraph

Second

name name is a term name2 name2 is a term name name is a term name2 name2 is a term

XML end it "generates unique ids which do not match existing ids" do expect(convert).to(be_equivalent_to(xmlpp(output))) end end context "when missing actual ref" do let(:input) do <<~XML #{ASCIIDOC_BLANK_HDR} == Terms and Definitions === name identity [[name-check]] === name check paragraph term:[name check] is a term term:[name identity] is a term Moreover, term:[missing] is a term {{name check}} is a term {{name identity}} is a term Moreover, {{missing}} is a term related:equivalent[missing] XML end let(:output) do <<~XML #{BLANK_HDR} Terms and definitions

For the purposes of this document, the following terms and definitions apply.

name identity name check term missing not resolved via ID missing

paragraph

name check name check is a term

name identity name identity is a term

Moreover, term missing not resolved via ID missing is a term

name check name check is a term

name identity name identity is a term

Moreover, term missing not resolved via ID missing is a term

XML end it "generates unique ids which do not match existing ids" do expect(convert).to(be_equivalent_to(xmlpp(output))) end end end end