require "spec_helper" RSpec.describe IsoDoc do it "cross-references external documents" do input = <<~INPUT

a#b

OUTPUT html = <<~OUTPUT #{HTML_HDR}

Foreword

a#b

OUTPUT doc = <<~OUTPUT


Foreword

a#b

OUTPUT expect(xmlpp(IsoDoc::PresentationXMLConvert.new({}) .convert("test", input, true))).to be_equivalent_to xmlpp(presxml) expect(xmlpp(IsoDoc::HtmlConvert.new({}) .convert("test", presxml, true))).to be_equivalent_to xmlpp(html) expect(xmlpp(IsoDoc::WordConvert.new({}) .convert("test", presxml, true) .sub(/^.*
/m, '
') .sub(%r{
.*$}m, "
"))).to be_equivalent_to xmlpp(doc) end it "warns of missing crossreference" do i = <<~INPUT

INPUT expect { IsoDoc::PresentationXMLConvert.new({}).convert("test", i, true) } .to output(/No label has been processed for ID N1/).to_stderr end it "does not warn of missing crossreference if text is supplied" do i = <<~INPUT

abc INPUT expect { IsoDoc::HtmlConvert.new({}).convert("test", i, true) } .not_to output(/No label has been processed for ID N1/).to_stderr end it "cross-references notes" do input = <<~INPUT

These results are based on a study carried out on three different types of kernel.

Preparatory

These results are based on a study carried out on three different types of kernel.

Scope

These results are based on a study carried out on three different types of kernel.

Widgets

These results are based on a study carried out on three different types of kernel.

These results are based on a study carried out on three different types of kernel.

These results are based on a study carried out on three different types of kernel.

These results are based on a study carried out on three different types of kernel.

These results are based on a study carried out on three different types of kernel.

INPUT output = <<~OUTPUT

Introduction, Note Preparatory, Note Clause 1, Note Clause 3.1, Note 1 Clause 3.1, Note 2 Annex A.1, Note Annex A.2, Note 1 Annex A.2, Note 2

NOTE

These results are based on a study carried out on three different types of kernel.

Preparatory NOTE

These results are based on a study carried out on three different types of kernel.

1. <tab/> Scope NOTE

These results are based on a study carried out on three different types of kernel.

Note

2. 3. <tab/> Widgets 3.1. NOTE 1

These results are based on a study carried out on three different types of kernel.

NOTE 2

These results are based on a study carried out on three different types of kernel.

Note 1 Note 2

<strong>Annex A</strong> <br/> (informative) A.1. NOTE

These results are based on a study carried out on three different types of kernel.

A.2. NOTE 1

These results are based on a study carried out on three different types of kernel.

NOTE 2

These results are based on a study carried out on three different types of kernel.

OUTPUT expect(xmlpp(IsoDoc::PresentationXMLConvert.new({}) .convert("test", input, true))).to be_equivalent_to xmlpp(output) end it "cross-references figures" do input = <<~INPUT

Split-it-right sample divider
Preparatory
Split-it-right sample divider
Scope
Split-it-right sample divider

Widgets
Split-it-right sample divider

pseudocode

Source! Code! A B C A B C
Split-it-right sample divider

Split-it-right sample divider
Split-it-right sample divider
Split-it-right sample divider
Source! Code! A B C
INPUT output = <<~OUTPUT

Figure 1 Figure (??) Figure 2 Figure 3 Figure 4 Figure 5 Figure 6 [note51] Figure A.1 Figure (??) Figure A.2 Figure A.3

Figure 1 — Split-it-right sample divider
Preparatory
Split-it-right sample divider
1. <tab/> Scope
Figure 2 — Split-it-right sample divider

Figure 2

2. 3. <tab/> Widgets 3.1.
Figure 3 — Split-it-right sample divider
Figure 4

pseudocode

Figure 5 — Source! Code! A B C EXAMPLE A B C
Figure 6 — Split-it-right sample divider

Figure 3 Figure 6

<strong>Annex A</strong> <br/> (informative) A.1.
Figure A.1 — Split-it-right sample divider
A.2.
Split-it-right sample divider
Figure A.2 — Split-it-right sample divider
Figure A.3 — Source! Code! A B C
OUTPUT expect(xmlpp(IsoDoc::PresentationXMLConvert.new({}) .convert("test", input, true))).to be_equivalent_to xmlpp(output) end it "cross-references subfigures" do input = <<~INPUT

Scope Widgets
Split-it-right sample divider
Split-it-right sample divider

Split-it-right sample divider
Split-it-right sample divider
INPUT output = <<~OUTPUT

Figure 1 Figure 1-1 Figure 1-2 Figure A.1 Figure A.1-1 Figure A.1-2

1. <tab/> Scope 2. 3. <tab/> Widgets 3.1.
Figure 1-1 — Split-it-right sample divider
Figure 1-2 — Split-it-right sample divider

Figure 1-1 Figure 1-2

<strong>Annex A</strong> <br/> (informative) A.1. A.2.
Figure A.1-1 — Split-it-right sample divider
Figure A.1-2 — Split-it-right sample divider
OUTPUT expect(xmlpp(IsoDoc::PresentationXMLConvert.new({}) .convert("test", input, true))).to be_equivalent_to xmlpp(output) end it "cross-references examples" do input = <<~INPUT

Hello

Preparatory

Hello

Scope

Hello

Widgets

Hello

Hello

Hello

Hello

Hello

INPUT output = <<~OUTPUT

Introduction, Example Preparatory, Example (??) Clause 1, Example Clause 3.1, Example 1 Clause 3.1, Example (??) Annex A.1, Example Annex A.2, Example (??) Annex A.2, Example 1

EXAMPLE

Hello

Preparatory EXAMPLE

Hello

1. <tab/> Scope EXAMPLE

Hello

Example

2. 3. <tab/> Widgets 3.1. EXAMPLE 1

Hello

EXAMPLE

Hello

Example 1 Example (??)

<strong>Annex A</strong> <br/> (informative) A.1. EXAMPLE

Hello

A.2. EXAMPLE

Hello

EXAMPLE 1

Hello

OUTPUT expect(xmlpp(IsoDoc::PresentationXMLConvert.new({}) .convert("test", input, true))).to be_equivalent_to xmlpp(output) end it "cross-references formulae" do input = <<~INPUT

r = 1 % Preparatory r = 1 %
Scope r = 1 %

Widgets r = 1 % r = 1 %

r = 1 % r = 1 % r = 1 %
INPUT output = <<~OUTPUT

Introduction, Formula (1) Preparatory, Formula ((??)) Clause 1, Formula (2) Clause 3.1, Formula (3) Clause 3.1, Formula (4) Formula (A.1) Formula ((??)) Formula (A.2)

1 r = 1 % Preparatory r = 1 %
1. <tab/> Scope 2 r = 1 %

Formula (2)

2. 3. <tab/> Widgets 3.1. 3 r = 1 % 4 r = 1 %

Formula (3) Formula (4)

<strong>Annex A</strong> <br/> (informative) A.1. A.1 r = 1 % A.2. r = 1 % A.2 r = 1 %
OUTPUT expect(xmlpp(IsoDoc::PresentationXMLConvert.new({}) .convert("test", input, true))).to be_equivalent_to xmlpp(output) end it "cross-references requirements" do input = <<~INPUT

r = 1 % Preparatory r = 1 %
Scope r = 1 %

Widgets r = 1 % r = 1 %

r = 1 % r = 1 % r = 1 %
INPUT output = <<~OUTPUT

Introduction, Requirement 1 Preparatory, Requirement (??) Clause 1, Requirement 2 Clause 3.1, Requirement 3 Clause 3.1, Requirement 4 Requirement A.1 Requirement (??) Requirement A.2

Requirement 1 r = 1 % Preparatory Requirement r = 1 %
1. <tab/> Scope Requirement 2 r = 1 %

Requirement 2

2. 3. <tab/> Widgets 3.1. Requirement 3 r = 1 % Requirement 4 r = 1 %

Requirement 3 Requirement 4

<strong>Annex A</strong> <br/> (informative) A.1. Requirement A.1 r = 1 % A.2. Requirement r = 1 % Requirement A.2 r = 1 %
OUTPUT expect(xmlpp(IsoDoc::PresentationXMLConvert.new({}) .convert("test", input, true))).to be_equivalent_to xmlpp(output) end it "cross-references recommendations" do input = <<~INPUT

r = 1 % Preparatory r = 1 %
Scope r = 1 %

Widgets r = 1 % r = 1 %

r = 1 % r = 1 % r = 1 %
INPUT output = <<~OUTPUT

Introduction, Recommendation 1 Preparatory, Recommendation (??) Clause 1, Recommendation 2 Clause 3.1, Recommendation 3 Clause 3.1, Recommendation 4 Recommendation A.1 Recommendation (??) Recommendation A.2

Recommendation 1 r = 1 % Preparatory Recommendation r = 1 %
1. <tab/> Scope Recommendation 2 r = 1 %

Recommendation 2

2. 3. <tab/> Widgets 3.1. Recommendation 3 r = 1 % Recommendation 4 r = 1 %

Recommendation 3 Recommendation 4

<strong>Annex A</strong> <br/> (informative) A.1. Recommendation A.1 r = 1 % A.2. Recommendation r = 1 % Recommendation A.2 r = 1 %
OUTPUT expect(xmlpp(IsoDoc::PresentationXMLConvert.new({}) .convert("test", input, true))).to be_equivalent_to xmlpp(output) end it "cross-references permissions" do input = <<~INPUT

r = 1 % Preparatory r = 1 %
Scope r = 1 %

Widgets r = 1 % r = 1 %

r = 1 % r = 1 % r = 1 %
INPUT output = <<~OUTPUT

Introduction, Permission 1 Preparatory, Permission (??) Clause 1, Permission 2 Clause 3.1, Permission 3 Clause 3.1, Permission 4 Permission A.1 Permission (??) Permission A.2

Permission 1 r = 1 % Preparatory Permission r = 1 %
1. <tab/> Scope Permission 2 r = 1 %

Permission 2

2. 3. <tab/> Widgets 3.1. Permission 3 r = 1 % Permission 4 r = 1 %

Permission 3 Permission 4

<strong>Annex A</strong> <br/> (informative) A.1. Permission A.1 r = 1 % A.2. Permission r = 1 % Permission A.2 r = 1 %
OUTPUT expect(xmlpp(IsoDoc::PresentationXMLConvert.new({}) .convert("test", input, true))).to be_equivalent_to xmlpp(output) end it "labels and cross-references nested requirements" do input = <<~INPUT

Preparatory Preparatory
INPUT output = <<~OUTPUT

Clause 1, Permission 1 Clause 1, Permission 1-1 Clause 1, Permission 1-1-1 Clause 1, Requirement 1-1 Clause 1, Recommendation 1-1 Permission A.1 Permission A.1-1 Permission A.1-1-1 Requirement A.1-1 Recommendation A.1-1

1. <tab/> Preparatory Permission 1 Permission 1-1 Permission 1-1-1 Requirement 1-1 Recommendation 1-1 <strong>Annex A</strong> <br/> (informative) <br/> <br/> <strong>Preparatory</strong> Permission A.1 Permission A.1-1 Permission A.1-1-1 Requirement A.1-1 Recommendation A.1-1
OUTPUT expect(xmlpp(IsoDoc::PresentationXMLConvert.new({}) .convert("test", input, true))).to be_equivalent_to xmlpp(output) end it "cross-references tables" do input = <<~INPUT

Repeatability and reproducibility of husked rice yield
Number of laboratories retained after eliminating outliers 13 11
Preparatory Repeatability and reproducibility of husked rice yield
Number of laboratories retained after eliminating outliers 13 11
Scope Repeatability and reproducibility of husked rice yield
Number of laboratories retained after eliminating outliers 13 11

Widgets Repeatability and reproducibility of husked rice yield
Number of laboratories retained after eliminating outliers 13 11
Repeatability and reproducibility of husked rice yield
Number of laboratories retained after eliminating outliers 13 11

Repeatability and reproducibility of husked rice yield
Number of laboratories retained after eliminating outliers 13 11
Repeatability and reproducibility of husked rice yield
Number of laboratories retained after eliminating outliers 13 11
Repeatability and reproducibility of husked rice yield
Number of laboratories retained after eliminating outliers 13 11
INPUT output = <<~OUTPUT

Table 1 Table (??) Table 2 Table 3 Table 4 Table A.1 Table (??) Table A.2

Table 1 — Repeatability and reproducibility of husked rice yield
Number of laboratories retained after eliminating outliers 13 11
Preparatory Table  — Repeatability and reproducibility of husked rice yield
Number of laboratories retained after eliminating outliers 13 11
1. <tab/> Scope Table 2 — Repeatability and reproducibility of husked rice yield
Number of laboratories retained after eliminating outliers 13 11

Table 2

2. 3. <tab/> Widgets 3.1. Table 3 — Repeatability and reproducibility of husked rice yield
Number of laboratories retained after eliminating outliers 13 11
Table 4 — Repeatability and reproducibility of husked rice yield
Number of laboratories retained after eliminating outliers 13 11

Table 3 Table 4

<strong>Annex A</strong> <br/> (informative) A.1. Table A.1 — Repeatability and reproducibility of husked rice yield
Number of laboratories retained after eliminating outliers 13 11
A.2. Table  — Repeatability and reproducibility of husked rice yield
Number of laboratories retained after eliminating outliers 13 11
Table A.2 — Repeatability and reproducibility of husked rice yield
Number of laboratories retained after eliminating outliers 13 11
OUTPUT expect(xmlpp(IsoDoc::PresentationXMLConvert.new({}) .convert("test", input, true))).to be_equivalent_to xmlpp(output) end it "cross-references term notes" do input = <<~INPUT

Scope waxy rice

The starch of waxy rice consists almost entirely of amylopectin. The kernels have a tendency to stick together after cooking.

nonwaxy rice

The starch of waxy rice consists almost entirely of amylopectin. The kernels have a tendency to stick together after cooking.

The starch of waxy rice consists almost entirely of amylopectin. The kernels have a tendency to stick together after cooking.

INPUT output = <<~OUTPUT

Clause 2.1, Note 1 Clause 2.2, Note 1 Clause 2.2, Note 2

1. <tab/> Scope 2. 2.1. waxy rice Note 1 to entry

The starch of waxy rice consists almost entirely of amylopectin. The kernels have a tendency to stick together after cooking.

2.2. nonwaxy rice Note 1 to entry

The starch of waxy rice consists almost entirely of amylopectin. The kernels have a tendency to stick together after cooking.

Note 2 to entry

The starch of waxy rice consists almost entirely of amylopectin. The kernels have a tendency to stick together after cooking.

OUTPUT expect(xmlpp(IsoDoc::PresentationXMLConvert.new({}) .convert("test", input, true))).to be_equivalent_to xmlpp(output) end it "cross-references sections" do input = <<~INPUT Foreword

This is a preamble

Introduction Introduction Subsection Text
Scope

Text

Terms, definitions, symbols and abbreviated terms Normal Terms Term2
Symbol
Definition
Symbol
Definition
Clause 4 Introduction Clause 4.2
Annex Annex A.1 Annex A.1a Normative References Bibliography Bibliography Subsection
INPUT output = <<~OUTPUT Foreword

This is a preamble#{' '} Introduction Subsection Introduction, 2 Clause 1 Clause 3 Clause 3.1 Clause 3.1.1 Clause 3.2 Clause 4 Clause 5 Clause 5.1 Clause 5.2 Annex A Annex A.1 Annex A.1.1 Annex B Annex B Annex B.1 Clause 2 Bibliography

Introduction Introduction Subsection Text
1. <tab/> Scope

Text

3. <tab/> Terms, definitions, symbols and abbreviated terms 3.1. <tab/> Normal Terms 3.1.1. Term2 3.2.
Symbol
Definition
4.
Symbol
Definition
5. <tab/> Clause 4 5.1. <tab/> Introduction 5.2. <tab/> Clause 4.2
<strong>Annex A</strong> <br/> (normative) <br/> <br/> <strong>Annex</strong> A.1. <tab/> Annex A.1 A.1.1. <tab/> Annex A.1a <strong>Annex B</strong> <br/> (informative) B. B.1. 2. <tab/> Normative References Bibliography Bibliography Subsection
OUTPUT expect(xmlpp(IsoDoc::PresentationXMLConvert.new({}) .convert("test", input, true))).to be_equivalent_to xmlpp(output) end it "cross-references lists" do input = <<~INPUT

  1. A

Preparatory
  1. A

Scope
  1. A

Widgets

    These results are based on a study carried out on three different types of kernel.

    These results are based on a study carried out on three different types of kernel.

    These results are based on a study carried out on three different types of kernel.

    These results are based on a study carried out on three different types of kernel.

    These results are based on a study carried out on three different types of kernel.

INPUT output = <<~OUTPUT

Introduction, List Preparatory, List Clause 1, List Clause 3.1, List 1 Clause 3.1, List 2 Annex A.1, List Annex A.2, List 1 Annex A.2, List 2

OUTPUT expect(xmlpp(Nokogiri::XML(IsoDoc::PresentationXMLConvert.new({}) .convert("test", input, true)) .at("//xmlns:foreword").to_xml)) .to be_equivalent_to xmlpp(output) end it "cross-references list items" do input = <<~INPUT

  1. A

Preparatory
  1. A

Scope
  1. A

Widgets
  1. A

  1. A

  1. A

  1. A

  1. A

INPUT output = <<~OUTPUT

Introduction, a) Preparatory, 1) Clause 1, i) Clause 3.1, List 1 a) Clause 3.1, List 2 I) Annex A.1, A) Annex A.2, List 1 iv) Annex A.2, List 2 a)

OUTPUT expect(xmlpp(Nokogiri::XML(IsoDoc::PresentationXMLConvert.new({}) .convert("test", input, true)) .at("//xmlns:foreword").to_xml)) .to be_equivalent_to xmlpp(output) end it "cross-references nested list items" do input = <<~INPUT

Scope
  1. A

    1. A

      1. A

        1. A

          1. A

            1. A

INPUT output = <<~OUTPUT

Clause 1, a) Clause 1, a.1) Clause 1, a.1.i) Clause 1, a.1.i.A) Clause 1, a.1.i.A.I) Clause 1, a.1.i.A.I.a)

OUTPUT expect(xmlpp(Nokogiri::XML(IsoDoc::PresentationXMLConvert.new({}) .convert("test", input, true)) .at("//xmlns:foreword").to_xml)) .to be_equivalent_to xmlpp(output) end it "cross-references definition lists" do input = <<~INPUT

  • A

  • Preparatory
  • A

  • Scope
  • A

  • Widgets

    These results are based on a study carried out on three different types of kernel.

    These results are based on a study carried out on three different types of kernel.

    These results are based on a study carried out on three different types of kernel.

    These results are based on a study carried out on three different types of kernel.

    These results are based on a study carried out on three different types of kernel.

    INPUT output = <<~OUTPUT

    Introduction, Definition List Preparatory, Definition List Clause 1, Definition List Clause 3.1, Definition List 1 Clause 3.1, Definition List 2 Annex A.1, Definition List Annex A.2, Definition List 1 Annex A.2, Definition List 2

    OUTPUT expect(xmlpp(Nokogiri::XML(IsoDoc::PresentationXMLConvert.new({}) .convert("test", input, true)) .at("//xmlns:foreword").to_xml)) .to be_equivalent_to xmlpp(output) end it "cross-references definition list terms" do input = <<~INPUT

    A

    Preparatory

    A

    Scope

    A

    Widgets

    A

    A

    A

    A

    A

    INPUT output = <<~OUTPUT

    Introduction, Definition List: A Preparatory, Definition List: A Clause 1, Definition List: A Clause 3.1, Definition List 1: A Clause 3.1, Definition List 2: A Annex A.1, Definition List: A Annex A.2, Definition List 1: A Annex A.2, Definition List 2: A

    OUTPUT expect(xmlpp(Nokogiri::XML(IsoDoc::PresentationXMLConvert.new({}) .convert("test", input, true)) .at("//xmlns:foreword").to_xml)) .to be_equivalent_to xmlpp(output) end it "cross-references bookmarks" do input = <<~INPUT

    Preparatory

    Scope

    Widgets

    INPUT output = <<~OUTPUT

    Introduction Preparatory Clause 1 Note 2 Clause 3.1 Annex A.1 Figure A.1 Annex A.2

    OUTPUT expect(xmlpp(Nokogiri::XML(IsoDoc::PresentationXMLConvert.new({}) .convert("test", input, true)) .at("//xmlns:foreword").to_xml)) .to be_equivalent_to xmlpp(output) end it "realises subsequences" do input = <<~INPUT

    Split-it-right sample divider
    Split-it-right sample divider
    Split-it-right sample divider
    Split-it-right sample divider
    Split-it-right sample divider
    Split-it-right sample divider
    Split-it-right sample divider
    Split-it-right sample divider
    INPUT output = <<~OUTPUT

    Figure 1 Figure 2a Figure 2b Figure 3a Figure 3b Figure 3c Figure 4 Figure 5

    OUTPUT expect(xmlpp(Nokogiri::XML(IsoDoc::PresentationXMLConvert.new({}) .convert("test", input, true)) .at("//xmlns:foreword").to_xml)) .to be_equivalent_to xmlpp(output) end it "realises numbering overrides" do input = <<~INPUT

    Split-it-right sample divider
    Split-it-right sample divider
    Split-it-right sample divider
    Split-it-right sample divider
    Split-it-right sample divider
    Split-it-right sample divider
    Split-it-right sample divider
    Split-it-right sample divider
    Split-it-right sample divider
    Split-it-right sample divider
    Split-it-right sample divider
    Split-it-right sample divider
    Split-it-right sample divider
    Scope

    Text

    Terms and definitions

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

    Term1
    Abbreviated terms Clause 4 Introduction Clause A Clause B Clause C Clause D Clause E Clause F Clause G Clause H Clause I Terms and Definitions
    First Annex Annex Annex A.1 Another Annex Normative references

    There are no normative references in this document.

    Bibliography Bibliography Subsection
    INPUT output = <<~OUTPUT

    Figure 1 Figure A Figure B Figure 7 Figure 8 Figure 9a Figure 9c Figure 9d Figure 20f Figure 20g Figure A.1 Figure A.2 Figure 100

    Clause 1bis Clause 2bis Clause 3bis Clause 3bis.4bis Clause 12bis Clause 13bis Clause 13bis.14bis Clause 13bis.14bit Clause 13bis.14biu Clause 13bis.0 Clause 13bis.1 Clause 13bis.2 Clause 13bis.a Clause 13bis.b Clause 13bis.B Clause 13bis.C Clause 16bis Annex A Annex 17bis Annex 17bis.18bis Annex 17bit Bibliography Bibliography Subsection

    OUTPUT expect(xmlpp(Nokogiri::XML(IsoDoc::PresentationXMLConvert.new({}) .convert("test", input, true)) .at("//xmlns:foreword").to_xml)) .to be_equivalent_to xmlpp(output) end it "realises roman counter for xrefs" do a = IsoDoc::XrefGen::Counter.new(0, numerals: :roman) a.increment({}) expect(a.print).to eq "I" a.increment({}) expect(a.print).to eq "II" a.increment({}) expect(a.print).to eq "III" a.increment({}) expect(a.print).to eq "IV" a.increment({}) expect(a.print).to eq "V" end it "skips I in counter for xrefs" do a = IsoDoc::XrefGen::Counter.new("@", skip_i: true) a.increment({}) a.increment({}) a.increment({}) a.increment({}) a.increment({}) a.increment({}) a.increment({}) a.increment({}) expect(a.print).to eq "H" a.increment({}) expect(a.print).to eq "J" a = IsoDoc::XrefGen::Counter.new("@") a.increment({}) a.increment({}) a.increment({}) a.increment({}) a.increment({}) a.increment({}) a.increment({}) a.increment({}) expect(a.print).to eq "H" a.increment({}) expect(a.print).to eq "I" end it "increments counter past Z for xrefs" do a = IsoDoc::XrefGen::Counter.new("Z") a.increment({}) expect(a.print).to eq "AA" a.increment({}) expect(a.print).to eq "AB" a = IsoDoc::XrefGen::Counter.new("BZ") a.increment({}) expect(a.print).to eq "CA" a.increment({}) expect(a.print).to eq "CB" a = IsoDoc::XrefGen::Counter.new("z") a.increment({}) expect(a.print).to eq "aa" a.increment({}) expect(a.print).to eq "ab" a = IsoDoc::XrefGen::Counter.new("Az") a.increment({}) expect(a.print).to eq "Ba" a.increment({}) expect(a.print).to eq "Bb" end end