require "spec_helper" RSpec.describe Metanorma::ISO do it "removes empty text elements" do input = <<~INPUT #{ASCIIDOC_BLANK_HDR} == {blank} INPUT output = <<~OUTPUT #{BLANK_HDR} OUTPUT expect(xmlpp(strip_guid(Asciidoctor.convert(input, *OPTIONS)))) .to be_equivalent_to xmlpp(output) end it "processes stem-only terms as admitted" do input = <<~INPUT #{ASCIIDOC_BLANK_HDR} == Terms and Definitions === stem:[t_90] stem:[t_91] Time INPUT output = <<~OUTPUT #{BLANK_HDR} Terms and definitions #{TERM_BOILERPLATE} t 90 t 91

Time

OUTPUT expect(xmlpp(strip_guid(Asciidoctor.convert(input, *OPTIONS)))) .to be_equivalent_to xmlpp(output) end it "moves term domains out of the term definition paragraph" do input = <<~INPUT #{ASCIIDOC_BLANK_HDR} == Terms and Definitions === Tempus domain:[relativity] Time INPUT output = <<~OUTPUT #{BLANK_HDR} Terms and definitions#{TERM_BOILERPLATE} Tempus relativity

Time

OUTPUT expect(xmlpp(strip_guid(Asciidoctor.convert(input, *OPTIONS)))) .to be_equivalent_to xmlpp(output) end it "permits multiple blocks in term definition paragraph" do input = <<~INPUT = Document title Author :docfile: test.adoc :nodoc: :novalid: :stem: :no-isobib: == Terms and Definitions === stem:[t_90] [.definition] -- [stem] ++++ t_A ++++ This paragraph is extraneous -- INPUT output = <<~OUTPUT #{BLANK_HDR} Terms and definitions #{TERM_BOILERPLATE} t 90 t A

This paragraph is extraneous

OUTPUT expect(xmlpp(strip_guid(Asciidoctor.convert(input, *OPTIONS)))) .to be_equivalent_to xmlpp(output) end it "keeps any initial boilerplate from terms and definitions" do input = <<~INPUT #{ASCIIDOC_BLANK_HDR} == Terms and Definitions I am boilerplate * So am I === Time This paragraph is extraneous INPUT output = <<~OUTPUT #{BLANK_HDR} Terms and definitions#{TERM_BOILERPLATE}

I am boilerplate

Time

This paragraph is extraneous

OUTPUT expect(xmlpp(strip_guid(Asciidoctor.convert(input, *OPTIONS)))) .to be_equivalent_to xmlpp(output) end it "moves notes inside preceding blocks, if they are not at clause end, and the blocks are not delimited" do input = <<~INPUT #{ASCIIDOC_BLANK_HDR} [stem] ++++ r = 1 % r = 1 % ++++ NOTE: That formula does not do much Indeed. INPUT output = <<~OUTPUT #{BLANK_HDR} r = 1 % r = 1 %

That formula does not do much

Indeed.

OUTPUT expect(xmlpp(strip_guid(Asciidoctor.convert(input, *OPTIONS)))) .to be_equivalent_to xmlpp(output) end it "does not move notes inside preceding blocks, if they are at clause end" do input = <<~INPUT #{ASCIIDOC_BLANK_HDR} [source,ruby] [1...x].each do |y| puts y end NOTE: That loop does not do much INPUT output = <<~OUTPUT #{BLANK_HDR} [1...x].each do |y| puts y end

That loop does not do much

OUTPUT expect(xmlpp(strip_guid(Asciidoctor.convert(input, *OPTIONS)))) .to be_equivalent_to xmlpp(output) end it "converts xrefs to references into erefs" do input = <<~INPUT #{ASCIIDOC_BLANK_HDR} <> [bibliography] == Normative References * [[[iso216,ISO 216:2001]]], _Reference_ INPUT output = <<~OUTPUT #{BLANK_HDR} Foreword

Normative references

The following documents are referred to in the text in such a way that some or all of their content constitutes requirements of this document. For dated references, only the edition cited applies. For undated references, the latest edition of the referenced document (including any amendments) applies.

Reference ISO 216:2001 216 2001 International Organization for Standardization ISO
OUTPUT expect(xmlpp(strip_guid(Asciidoctor.convert(input, *OPTIONS)))) .to be_equivalent_to xmlpp(output) end it "extracts localities from erefs" do input = <<~INPUT #{ASCIIDOC_BLANK_HDR} <> [bibliography] == Normative References * [[[iso216,ISO 216]]], _Reference_ INPUT output = <<~OUTPUT #{BLANK_HDR} Foreword

3 9 11 33 the reference

Normative references

The following documents are referred to in the text in such a way that some or all of their content constitutes requirements of this document. For dated references, only the edition cited applies. For undated references, the latest edition of the referenced document (including any amendments) applies.

Reference ISO 216 216 International Organization for Standardization ISO
OUTPUT expect(xmlpp(strip_guid(Asciidoctor.convert(input, *OPTIONS)))) .to be_equivalent_to xmlpp(output) end it "strips type from xrefs" do input = <<~INPUT #{ASCIIDOC_BLANK_HDR} <> [bibliography] == Clause * [[[iso216,ISO 216]]], _Reference_ INPUT output = <<~OUTPUT #{BLANK_HDR} Foreword

Bibliography Reference ISO 216 216 International Organization for Standardization ISO OUTPUT expect(xmlpp(strip_guid(Asciidoctor.convert(input, *OPTIONS)))) .to be_equivalent_to xmlpp(output) end it "processes localities in term sources" do input = <<~INPUT #{ASCIIDOC_BLANK_HDR} == Terms and Definitions === Term1 Definition [.source] <> INPUT output = <<~OUTPUT #{BLANK_HDR} Terms and definitions #{TERM_BOILERPLATE} Term1

Definition

1
OUTPUT expect(xmlpp(strip_guid(Asciidoctor.convert(input, *OPTIONS)))) .to be_equivalent_to xmlpp(output) end it "removes extraneous material from Normative References" do input = <<~INPUT #{ASCIIDOC_BLANK_HDR} [bibliography] == Normative References This is extraneous information * [[[iso216,ISO 216]]], _Reference_ INPUT output = <<~OUTPUT #{BLANK_HDR} Normative references

The following documents are referred to in the text in such a way that some or all of their content constitutes requirements of this document. For dated references, only the edition cited applies. For undated references, the latest edition of the referenced document (including any amendments) applies.

Reference ISO 216 216 International Organization for Standardization ISO
OUTPUT expect(xmlpp(strip_guid(Asciidoctor.convert(input, *OPTIONS)))) .to be_equivalent_to xmlpp(output) end it "inserts IDs into paragraphs" do input = <<~INPUT #{ASCIIDOC_BLANK_HDR} Paragraph INPUT output = <<~OUTPUT #{BLANK_HDR}

Paragraph

OUTPUT expect(xmlpp(strip_guid(Asciidoctor.convert(input, *OPTIONS)))) .to be_equivalent_to xmlpp(output) end it "inserts IDs into notes" do input = <<~INPUT #{ASCIIDOC_BLANK_HDR} [example] ==== NOTE: This note has no ID ==== INPUT output = <<~OUTPUT #{BLANK_HDR}

This note has no ID

OUTPUT expect(xmlpp(strip_guid(Asciidoctor.convert(input, *OPTIONS)))) .to be_equivalent_to xmlpp(output) end it "moves table key inside table" do input = <<~INPUT #{ASCIIDOC_BLANK_HDR} |=== |a |b |c |=== Key a:: b INPUT output = <<~OUTPUT #{BLANK_HDR}
a

b

a b c
OUTPUT expect(xmlpp(strip_guid(Asciidoctor.convert(input, *OPTIONS)))) .to be_equivalent_to xmlpp(output) end it "processes headerrows attribute for table without header rows" do input = <<~INPUT #{ASCIIDOC_BLANK_HDR} [headerrows=3] |=== |a |b |c |a |b |c |a |b |c |a |b |c |=== INPUT output = <<~OUTPUT #{BLANK_HDR}
a b c
a b c
a b c
a b c
OUTPUT expect(xmlpp(strip_guid(Asciidoctor.convert(input, *OPTIONS)))) .to be_equivalent_to xmlpp(output) end it "processes headerrows attribute for table with header rows" do input = <<~INPUT #{ASCIIDOC_BLANK_HDR} [headerrows=3] |=== |a |b |c |a |b |c |a |b |c |a |b |c |=== INPUT output = <<~OUTPUT #{BLANK_HDR}
a b c
a b c
a b c
a b c
OUTPUT expect(xmlpp(strip_guid(Asciidoctor.convert(input, *OPTIONS)))) .to be_equivalent_to xmlpp(output) end it "moves table notes inside table" do input = <<~INPUT #{ASCIIDOC_BLANK_HDR} |=== |a |b |c |=== NOTE: Note 1 NOTE: Note 2 INPUT output = <<~OUTPUT #{BLANK_HDR}

Note 1

Note 2

a b c
OUTPUT expect(xmlpp(strip_guid(Asciidoctor.convert(input, *OPTIONS)))) .to be_equivalent_to xmlpp(output) end it "moves formula key inside formula" do input = <<~INPUT #{ASCIIDOC_BLANK_HDR} [stem] ++++ Formula ++++ where a:: b INPUT output = <<~OUTPUT #{BLANK_HDR} F or μ l a
a

b

OUTPUT expect(xmlpp(strip_guid(Asciidoctor.convert(input, *OPTIONS)))) .to be_equivalent_to xmlpp(output) end it "moves footnotes inside figures" do input = <<~INPUT #{ASCIIDOC_BLANK_HDR} image::spec/examples/rice_images/rice_image1.png[] footnote:[This is a footnote to a figure] footnote:[This is another footnote to a figure] INPUT output = <<~OUTPUT #{BLANK_HDR}

This is a footnote to a figure

This is another footnote to a figure

OUTPUT expect(xmlpp(strip_guid(Asciidoctor.convert(input, *OPTIONS)))) .to be_equivalent_to xmlpp(output) end it "moves figure key inside figure" do input = <<~INPUT #{ASCIIDOC_BLANK_HDR} image::spec/examples/rice_images/rice_image1.png[] Key a:: b INPUT output = <<~OUTPUT #{BLANK_HDR}
a

b

OUTPUT expect(xmlpp(strip_guid(Asciidoctor.convert(input, *OPTIONS)))) .to be_equivalent_to xmlpp(output) end it "numbers bibliographic notes and footnotes sequentially" do input = <<~INPUT #{ASCIIDOC_BLANK_HDR} footnote:[Footnote] [bibliography] == Normative References * [[[iso123,ISO 123:--]]] footnote:[The standard is in press] _Standard_ == Clause footnote:[Footnote2] INPUT output = <<~OUTPUT #{BLANK_HDR} Foreword

Footnote

Clause

Footnote2

Normative references

The following documents are referred to in the text in such a way that some or all of their content constitutes requirements of this document. For dated references, only the edition cited applies. For undated references, the latest edition of the referenced document (including any amendments) applies.

Standard ISO 123:— 123 International Organization for Standardization ISO The standard is in press
OUTPUT expect(xmlpp(strip_guid(Asciidoctor.convert(input, *OPTIONS)))) .to be_equivalent_to xmlpp(output) end it "defaults section obligations" do input = <<~INPUT #{ASCIIDOC_BLANK_HDR} == Clause Text [appendix] == Clause Text INPUT output = <<~OUTPUT #{BLANK_HDR} Clause

Text

Clause

Text

OUTPUT expect(xmlpp(strip_guid(Asciidoctor.convert(input, *OPTIONS)))) .to be_equivalent_to xmlpp(output) end it "extends clause levels past 5" do input = <<~INPUT #{ASCIIDOC_BLANK_HDR} == Clause1 === Clause2 ==== Clause3 ===== Clause4 ====== Clause 5 [level=6] ====== Clause 6 [level=7] ====== Clause 7A [level=7] ====== Clause 7B [level=6] ====== Clause 6B ====== Clause 5B INPUT output = <<~OUTPUT #{BLANK_HDR} Clause1 Clause2 Clause3 Clause4 Clause 5 Clause 6 Clause 7A Clause 7B Clause 6B Clause 5B OUTPUT expect(xmlpp(strip_guid(Asciidoctor.convert(input, *OPTIONS)))) .to be_equivalent_to xmlpp(output) end it "reorders references in bibliography, and renumbers citations accordingly" do input = <<~INPUT #{ASCIIDOC_BLANK_HDR} == Clause 1 <> <> <> <> <> <> <> <> <> <> <> <> [bibliography] == Bibliography [bibliography] === Clause 1 * [[[ref3,IEC 123]]], _Standard IEC 123_ * [[[ref5,20]]], _Standard 10_ * [[[ref1,ISO 123]]], _Standard ISO 123_ * [[[ref1a,ISO 123-100]]], _Standard ISO 123_ * [[[ref1b,ISO/TS 123-1]]], _Standard ISO 123_ * [[[ref4,GB 123]]], _Standard GB 123_ * [[[ref2,ISO/IEC 123]]], _Standard ISO/IEC 123_ * [[[ref6,(B)]]], _Standard 20_ * [[[ref7,(A)]]], _Standard 30_ [bibliography] === {blank} * [[[ref15,20]]], _Standard 10_ * [[[ref14,GB 123]]], _Standard GB 123_ * [[[ref13,IEC 123]]], _Standard IEC 123_ * [[[ref11,ISO 123]]], _Standard ISO 123_ * [[[ref10,ISO/IEC 123]]], _Standard ISO/IEC 123_ * [[[ref16,(B)]]], _Standard 20_ * [[[ref17,(A)]]], _Standard 30_ INPUT output = <<~OUTPUT #{BLANK_HDR} Clause 1

Bibliography Clause 1 Standard ISO 123 ISO 123 123 International Organization for Standardization ISO Standard ISO/IEC 123 ISO/IEC 123 123 International Organization for Standardization ISO International Electrotechnical Commission IEC Standard ISO 123 ISO/TS 123-1 123-1 International Organization for Standardization ISO TS Standard ISO 123 ISO 123-100 123-100 International Organization for Standardization ISO Standard IEC 123 IEC 123 123 International Electrotechnical Commission IEC Standard GB 123 GB 123 123 Standard 10 [7] Standard 30 [A] Standard 20 [B] Standard ISO 123 ISO 123 123 International Organization for Standardization ISO Standard ISO/IEC 123 ISO/IEC 123 123 International Organization for Standardization ISO International Electrotechnical Commission IEC Standard IEC 123 IEC 123 123 International Electrotechnical Commission IEC Standard GB 123 GB 123 123 Standard 10 [14] Standard 30 [A] Standard 20 [B] OUTPUT expect(xmlpp(strip_guid(Asciidoctor.convert(input, *OPTIONS)))) .to be_equivalent_to xmlpp(output) end context "terms & definitions boilerplate" do it "places normal terms & definitions boilerplate in flat clause" do input = <<~INPUT #{ASCIIDOC_BLANK_HDR} == Terms and definitions === Term1 INPUT output = <<~OUTPUT #{BLANK_HDR} Terms and definitions

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

ISO and IEC maintain terminology databases for use in standardization at the following addresses:

  • ISO Online browsing platform: available at

  • IEC Electropedia: available at

Term1
OUTPUT expect(xmlpp(strip_guid(Asciidoctor.convert(input, *OPTIONS)))) .to be_equivalent_to xmlpp(output) end it "places normal terms & definitions boilerplate in multi-clause" do input = <<~INPUT #{ASCIIDOC_BLANK_HDR} == Terms and definitions === Normal Terms ==== Term1 === Abnormal terms ==== Term 2 INPUT output = <<~OUTPUT #{BLANK_HDR} Terms and definitions

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

ISO and IEC maintain terminology databases for use in standardization at the following addresses:

  • ISO Online browsing platform: available at

  • IEC Electropedia: available at

Normal Terms Term1 Abnormal terms Term 2
OUTPUT expect(xmlpp(strip_guid(Asciidoctor.convert(input, *OPTIONS)))) .to be_equivalent_to xmlpp(output) end it "places normal terms & definitions boilerplate in single clause that excludes symbols" do input = <<~INPUT #{ASCIIDOC_BLANK_HDR} == Terms, definitions, symbols and abbreviated terms === Terms and definitions ==== Normal Terms ===== Term1 ==== Abnormal terms ===== Term 2 === Symbols and abbreviated terms INPUT output = <<~OUTPUT #{BLANK_HDR} Terms, definitions, symbols and abbreviated terms Terms and definitions

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

ISO and IEC maintain terminology databases for use in standardization at the following addresses:

  • ISO Online browsing platform: available at

  • IEC Electropedia: available at

Normal Terms Term1 Abnormal terms Term 2
Symbols and abbreviated terms
OUTPUT expect(xmlpp(strip_guid(Asciidoctor.convert(input, *OPTIONS)))) .to be_equivalent_to xmlpp(output) end it "places normal terms & definitions boilerplate in first of multiple clauses that excludes symbols" do input = <<~INPUT #{ASCIIDOC_BLANK_HDR} == Terms, definitions, symbols and abbreviated terms === Terms and definitions ==== Term1 [heading=terms] === Other Terms ==== Term 2 === Symbols and abbreviated terms INPUT output = <<~OUTPUT #{BLANK_HDR} Terms, definitions, symbols and abbreviated terms Terms and definitions

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

ISO and IEC maintain terminology databases for use in standardization at the following addresses:

  • ISO Online browsing platform: available at

  • IEC Electropedia: available at

Term1
Other Terms Term 2 Symbols and abbreviated terms
OUTPUT expect(xmlpp(strip_guid(Asciidoctor.convert(input, *OPTIONS)))) .to be_equivalent_to xmlpp(output) end it "modifies normal terms & definitions boilerplate in vocabulary document" do input = <<~INPUT = Document title Author :docfile: test.adoc :nodoc: :novalid: :no-isobib: :docsubtype: vocabulary == Terms and definitions === Term1 INPUT output = <<~OUTPUT #{BLANK_HDR.sub(%r{}, 'vocabulary')} Terms and definitions

ISO and IEC maintain terminology databases for use in standardization at the following addresses:

  • ISO Online browsing platform: available at

  • IEC Electropedia: available at

Term1
OUTPUT expect(xmlpp(strip_guid(Asciidoctor.convert(input, *OPTIONS)))) .to be_equivalent_to xmlpp(output) end end end