require "spec_helper" RSpec.describe IsoDoc do it "processes English" do expect(IsoDoc::HtmlConvert.new({}).convert("test", <<~"INPUT", true)).to be_equivalent_to <<~"OUTPUT" <iso-standard xmlns="http://riboseinc.com/isoxml"> <bibdata> <language>en</language> </bibdata> <preface> <foreword obligation="informative"> <title>Foreword</title> <p id="A">This is a preamble</p> </foreword> <introduction id="B" obligation="informative"><title>Introduction</title><clause id="C" inline-header="false" obligation="informative"> <title>Introduction Subsection</title> </clause> </introduction></preface><sections> <clause id="D" obligation="normative"> <title>Scope</title> <p id="E">Text</p> </clause> <clause id="H" obligation="normative"><title>Terms, Definitions, Symbols and Abbreviated Terms</title><terms id="I" obligation="normative"> <title>Normal Terms</title> <term id="J"> <preferred>Term2</preferred> </term> </terms> <definitions id="K"> <dl> <dt>Symbol</dt> <dd>Definition</dd> </dl> </definitions> </clause> <definitions id="L"> <dl> <dt>Symbol</dt> <dd>Definition</dd> </dl> </definitions> <clause id="M" inline-header="false" obligation="normative"><title>Clause 4</title><clause id="N" inline-header="false" obligation="normative"> <title>Introduction</title> </clause> <clause id="O" inline-header="false" obligation="normative"> <title>Clause 4.2</title> </clause></clause> </sections><annex id="P" inline-header="false" obligation="normative"> <title>Annex</title> <clause id="Q" inline-header="false" obligation="normative"> <title>Annex A.1</title> <clause id="Q1" inline-header="false" obligation="normative"> <title>Annex A.1a</title> </clause> </clause> </annex><bibliography><references id="R" obligation="informative"> <title>Normative References</title> </references><clause id="S" obligation="informative"> <title>Bibliography</title> <references id="T" obligation="informative"> <title>Bibliography Subsection</title> </references> </clause> </bibliography> </iso-standard> INPUT #{HTML_HDR} <br/> <div> <h1 class="ForewordTitle">Foreword</h1> <p id="A">This is a preamble</p> </div> <br/> <div class="Section3" id="B"> <h1 class="IntroTitle">Introduction</h1> <div id="C"> <h2>Introduction Subsection</h2> </div> </div> <p class="zzSTDTitle1"/> <div id="D"> <h1>1.  Scope</h1> <p id="E">Text</p> </div> <div> <h1>2.  Normative references</h1> <p>There are no normative references in this document.</p> </div> <div id="H"><h1>3.  Terms, definitions, symbols and abbreviated terms</h1><p>For the purposes of this document, the following terms and definitions apply.</p> <div id="I"> <h2>3.1. Normal Terms</h2> <p class="TermNum" id="J">3.1.1.</p> <p class="Terms" style="text-align:left;">Term2</p> </div><div id="K"><h2>3.2. Symbols and abbreviated terms</h2> <dl><dt><p>Symbol</p></dt><dd>Definition</dd></dl> </div></div> <div id="L" class="Symbols"> <h1>4.  Symbols and abbreviated terms</h1> <dl> <dt> <p>Symbol</p> </dt> <dd>Definition</dd> </dl> </div> <div id="M"> <h1>5.  Clause 4</h1> <div id="N"> <h2>5.1. Introduction</h2> </div> <div id="O"> <h2>5.2. Clause 4.2</h2> </div> </div> <br/> <div id="P" class="Section3"> <h1 class="Annex"><b>Annex A</b><br/>(normative)<br/><br/><b>Annex</b></h1> <div id="Q"> <h2>A.1. Annex A.1</h2> <div id="Q1"> <h3>A.1.1. Annex A.1a</h3> </div> </div> </div> <br/> <div> <h1 class="Section3">Bibliography</h1> <div> <h2 class="Section3">Bibliography Subsection</h2> </div> </div> </div> </body> </html> OUTPUT end it "defaults to English" do expect(IsoDoc::HtmlConvert.new({}).convert("test", <<~"INPUT", true)).to be_equivalent_to <<~"OUTPUT" <iso-standard xmlns="http://riboseinc.com/isoxml"> <bibdata> <language>tlh</language> </bibdata> <preface> <foreword obligation="informative"> <title>Foreword</title> <p id="A">This is a preamble</p> </foreword> <introduction id="B" obligation="informative"><title>Introduction</title><clause id="C" inline-header="false" obligation="informative"> <title>Introduction Subsection</title> </clause> </introduction></preface><sections> <clause id="D" obligation="normative"> <title>Scope</title> <p id="E">Text</p> </clause> <clause id="H" obligation="normative"><title>Terms, Definitions, Symbols and Abbreviated Terms</title><terms id="I" obligation="normative"> <title>Normal Terms</title> <term id="J"> <preferred>Term2</preferred> </term> </terms> <definitions id="K"> <dl> <dt>Symbol</dt> <dd>Definition</dd> </dl> </definitions> </clause> <definitions id="L"> <dl> <dt>Symbol</dt> <dd>Definition</dd> </dl> </definitions> <clause id="M" inline-header="false" obligation="normative"><title>Clause 4</title><clause id="N" inline-header="false" obligation="normative"> <title>Introduction</title> </clause> <clause id="O" inline-header="false" obligation="normative"> <title>Clause 4.2</title> </clause></clause> </sections><annex id="P" inline-header="false" obligation="normative"> <title>Annex</title> <clause id="Q" inline-header="false" obligation="normative"> <title>Annex A.1</title> <clause id="Q1" inline-header="false" obligation="normative"> <title>Annex A.1a</title> </clause> </clause> </annex><bibliography><references id="R" obligation="informative"> <title>Normative References</title> </references><clause id="S" obligation="informative"> <title>Bibliography</title> <references id="T" obligation="informative"> <title>Bibliography Subsection</title> </references> </clause> </bibliography> </iso-standard> INPUT #{HTML_HDR} <br/> <div> <h1 class="ForewordTitle">Foreword</h1> <p id="A">This is a preamble</p> </div> <br/> <div class="Section3" id="B"> <h1 class="IntroTitle">Introduction</h1> <div id="C"> <h2>Introduction Subsection</h2> </div> </div> <p class="zzSTDTitle1"/> <div id="D"> <h1>1.  Scope</h1> <p id="E">Text</p> </div> <div> <h1>2.  Normative references</h1> <p>There are no normative references in this document.</p> </div> <div id="H"><h1>3.  Terms, definitions, symbols and abbreviated terms</h1><p>For the purposes of this document, the following terms and definitions apply.</p> <div id="I"> <h2>3.1. Normal Terms</h2> <p class="TermNum" id="J">3.1.1.</p> <p class="Terms" style="text-align:left;">Term2</p> </div><div id="K"><h2>3.2. Symbols and abbreviated terms</h2> <dl><dt><p>Symbol</p></dt><dd>Definition</dd></dl> </div></div> <div id="L" class="Symbols"> <h1>4.  Symbols and abbreviated terms</h1> <dl> <dt> <p>Symbol</p> </dt> <dd>Definition</dd> </dl> </div> <div id="M"> <h1>5.  Clause 4</h1> <div id="N"> <h2>5.1. Introduction</h2> </div> <div id="O"> <h2>5.2. Clause 4.2</h2> </div> </div> <br/> <div id="P" class="Section3"> <h1 class="Annex"><b>Annex A</b><br/>(normative)<br/><br/><b>Annex</b></h1> <div id="Q"> <h2>A.1. Annex A.1</h2> <div id="Q1"> <h3>A.1.1. Annex A.1a</h3> </div> </div> </div> <br/> <div> <h1 class="Section3">Bibliography</h1> <div> <h2 class="Section3">Bibliography Subsection</h2> </div> </div> </div> </body> </html> OUTPUT end it "processes French" do expect(IsoDoc::HtmlConvert.new({}).convert("test", <<~"INPUT", true)).to be_equivalent_to <<~"OUTPUT" <iso-standard xmlns="http://riboseinc.com/isoxml"> <bibdata> <language>fr</language> </bibdata> <preface> <foreword obligation="informative"> <title>Foreword</title> <p id="A">This is a preamble</p> </foreword> <introduction id="B" obligation="informative"><title>Introduction</title><clause id="C" inline-header="false" obligation="informative"> <title>Introduction Subsection</title> </clause> </introduction></preface><sections> <clause id="D" obligation="normative"> <title>Scope</title> <p id="E">Text</p> </clause> <clause id="H" obligation="normative"><title>Terms, Definitions, Symbols and Abbreviated Terms</title><terms id="I" obligation="normative"> <title>Normal Terms</title> <term id="J"> <preferred>Term2</preferred> </term> </terms> <definitions id="K"> <dl> <dt>Symbol</dt> <dd>Definition</dd> </dl> </definitions> </clause> <definitions id="L"> <dl> <dt>Symbol</dt> <dd>Definition</dd> </dl> </definitions> <clause id="M" inline-header="false" obligation="normative"><title>Clause 4</title><clause id="N" inline-header="false" obligation="normative"> <title>Introduction</title> </clause> <clause id="O" inline-header="false" obligation="normative"> <title>Clause 4.2</title> </clause></clause> </sections><annex id="P" inline-header="false" obligation="normative"> <title>Annex</title> <clause id="Q" inline-header="false" obligation="normative"> <title>Annex A.1</title> <clause id="Q1" inline-header="false" obligation="normative"> <title>Annex A.1a</title> </clause> </clause> </annex><bibliography><references id="R" obligation="informative"> <title>Normative References</title> </references><clause id="S" obligation="informative"> <title>Bibliography</title> <references id="T" obligation="informative"> <title>Bibliography Subsection</title> </references> </clause> </bibliography> </iso-standard> INPUT #{HTML_HDR} <br/> <div> <h1 class="ForewordTitle">Avant-propos</h1> <p id="A">This is a preamble</p> </div> <br/> <div class="Section3" id="B"> <h1 class="IntroTitle">Introduction</h1> <div id="C"> <h2>Introduction Subsection</h2> </div> </div> <p class="zzSTDTitle1"/> <div id="D"> <h1>1.  Domaine d'application</h1> <p id="E">Text</p> </div> <div> <h1>2.  Références normatives</h1> <p>Le présent document ne contient aucune référence normative.</p> </div> <div id="H"><h1>3.  Terms, définitions, symboles et termes abrégés</h1><p>Pour les besoins du présent document, les termes et définitions suivants s'appliquent.</p> <div id="I"> <h2>3.1. Normal Terms</h2> <p class="TermNum" id="J">3.1.1.</p> <p class="Terms" style="text-align:left;">Term2</p> </div><div id="K"><h2>3.2. Symboles et termes abrégés</h2> <dl><dt><p>Symbol</p></dt><dd>Definition</dd></dl> </div></div> <div id="L" class="Symbols"> <h1>4.  Symboles et termes abrégés</h1> <dl> <dt> <p>Symbol</p> </dt> <dd>Definition</dd> </dl> </div> <div id="M"> <h1>5.  Clause 4</h1> <div id="N"> <h2>5.1. Introduction</h2> </div> <div id="O"> <h2>5.2. Clause 4.2</h2> </div> </div> <br/> <div id="P" class="Section3"> <h1 class="Annex"><b>Annexe A</b><br/>(normative)<br/><br/><b>Annex</b></h1> <div id="Q"> <h2>A.1. Annex A.1</h2> <div id="Q1"> <h3>A.1.1. Annex A.1a</h3> </div> </div> </div> <br/> <div> <h1 class="Section3">Bibliographie</h1> <div> <h2 class="Section3">Bibliography Subsection</h2> </div> </div> </div> </body> </html> OUTPUT end it "processes Simplified Chinese" do expect(IsoDoc::HtmlConvert.new({}).convert("test", <<~"INPUT", true)).to be_equivalent_to <<~"OUTPUT" <iso-standard xmlns="http://riboseinc.com/isoxml"> <bibdata> <language>zh</language> <script>Hans</script> </bibdata> <preface> <foreword obligation="informative"> <title>Foreword</title> <p id="A">This is a preamble</p> </foreword> <introduction id="B" obligation="informative"><title>Introduction</title><clause id="C" inline-header="false" obligation="informative"> <title>Introduction Subsection</title> </clause> </introduction></preface><sections> <clause id="D" obligation="normative"> <title>Scope</title> <p id="E"><eref type="inline" bibitemid="ISO712"><locality type="table"><referenceFrom>1</referenceFrom><referenceTo>1</referenceTo></locality></eref></p> </clause> <clause id="H" obligation="normative"><title>Terms, Definitions, Symbols and Abbreviated Terms</title><terms id="I" obligation="normative"> <title>Normal Terms</title> <term id="J"> <preferred>Term2</preferred> </term> </terms> <definitions id="K"> <dl> <dt>Symbol</dt> <dd>Definition</dd> </dl> </definitions> </clause> <definitions id="L"> <dl> <dt>Symbol</dt> <dd>Definition</dd> </dl> </definitions> <clause id="M" inline-header="false" obligation="normative"><title>Clause 4</title><clause id="N" inline-header="false" obligation="normative"> <title>Introduction</title> </clause> <clause id="O" inline-header="false" obligation="normative"> <title>Clause 4.2</title> </clause></clause> </sections><annex id="P" inline-header="false" obligation="normative"> <title>Annex</title> <clause id="Q" inline-header="false" obligation="normative"> <title>Annex A.1</title> <clause id="Q1" inline-header="false" obligation="normative"> <title>Annex A.1a</title> </clause> </clause> </annex><bibliography><references id="R" obligation="informative"> <title>Normative References</title> <bibitem id="ISO712" type="standard"> <title format="text/plain">Cereals and cereal products</title> <docidentifier>ISO 712</docidentifier> <contributor> <role type="publisher"/> <organization> <abbreviation>ISO</abbreviation> </organization> </contributor> </bibitem> </references><clause id="S" obligation="informative"> <title>Bibliography</title> <references id="T" obligation="informative"> <title>Bibliography Subsection</title> </references> </clause> </bibliography> </iso-standard> INPUT #{HTML_HDR} <br/> <div> <h1 class="ForewordTitle">前言</h1> <p id="A">This is a preamble</p> </div> <br/> <div class="Section3" id="B"> <h1 class="IntroTitle">引言</h1> <div id="C"> <h2>Introduction Subsection</h2> </div> </div> <p class="zzSTDTitle1"/> <div id="D"> <h1>1.  范围</h1> <p id="E"> <a href="#ISO712">ISO 712、第1–<referenceto>1</referenceto>表</a> </p> </div> <div> <h1>2.  规范性引用文件</h1> <p>下列文件对于本文件的应用是必不可少的。 凡是注日期的引用文件,仅注日期的版本适用于本文件。 凡是不注日期的引用文件,其最新版本(包括所有的修改单)适用于本文件。</p> <p id="ISO712" class="NormRef">ISO 712, <i> Cereals and cereal products</i></p> </div> <div id="H"><h1>3.  术语、定义、符号、代号和缩略语</h1><p>下列术语和定义适用于本文件。</p> <div id="I"> <h2>3.1. Normal Terms</h2> <p class="TermNum" id="J">3.1.1.</p> <p class="Terms" style="text-align:left;">Term2</p> </div><div id="K"><h2>3.2. 符号、代号和缩略语</h2> <dl><dt><p>Symbol</p></dt><dd>Definition</dd></dl> </div></div> <div id="L" class="Symbols"> <h1>4.  符号、代号和缩略语</h1> <dl> <dt> <p>Symbol</p> </dt> <dd>Definition</dd> </dl> </div> <div id="M"> <h1>5.  Clause 4</h1> <div id="N"> <h2>5.1. Introduction</h2> </div> <div id="O"> <h2>5.2. Clause 4.2</h2> </div> </div> <br/> <div id="P" class="Section3"> <h1 class="Annex">附件A<br/>(规范性附录)<br/><br/><b>Annex</b></h1> <div id="Q"> <h2>A.1. Annex A.1</h2> <div id="Q1"> <h3>A.1.1. Annex A.1a</h3> </div> </div> </div> <br/> <div> <h1 class="Section3">参考文献</h1> <div> <h2 class="Section3">Bibliography Subsection</h2> </div> </div> </div> </body> </html> OUTPUT end end