require "spec_helper" require "relaton_iec" require "fileutils" RSpec.describe Metanorma::Standoc do =begin it "appends any initial user-supplied text to boilerplate in 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

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

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 "removes initial extraneous material from Normative References" do input = <<~INPUT #{ASCIIDOC_BLANK_HDR} [bibliography] == Normative References This is extraneous information * [[[iso216,ISO 216]]], _Reference_ This is also extraneous information INPUT output = <<~OUTPUT #{BLANK_HDR} Normative references #{NORM_REF_BOILERPLATE} Reference ISO 216 216 ISO

This is also extraneous information

OUTPUT expect(xmlpp(strip_guid(Asciidoctor.convert(input, *OPTIONS)))) .to be_equivalent_to xmlpp(output) end it "preserves user-supplied boilerplate in Normative References" do input = <<~INPUT #{ASCIIDOC_BLANK_HDR} [bibliography] == Normative References [NOTE,type=boilerplate] -- This is extraneous information -- * [[[iso216,ISO 216]]], _Reference_ This is also extraneous information INPUT output = <<~OUTPUT #{BLANK_HDR} Normative references

This is extraneous information

Reference ISO 216 216 ISO

This is also extraneous information

OUTPUT expect(xmlpp(strip_guid(Asciidoctor.convert(input, *OPTIONS)))) .to be_equivalent_to xmlpp(output) end it "sorts references with their notes in Bibliography" do input = <<~INPUT #{ASCIIDOC_BLANK_HDR} [bibliography] == Bibliography This is extraneous information * [[[iso216,ISO 216]]], _Reference_ NOTE: ABC NOTE: DEF This is further extraneous information NOTE: GHI * [[[iso216,ISO 215]]], _Reference_ NOTE: JKL This is also extraneous information INPUT output = <<~OUTPUT #{BLANK_HDR} Bibliography

This is extraneous information

Reference ISO 216 216 ISO

ABC

DEF

Reference ISO 215 215 ISO

JKL

This is further extraneous information

GHI

This is also extraneous information

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 "inserts boilerplate before empty Normative References" do input = <<~INPUT #{ASCIIDOC_BLANK_HDR} [bibliography] == Normative References INPUT output = <<~OUTPUT #{BLANK_HDR} Normative references

There are no normative references in this document.

OUTPUT expect(xmlpp(strip_guid(Asciidoctor.convert(input, *OPTIONS)))) .to be_equivalent_to xmlpp(output) end it "inserts boilerplate before non-empty Normative References" do input = <<~INPUT #{ASCIIDOC_BLANK_HDR} [bibliography] == Normative References * [[[a,b]]] A 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.

A b
OUTPUT expect(xmlpp(strip_guid(Asciidoctor.convert(input, *OPTIONS)))) .to be_equivalent_to xmlpp(output) end it "inserts boilerplate before empty Normative References in French" do input = <<~INPUT = Document title Author :docfile: test.adoc :nodoc: :novalid: :no-isobib: :language: fr [bibliography] == Normative References INPUT output = <<~OUTPUT #{BLANK_HDR.sub(/en/, 'fr')} Références normatives

Le présent document ne contient aucune référence normative.

OUTPUT expect(xmlpp(strip_guid(Asciidoctor.convert(input, *OPTIONS)))) .to be_equivalent_to xmlpp(output) end it "processes section names, with footnotes" do input = <<~INPUT #{ASCIIDOC_BLANK_HDR} .Foreword.footnote:[A] Text [abstract] == Abstract.footnote:[A] Text [heading=introduction] == Introduction.footnote:[A] === Introduction Subsection [heading=acknowledgements] == Acknowledgements.footnote:[A] [.preface] == Dedication [heading=scope] == Scope.footnote:[A] Text [bibliography,heading=normative references] == Normative References.footnote:[A] [bibliography,normative=true] == Normative References 2.footnote:[A] [heading=terms and definitions] == Terms and Definitions.footnote:[A] === Term1 [heading="terms and definitions"] == Terms, Definitions, Symbols and Abbreviated Terms.footnote:[A] [.nonterm] === Introduction ==== Intro 1 === Intro 2 [.nonterm] ==== Intro 3 === Intro 4 ==== Intro 5 ===== Term1 === Normal Terms ==== Term2 [heading=symbols and abbreviated terms] === Symbols and Abbreviated Terms.footnote:[A] [.nonterm] ==== General [heading=symbols] ==== Symbols 1.footnote:[A] [heading=abbreviated terms] == Abbreviated Terms.footnote:[A] == Clause 4 === Introduction === Clause 4.2 == Terms and Definitions [appendix] == Annex.footnote:[A] === Annex A.1 [bibliography,heading=bibliography] == Bibliography.footnote:[A] [bibliography,normative=false] == Bibliography 2.footnote:[A] === Bibliography Subsection INPUT output = <<~OUTPUT Document title en

Text

published #{Time.now.year} standard
Abstract

Text

Foreword <fn reference='1'> <p id='_'>A</p> </fn>

Text

Introduction Introduction Subsection Dedication Acknowledgements <fn reference='1'> <p id='_'>A</p> </fn>
Scope <fn reference='1'> <p id='_'>A</p> </fn>

Text

Terms and definitions <fn reference='1'> <p id='_'>A</p> </fn>

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

Term1
Terms, Definitions, Symbols and Abbreviated Terms. <fn reference='1'> <p id='_'>A</p> </fn> Introduction Intro 1 Intro 2 Intro 3 Intro 4 Intro 5 Term1 Normal Terms Term2 Symbols and abbreviated terms <fn reference='1'> <p id='_'>A</p> </fn> General Symbols <fn reference='1'> <p id='_'>A</p> </fn> Abbreviated terms <fn reference='1'> <p id='_'>A</p> </fn> Clause 4 Introduction Clause 4.2 Terms and Definitions
Annex. <fn reference='1'> <p id='_'>A</p> </fn> Annex A.1 Normative references <fn reference='1'> <p id='_'>A</p> </fn>

There are no normative references in this document.

Normative References 2. <fn reference='1'> <p id='_'>A</p> </fn> Bibliography <fn reference='1'> <p id='_'>A</p> </fn> Bibliography 2. <fn reference='1'> <p id='_'>A</p> </fn> Bibliography Subsection
OUTPUT expect(xmlpp(strip_guid(Asciidoctor.convert(input, *OPTIONS)))) .to be_equivalent_to xmlpp(output) end it "processes section names, default to English" do input = <<~INPUT #{ASCIIDOC_BLANK_HDR.sub(/:nodoc:/, ":language: tlh\n:script: Latn\n:nodoc:")} .Foreword Text [abstract] == Abstract Text [heading=introduction] == Introduction === Introduction Subsection [heading=acknowledgements] == Acknowledgements [.preface] == Dedication [heading=scope] == Scope Text [bibliography,heading=normative references] == Normative References [bibliography,normative=true] == Normative References 2 [heading=terms and definitions] == Terms and Definitions === Term1 [heading="terms and definitions"] == Terms, Definitions, Symbols and Abbreviated Terms [.nonterm] === Introduction ==== Intro 1 === Intro 2 [.nonterm] ==== Intro 3 === Intro 4 ==== Intro 5 ===== Term1 === Normal Terms ==== Term2 [heading=symbols and abbreviated terms] === Symbols and Abbreviated Terms [.nonterm] ==== General [heading=symbols] ==== Symbols 1 [heading=abbreviated terms] == Abbreviated Terms == Clause 4 === Introduction === Clause 4.2 == Terms and Definitions [appendix] == Annex === Annex A.1 [bibliography,heading=bibliography] == Bibliography [bibliography,normative=false] == Bibliography 2 === Bibliography Subsection INPUT output = <<~OUTPUT Document title tlh

Text

published #{Time.now.year} standard
Abstract

Text

Foreword

Text

Introduction Introduction Subsection Dedication Acknowledgements
Scope

Text

Terms and definitions

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

Term1
Terms, Definitions, Symbols and Abbreviated Terms Introduction Intro 1 Intro 2 Intro 3 Intro 4 Intro 5 Term1 Normal Terms Term2 Symbols and abbreviated terms General Symbols Abbreviated terms Clause 4 Introduction Clause 4.2 Terms and Definitions
Annex Annex A.1 Normative references

There are no normative references in this document.

Normative References 2 Bibliography Bibliography 2 Bibliography Subsection
OUTPUT expect(xmlpp(strip_guid(Asciidoctor.convert(input, *OPTIONS)))) .to be_equivalent_to xmlpp(output) end it "processes section names, French" do input = <<~INPUT #{ASCIIDOC_BLANK_HDR.sub(/:nodoc:/, ":language: fr\n:script: Latn\n:nodoc:")} .Foreword Text [abstract] == Abstract Text [heading=introduction] == Introduction === Introduction Subsection [heading=acknowledgements] == Acknowledgements [.preface] == Dedication [heading=scope] == Scope Text [bibliography,heading=normative references] == Normative References [bibliography,normative=true] == Normative References 2 [heading=terms and definitions] == Terms and Definitions === Term1 [heading="terms and definitions"] == Terms, Definitions, Symbols and Abbreviated Terms [.nonterm] === Introduction ==== Intro 1 === Intro 2 [.nonterm] ==== Intro 3 === Intro 4 ==== Intro 5 ===== Term1 === Normal Terms ==== Term2 [heading=symbols and abbreviated terms] === Symbols and Abbreviated Terms [.nonterm] ==== General [heading=symbols] ==== Symbols 1 [heading=abbreviated terms] == Abbreviated Terms == Clause 4 === Introduction === Clause 4.2 == Terms and Definitions [appendix] == Annex === Annex A.1 [bibliography,heading=bibliography] == Bibliography [bibliography,normative=false] == Bibliography 2 === Bibliography Subsection INPUT output = <<~OUTPUT Document title fr

Text

published #{Time.now.year} standard
Résumé

Text

Avant-propos

Text

Introduction Introduction Subsection Dedication Remerciements
Domaine d’application

Text

Terms et définitions

Pour les besoins du présent document, les termes et définitions suivants s’appliquent.

Term1
Terms, Definitions, Symbols and Abbreviated Terms Introduction Intro 1 Intro 2 Intro 3 Intro 4 Intro 5 Term1 Normal Terms Term2 Symboles et termes abrégés General Symboles Termes abrégés Clause 4 Introduction Clause 4.2 Terms and Definitions
Annex Annex A.1 Références normatives

Le présent document ne contient aucune référence normative.

Normative References 2 Bibliographie Bibliography 2 Bibliography Subsection
OUTPUT expect(xmlpp(strip_guid(Asciidoctor.convert(input, *OPTIONS)))) .to be_equivalent_to xmlpp(output) end it "processes section names, Simplified Chinese" do input = <<~INPUT #{ASCIIDOC_BLANK_HDR.sub(/:nodoc:/, ":language: zh\n:script: Hans\n:nodoc:")} .Foreword Text [abstract] == Abstract Text [heading=introduction] == Introduction === Introduction Subsection [heading=acknowledgements] == Acknowledgements [.preface] == Dedication [heading=scope] == Scope Text [bibliography,heading=normative references] == Normative References [bibliography,normative=true] == Normative References 2 [heading=terms and definitions] == Terms and Definitions === Term1 [heading="terms and definitions"] == Terms, Definitions, Symbols and Abbreviated Terms [.nonterm] === Introduction ==== Intro 1 === Intro 2 [.nonterm] ==== Intro 3 === Intro 4 ==== Intro 5 ===== Term1 === Normal Terms ==== Term2 [heading=symbols and abbreviated terms] === Symbols and Abbreviated Terms [.nonterm] ==== General [heading=symbols] ==== Symbols 1 [heading=abbreviated terms] == Abbreviated Terms == Clause 4 === Introduction === Clause 4.2 == Terms and Definitions [appendix] == Annex === Annex A.1 [bibliography,heading=bibliography] == Bibliography [bibliography,normative=false] == Bibliography 2 === Bibliography Subsection INPUT output = <<~OUTPUT Document title zh

Text

published #{Time.now.year} standard
摘要

Text

前言

Text

引言 Introduction Subsection Dedication 致謝
范围

Text

术语和定义

下列术语和定义适用于本文件。

Term1
Terms, Definitions, Symbols and Abbreviated Terms Introduction Intro 1 Intro 2 Intro 3 Intro 4 Intro 5 Term1 Normal Terms Term2 符号、代号和缩略语 General 符号 代号和缩略语 Clause 4 Introduction Clause 4.2 Terms and Definitions
Annex Annex A.1 规范性引用文件

本文件并没有规范性引用文件。

Normative References 2 参考文献 Bibliography 2 Bibliography Subsection
OUTPUT expect(xmlpp(strip_guid(Asciidoctor.convert(input, *OPTIONS)))) .to be_equivalent_to xmlpp(output) end =end it "processes section names, internationalisation file" do input = <<~INPUT #{ASCIIDOC_BLANK_HDR.sub(/:nodoc:/, ":no-pdf:\n:i18nyaml: spec/assets/i18n.yaml")} .Foreword Text [abstract] == Abstract Text [heading=introduction] == Introduction === Introduction Subsection [heading=acknowledgements] == Acknowledgements [.preface] == Dedication [heading=scope] == Scope Text [bibliography,heading=normative references] == Normative References [bibliography,normative=true] == Normative References 2 [heading=terms and definitions] == Terms and Definitions === Term1 [heading="terms and definitions"] == Terms, Definitions, Symbols and Abbreviated Terms [.nonterm] === Introduction ==== Intro 1 === Intro 2 [.nonterm] ==== Intro 3 === Intro 4 ==== Intro 5 ===== Term1 === Normal Terms ==== Term2 [heading=symbols and abbreviated terms] === Symbols and Abbreviated Terms [.nonterm] ==== General [heading=symbols] ==== Symbols 1 [heading=abbreviated terms] == Abbreviated Terms == Clause 4 === Introduction === Clause 4.2 == Terms and Definitions [appendix] == Annex === Annex A.1 [bibliography,heading=bibliography] == Bibliography [bibliography,normative=false] == Bibliography 2 === Bibliography Subsection INPUT output = <<~OUTPUT Document title en

Text

published #{Time.now.year} standard
Abstract

Text

Antaŭparolo

Text

Enkonduko Introduction Subsection Dedication Acknowledgements
Amplekso

Text

Terms and definitions

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

Term1
Terms, Definitions, Symbols and Abbreviated Terms Introduction Intro 1 Intro 2 Intro 3 Intro 4 Intro 5 Term1 Normal Terms Term2 Symbols and abbreviated terms General Simboloj kai mallongigitaj terminoj Abbreviated terms Clause 4 Introduction Clause 4.2 Terms and Definitions
Annex Annex A.1 Normaj citaĵoj

There are no normative references in this document.

Normative References 2 Bibliografio Bibliography 2 Bibliography Subsection
OUTPUT expect(xmlpp(strip_guid(Asciidoctor.convert(input, *OPTIONS)))) .to be_equivalent_to xmlpp(output) end it "adds variant titles" do input = <<~INPUT #{ASCIIDOC_BLANK_HDR} == Clause Text === Subclause [.variant-title,type=toc] Clause _A_ stem:[x] [.variant-title,type=sub] "A" 'B' Text [appendix] == Clause [.variant-title,type=toc] Clause _A_ stem:[y] Text INPUT output = <<~OUTPUT #{BLANK_HDR} Clause

Text

Subclause “A” ‘B’ Clause A x

Text

Clause Clause A y

Text

OUTPUT expect(xmlpp(strip_guid(Asciidoctor.convert(input, *OPTIONS)))) .to be_equivalent_to xmlpp(output) end it "processes TOC clause" do input = <<~INPUT #{ASCIIDOC_BLANK_HDR} == Clause Text [type=toc] === Table of contents Text at the start ==== Toc 1 * <> ** <> ==== Toc 2 * <> ** <> [[cl2]] == Clause2 [.variant-title,type=toc] Clause _A_ stem:[x] [.variant-title,type=sub] "A" 'B' Text [[a1]] [appendix] == Clause [.variant-title,type=toc] Clause _A_ stem:[y] Text INPUT output = <<~OUTPUT #{BLANK_HDR} Clause

Text

Table of contents

Text at the start

Toc 1
  • Clause#{' '} A x

    • Clause#{' '} A y

Toc 2
  • some text

    • some more text

Clause2 “A” ‘B’ Clause#{' '} A x

Text

Clause Clause#{' '} A y

Text

OUTPUT expect(xmlpp(strip_guid(Asciidoctor.convert(input, *OPTIONS)))) .to be_equivalent_to xmlpp(output) end it "processes bibliography annex" do input = <<~INPUT #{ASCIIDOC_BLANK_HDR} [appendix] == Bibliography [bibliography] === Bibliography INPUT output = <<~OUTPUT Bibliography Bibliography OUTPUT ret = Nokogiri::XML(Asciidoctor.convert(input, *OPTIONS)) expect(xmlpp(strip_guid(ret.at("//xmlns:annex").to_xml))) .to be_equivalent_to(output) end it "processes terms annex" do input = <<~INPUT #{ASCIIDOC_BLANK_HDR} [appendix] == Terms and definitions === Terms and definitions INPUT output = <<~OUTPUT Terms and definitions Terms and definitions OUTPUT ret = Nokogiri::XML(Asciidoctor.convert(input, *OPTIONS)) expect(xmlpp(strip_guid(ret.at("//xmlns:annex").to_xml))) .to be_equivalent_to(output) end end