Skip to content

Commit

Permalink
rspec
Browse files Browse the repository at this point in the history
  • Loading branch information
opoudjis committed Nov 16, 2024
1 parent 23ea27f commit 6c38850
Show file tree
Hide file tree
Showing 2 changed files with 146 additions and 61 deletions.
205 changes: 144 additions & 61 deletions spec/isodoc/footnotes_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,39 @@
</iso-standard>
INPUT
presxml = <<~INPUT
<iso-standard xmlns="http://riboseinc.com/isoxml">
<iso-standard xmlns="http://riboseinc.com/isoxml" type="presentation">
<preface>
<foreword><title>Foreword</title>
<p>A.<fn reference="2">
<p id="_1e228e29-baef-4f38-b048-b05a051747e4">Formerly denoted as 15 % (m/m).</p>
</fn></p>
<p>B.<fn reference="2">
<p id="_1e228e29-baef-4f38-b048-b05a051747e4">Formerly denoted as 15 % (m/m).</p>
</fn></p>
<p>C.<fn reference="1">
<p id="_1e228e29-baef-4f38-b048-b05a051747e4">Hello! denoted as 15 % (m/m).</p>
</fn></p>
</foreword>
<clause type="toc" id="_" displayorder="1">
<fmt-title depth="1">Table of contents</fmt-title>
</clause>
<foreword displayorder="2">
<title id="_">Foreword</title>
<fmt-title depth="1">
<span class="fmt-caption-label">
<semx element="title" source="_">Foreword</semx>
</span>
</fmt-title>
<p>
A.
<fn reference="2">
<p id="_">Formerly denoted as 15 % (m/m).</p>
</fn>
</p>
<p>
B.
<fn reference="2">
<p id="_">Formerly denoted as 15 % (m/m).</p>
</fn>
</p>
<p>
C.
<fn reference="1">
<p id="_">Hello! denoted as 15 % (m/m).</p>
</fn>
</p>
</foreword>
</preface>
</iso-standard>
</iso-standard>
INPUT
html = <<~OUTPUT
#{HTML_HDR}
Expand Down Expand Up @@ -128,10 +146,10 @@
</p>
<div class='WordSection3'>
<aside id='ftn2'>
<p id='_1e228e29-baef-4f38-b048-b05a051747e4'>Formerly denoted as 15 % (m/m).</p>
<p id='_'>Formerly denoted as 15 % (m/m).</p>
</aside>
<aside id='ftn1'>
<p id='_1e228e29-baef-4f38-b048-b05a051747e4'>Hello! denoted as 15 % (m/m).</p>
<p id='_'>Hello! denoted as 15 % (m/m).</p>
</aside>
</div>
</body>
Expand All @@ -144,10 +162,10 @@
.to be_equivalent_to Xml::C14n.format(presxml)
expect(Xml::C14n.format(strip_guid(IsoDoc::HtmlConvert.new({})
.convert("test", pres_output, true))))
.to be_equivalent_to Xml::C14n.format(html)
.to be_equivalent_to Xml::C14n.format(strip_guid(html))
expect(Xml::C14n.format(strip_guid(IsoDoc::WordConvert.new({})
.convert("test", pres_output, true))))
.to be_equivalent_to Xml::C14n.format(doc)
.to be_equivalent_to Xml::C14n.format(strip_guid(doc))
end

it "processes IsoXML reviewer notes" do
Expand All @@ -170,25 +188,56 @@
</iso-standard>
INPUT
presxml = <<~INPUT
<iso-standard xmlns="http://riboseinc.com/isoxml">
<preface>
<foreword displayorder="1"><title>Foreword</title>
<p id="A">A.</p>
<p id="B">B.</p>
<review reviewer="ISO" id="_4f4dff63-23c1-4ecb-8ac6-d3ffba93c711" date="20170101T0000" from="A" to="B"><p id="_c54b9549-369f-4f85-b5b2-9db3fd3d4c07">A Foreword shall appear in each document. The generic text is shown here. It does not contain requirements, recommendations or permissions.</p>
<p id="_f1a8b9da-ca75-458b-96fa-d4af7328975e">For further information on the Foreword, see <strong>ISO/IEC Directives, Part 2, 2016, Clause 12.</strong></p></review>
<p id="C">C.</p>
<review reviewer="ISO" id="_4f4dff63-23c1-4ecb-8ac6-d3ffba93c712" date="20170108T0000" from="C" to="C"><p id="_c54b9549-369f-4f85-b5b2-9db3fd3d4c08">Second note.</p></review>
</foreword>
<introduction displayorder="2"><title>Introduction</title>
<review reviewer="ISO" id="_4f4dff63-23c1-4ecb-8ac6-d3ffba93c712" date="20170108T0000" from="A" to="C"><p id="_c54b9549-369f-4f85-b5b2-9db3fd3d4c08">Second note.</p></review>
</introduction>
</preface>
</iso-standard>
<iso-standard xmlns="http://riboseinc.com/isoxml" type="presentation">
<preface>
<clause type="toc" id="_" displayorder="1">
<fmt-title depth="1">Table of contents</fmt-title>
</clause>
<foreword displayorder="2">
<title id="_">Foreword</title>
<fmt-title depth="1">
<span class="fmt-caption-label">
<semx element="title" source="_">Foreword</semx>
</span>
</fmt-title>
<p id="A">A.</p>
<p id="B">B.</p>
<review reviewer="ISO" id="_" date="20170101T0000" from="A" to="B">
<p id="_">A Foreword shall appear in each document. The generic text is shown here. It does not contain requirements, recommendations or permissions.</p>
<p id="_">
For further information on the Foreword, see
<strong>ISO/IEC Directives, Part 2, 2016, Clause 12.</strong>
</p>
</review>
<p id="C">C.</p>
<review reviewer="ISO" id="_" date="20170108T0000" from="C" to="C">
<p id="_">Second note.</p>
</review>
</foreword>
<introduction displayorder="3">
<title id="_">Introduction</title>
<fmt-title depth="1">
<span class="fmt-caption-label">
<semx element="title" source="_">Introduction</semx>
</span>
</fmt-title>
<review reviewer="ISO" id="_" date="20170108T0000" from="A" to="C">
<p id="_">Second note.</p>
</review>
</introduction>
</preface>
</iso-standard>
INPUT
html = <<~OUTPUT
<main class="main-section"><button onclick="topFunction()" id="myBtn" title="Go to top">Top</button>
<br />
<div id="_" class="TOC">
<h1 class="IntroTitle">
<a class="anchor" href="#_"/>
<a class="header" href="#_">Table of contents</a>
</h1>
</div>
<br/>
<div>
<h1 class="ForewordTitle">Foreword</h1>
<p id="A">A.</p>
Expand All @@ -202,7 +251,7 @@
</main>
OUTPUT

doc = <<~OUTPUT
word = <<~OUTPUT
<body lang="EN-US" link="blue" vlink="#954F72" xml:lang="EN-US">
<div class="WordSection2">
<p class="MsoNormal">
Expand Down Expand Up @@ -265,18 +314,18 @@
<div style="mso-element:comment">
<a name="3" id="3"/>
<span style="mso-comment-author:&quot;ISO&quot;"/>
<p class="MsoCommentText"><a name="_c54b9549-369f-4f85-b5b2-9db3fd3d4c08" id="_c54b9549-369f-4f85-b5b2-9db3fd3d4c08"/><span style="MsoCommentReference"><span lang="EN-GB" style="font-size:9.0pt" xml:lang="EN-GB"><span style="mso-special-character:comment"/></span></span>Second note.</p>
<p class="MsoCommentText"><a name="_" id="_"/><span style="MsoCommentReference"><span lang="EN-GB" style="font-size:9.0pt" xml:lang="EN-GB"><span style="mso-special-character:comment"/></span></span>Second note.</p>
</div>
<div style="mso-element:comment">
<a name="1" id="1"/>
<span style="mso-comment-author:&quot;ISO&quot;"/>
<p class="MsoCommentText"><a name="_c54b9549-369f-4f85-b5b2-9db3fd3d4c07" id="_c54b9549-369f-4f85-b5b2-9db3fd3d4c07"/><span style="MsoCommentReference"><span lang="EN-GB" style="font-size:9.0pt" xml:lang="EN-GB"><span style="mso-special-character:comment"/></span></span>A Foreword shall appear in each document. The generic text is shown here. It does not contain requirements, recommendations or permissions.</p>
<p class="MsoCommentText"><a name="_f1a8b9da-ca75-458b-96fa-d4af7328975e" id="_f1a8b9da-ca75-458b-96fa-d4af7328975e"/>For further information on the Foreword, see <b>ISO/IEC Directives, Part 2, 2016, Clause 12.</b></p>
<p class="MsoCommentText"><a name="_" id="_"/><span style="MsoCommentReference"><span lang="EN-GB" style="font-size:9.0pt" xml:lang="EN-GB"><span style="mso-special-character:comment"/></span></span>A Foreword shall appear in each document. The generic text is shown here. It does not contain requirements, recommendations or permissions.</p>
<p class="MsoCommentText"><a name="_" id="_"/>For further information on the Foreword, see <b>ISO/IEC Directives, Part 2, 2016, Clause 12.</b></p>
</div>
<div style="mso-element:comment">
<a name="2" id="2"/>
<span style="mso-comment-author:&quot;ISO&quot;"/>
<p class="MsoCommentText"><a name="_c54b9549-369f-4f85-b5b2-9db3fd3d4c08" id="_c54b9549-369f-4f85-b5b2-9db3fd3d4c08"/><span style="MsoCommentReference"><span lang="EN-GB" style="font-size:9.0pt" xml:lang="EN-GB"><span style="mso-special-character:comment"/></span></span>Second note.</p>
<p class="MsoCommentText"><a name="_" id="_"/><span style="MsoCommentReference"><span lang="EN-GB" style="font-size:9.0pt" xml:lang="EN-GB"><span style="mso-special-character:comment"/></span></span>Second note.</p>
</div>
</div>
</div>
Expand All @@ -294,14 +343,16 @@
out = File.read("test.html").sub(/^.*<main/m, "<main").sub(
%r{</main>.*$}m, "</main>"
)
expect(Xml::C14n.format(out)).to be_equivalent_to Xml::C14n.format(html)
expect(Xml::C14n.format(strip_guid(out)))
.to be_equivalent_to Xml::C14n.format(html)
FileUtils.rm_f "test.doc"
IsoDoc::WordConvert.new({ wordstylesheet: "spec/assets/word.css",
htmlstylesheet: "spec/assets/html.scss" })
.convert("test", pres_output, false)
out = File.read("test.doc").sub(/^.*<body/m, "<body").sub(%r{</body>.*$}m,
"</body>")
expect(Xml::C14n.format(out)).to be_equivalent_to Xml::C14n.format(word)
expect(Xml::C14n.format(strip_guid(out)))
.to be_equivalent_to Xml::C14n.format(word)
end

it "processes IsoXML reviewer notes spanning list" do
Expand All @@ -326,27 +377,57 @@
</iso-standard>
INPUT
presxml = <<~INPUT
<iso-standard xmlns="http://riboseinc.com/isoxml">
<preface>
<foreword displayorder="1"><title>Foreword</title>
<ol>
<li id="A"><p>A.</p><p>A1</p></li>
<li id="B">B.</li>
<ul>
<li><p>C.</p><p id="C">C1</p></li>
<li id="D">D.</li>
</ul>
</ol>
</foreword>
<introduction displayorder="2"><title>Introduction</title>
<review reviewer="ISO" id="_4f4dff63-23c1-4ecb-8ac6-d3ffba93c712" date="20170108T0000" from="A" to="C"><p id="_c54b9549-369f-4f85-b5b2-9db3fd3d4c08">Second note.</p></review>
</introduction>
</preface>
</iso-standard>
<iso-standard xmlns="http://riboseinc.com/isoxml" type="presentation">
<preface>
<clause type="toc" id="_" displayorder="1">
<fmt-title depth="1">Table of contents</fmt-title>
</clause>
<foreword displayorder="2">
<title id="_">Foreword</title>
<fmt-title depth="1">
<span class="fmt-caption-label">
<semx element="title" source="_">Foreword</semx>
</span>
</fmt-title>
<ol type="alphabet">
<li id="A" label="">
<p>A.</p>
<p>A1</p>
</li>
<li id="B" label="">B.</li>
<ul>
<li>
<p>C.</p>
<p id="C">C1</p>
</li>
<li id="D">D.</li>
</ul>
</ol>
</foreword>
<introduction displayorder="3">
<title id="_">Introduction</title>
<fmt-title depth="1">
<span class="fmt-caption-label">
<semx element="title" source="_">Introduction</semx>
</span>
</fmt-title>
<review reviewer="ISO" id="_" date="20170108T0000" from="A" to="C">
<p id="_">Second note.</p>
</review>
</introduction>
</preface>
</iso-standard>
INPUT
html = <<~OUTPUT
<main class="main-section"><button onclick="topFunction()" id="myBtn" title="Go to top">Top</button>
<br />
<div id="_" class="TOC">
<h1 class="IntroTitle">
<a class="anchor" href="#_"/>
<a class="header" href="#_">Table of contents</a>
</h1>
</div>
<br/>
<div>
<h1 class="ForewordTitle">Foreword</h1>
<div class="ol_wrap">
Expand Down Expand Up @@ -431,7 +512,7 @@
<div style="mso-element:comment">
<a name="1" id="1"/>
<span style="mso-comment-author:&quot;ISO&quot;"/>
<p class="MsoCommentText"><a name="_c54b9549-369f-4f85-b5b2-9db3fd3d4c08" id="_c54b9549-369f-4f85-b5b2-9db3fd3d4c08"/><span style="MsoCommentReference"><span lang="EN-GB" style="font-size:9.0pt" xml:lang="EN-GB"><span style="mso-special-character:comment"/></span></span>Second note.</p>
<p class="MsoCommentText"><a name="_" id="_"/><span style="MsoCommentReference"><span lang="EN-GB" style="font-size:9.0pt" xml:lang="EN-GB"><span style="mso-special-character:comment"/></span></span>Second note.</p>
</div>
</div>
</div>
Expand All @@ -449,13 +530,15 @@
out = File.read("test.html").sub(/^.*<main/m, "<main").sub(
%r{</main>.*$}m, "</main>"
)
expect(Xml::C14n.format(out)).to be_equivalent_to Xml::C14n.format(html)
expect(Xml::C14n.format(strip_guid(out)))
.to be_equivalent_to Xml::C14n.format(html)
FileUtils.rm_f "test.doc"
IsoDoc::WordConvert.new({ wordstylesheet: "spec/assets/word.css",
htmlstylesheet: "spec/assets/html.scss" })
.convert("test", pres_output, false)
out = File.read("test.doc").sub(/^.*<body/m, "<body").sub(%r{</body>.*$}m,
"</body>")
expect(Xml::C14n.format(out)).to be_equivalent_to Xml::C14n.format(word)
out = File.read("test.doc")
.sub(/^.*<body/m, "<body").sub(%r{</body>.*$}m, "</body>")
expect(Xml::C14n.format(strip_guid(out)))
.to be_equivalent_to Xml::C14n.format(word)
end
end
2 changes: 2 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ def strip_guid(xml)
.gsub(%r( name="_[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12,13}"), ' name="_"')
.gsub(%r( reference="[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}"), ' reference="_"')
.gsub(%r[ src="([^/]+)/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\.], ' src="\\1/_.')
.gsub(%r[ _Ref\d+{8,10}], " _Ref")
.gsub(%r[:_Ref\d+{8,10}], ":_Ref")
end

HTML_HDR = <<~HEADER.freeze
Expand Down

0 comments on commit 6c38850

Please sign in to comment.