From 85add8ac2fca486643e58e71ca47946098d6392d Mon Sep 17 00:00:00 2001 From: Nick Nicholas Date: Fri, 15 Nov 2024 21:03:36 +1100 Subject: [PATCH] rspec --- spec/isodoc/ref_spec.rb | 579 ++++++++++++++++++++++++++++++++-------- spec/spec_helper.rb | 4 +- 2 files changed, 464 insertions(+), 119 deletions(-) diff --git a/spec/isodoc/ref_spec.rb b/spec/isodoc/ref_spec.rb index 100cc08a..048d77ec 100644 --- a/spec/isodoc/ref_spec.rb +++ b/spec/isodoc/ref_spec.rb @@ -137,8 +137,16 @@ en - Table of contents - Foreword + #{' '} + Table of contents + + + Foreword + + + Foreword + +

[110] [1] @@ -153,7 +161,21 @@ - 1.<tab/>Normative References + Normative References + + + 1 + . + + + + Normative References + + + + Clause + 1 +

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. @@ -199,7 +221,11 @@ ICC/167, - NOTE + + + NOTE + +

This is an annotation of ISO 20483:2013-2014

@@ -211,7 +237,12 @@ - Bibliography + Bibliography + + + Bibliography + + Chemicals for analytical laboratory use. n.p.: n.d. ISBN: ISBN. [1] @@ -225,11 +256,19 @@ [2] - NOTE + + + NOTE + +

This is an annotation of document ISSN.

- NOTE + + + NOTE + +

This is another annotation of document ISSN.

@@ -378,6 +417,9 @@ + @@ -419,7 +461,7 @@ amendments) applies.

[110], ISO 712, International Organization for Standardization. Cereals and cereal products.

-

ISO 16634:-- (all parts), Cereals, pulses, milled cereal products, oilseeds and animal feeding stuffs.

+

ISO 16634:-- (all parts), Cereals, pulses, milled cereal products, oilseeds and animal feeding stuffs.

ISO 20483:2013-2014, International Organization for Standardization. Cereals and pulses. 2013–2014.

ICC/167, Standard No I.C.C 167 @@ -451,7 +493,15 @@

-

[3]  ISO 3696 NOTEREF _Ref \\f \\h_, Water for analytical laboratory use.

+

[3]  ISO 3696 + + + + + + + + , Water for analytical laboratory use.

[4]  Standard No I.C.C 167 . @@ -475,23 +525,36 @@

-

Under preparation. (Stage at the time of publication ISO/DIS 16634)

+

Under preparation. (Stage at the time of publication ISO/DIS 16634)

+
+

+ + + + + + Under preparation. (Stage at the time of publication ISO/DIS 3696) +

+
OUTPUT FileUtils.rm_rf("test.doc") - expect(Xml::C14n.format(strip_guid(IsoDoc::PresentationXMLConvert.new(presxml_options) - .convert("test", input, true)) + pres_output = IsoDoc::PresentationXMLConvert + .new(presxml_options) + .convert("test", input, true) + expect(Xml::C14n.format(strip_guid(pres_output) .sub(%r{.*}m, "") .gsub(%r{[0-9a-f-]+}, "_")))) .to be_equivalent_to Xml::C14n.format(html) IsoDoc::WordConvert.new({}) - .convert("test", presxml, false) + .convert("test", pres_output, false) expect(File.exist?("test.doc")).to be true html = File.read("test.doc") .sub(/^.* INPUT presxml = <<~PRESXML - - Table of contents + + #{' '} + Table of contents + + PRESXML - expect(Xml::C14n.format(strip_guid(IsoDoc::PresentationXMLConvert.new(presxml_options) + expect(Xml::C14n.format(strip_guid(IsoDoc::PresentationXMLConvert + .new(presxml_options) .convert("test", input, true) .sub(%r{.*}m, "")))) .to be_equivalent_to Xml::C14n.format(presxml) @@ -562,7 +634,9 @@ en - Table of contents + #{' '} + Table of contents +

[110] @@ -578,7 +652,7 @@

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. @@ -738,7 +812,13 @@ en - Foreword + + Foreword + + + Foreword + +

[110] [1] @@ -751,12 +831,26 @@

- Table of contents + Table of contents
OUTPUT - expect(Xml::C14n.format(strip_guid(IsoDoc::PresentationXMLConvert.new(presxml_options) + expect(Xml::C14n.format(strip_guid(IsoDoc::PresentationXMLConvert + .new(presxml_options) .convert("test", input, true) .sub(%r{.*}m, "")))) .to be_equivalent_to Xml::C14n.format(presxml) @@ -942,19 +1063,44 @@ en - Foreword + + Foreword + + + Foreword + +

[110] ISO 16634:-- (all parts)

- Table of contents + Table of contents + + + Table of contents + +
- 1.<tab/>Normative References + Normative References + + + 1 + . + + + + Normative References + + + + Clause + 1 +

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. @@ -995,9 +1141,10 @@ OUTPUT - expect(Xml::C14n.format(strip_guid(IsoDoc::PresentationXMLConvert.new(presxml_options) - .convert("test", input, true) - .sub(%r{.*}m, "")))) + expect(Xml::C14n.format(strip_guid(IsoDoc::PresentationXMLConvert + .new(presxml_options) + .convert("test", input, true) + .sub(%r{.*}m, "")))) .to be_equivalent_to Xml::C14n.format(presxml) end @@ -1029,8 +1176,14 @@ INPUT presxml = <<~PRESXML - Foreword -

+ + Foreword + + + Foreword + + +

IEC 217

@@ -1053,7 +1206,22 @@

- Normative References + + Normative References + + + 1 + . + + + + Normative References + + + + Clause + 1 +

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.

Cereals or cereal products @@ -1070,16 +1238,22 @@
INPUT presxml = <<~PRESXML - Foreword -

+ + Foreword + + + Foreword + + +

ISO 712 / IEC 217

PRESXML - expect(Xml::C14n.format(Nokogiri::XML( + expect(Xml::C14n.format(strip_guid(Nokogiri::XML( IsoDoc::PresentationXMLConvert.new(presxml_options) .convert("test", input, true), - ).at("//xmlns:foreword").to_xml)) + ).at("//xmlns:foreword").to_xml))) .to be_equivalent_to Xml::C14n.format(presxml) end @@ -1106,8 +1280,13 @@ INPUT presxml = <<~PRESXML - - Bibliography + + Bibliography + + + Bibliography + + Cereals or cereal products. [1] @@ -1130,10 +1309,10 @@ PRESXML - expect(Xml::C14n.format(Nokogiri::XML( + expect(Xml::C14n.format(strip_guid(Nokogiri::XML( IsoDoc::PresentationXMLConvert.new(presxml_options) .convert("test", input, true), - ).at("//xmlns:bibliography").to_xml)) + ).at("//xmlns:bibliography").to_xml))) .to be_equivalent_to Xml::C14n.format(presxml) end @@ -1160,8 +1339,13 @@ INPUT presxml = <<~PRESXML - - Bibliography + + Bibliography + + + Bibliography + + Cereals or cereal products. [1] @@ -1178,10 +1362,10 @@ PRESXML - expect(Xml::C14n.format(Nokogiri::XML( + expect(Xml::C14n.format(strip_guid(Nokogiri::XML( IsoDoc::PresentationXMLConvert.new(presxml_options) .convert("test", input, true), - ).at("//xmlns:bibliography").to_xml)) + ).at("//xmlns:bibliography").to_xml))) .to be_equivalent_to Xml::C14n.format(presxml) end @@ -1208,8 +1392,13 @@ INPUT presxml = <<~PRESXML - - Bibliography + + Bibliography + + + Bibliography + + Cereals or cereal products. [1] @@ -1232,10 +1421,10 @@ PRESXML - expect(Xml::C14n.format(Nokogiri::XML( + expect(Xml::C14n.format(strip_guid(Nokogiri::XML( IsoDoc::PresentationXMLConvert.new(presxml_options) .convert("test", input, true), - ).at("//xmlns:bibliography").to_xml)) + ).at("//xmlns:bibliography").to_xml))) .to be_equivalent_to Xml::C14n.format(presxml) end @@ -1269,11 +1458,21 @@ INPUT presxml = <<~PRESXML - - 1. - <tab/> - Normative References - + Normative References + + + 1 + . + + + + Normative References + + + + Clause + 1 +

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. @@ -1342,13 +1541,14 @@ OUTPUT - doc = IsoDoc::PresentationXMLConvert.new(presxml_options) + pres_output = IsoDoc::PresentationXMLConvert + .new(presxml_options) .convert("test", input, true) - expect(Xml::C14n.format(strip_guid(Nokogiri::XML(doc) - .at("//xmlns:references").to_xml))) + expect(Xml::C14n.format(strip_guid(Nokogiri::XML(pres_output) + .at("//xmlns:references").to_xml))) .to be_equivalent_to Xml::C14n.format(presxml) expect(Xml::C14n.format(strip_guid(IsoDoc::HtmlConvert.new({}) - .convert("test", doc, true)))) + .convert("test", pres_output, true)))) .to be_equivalent_to Xml::C14n.format(html) end @@ -1380,7 +1580,21 @@ INPUT presxml = <<~PRESXML - 1.<tab/>Normative References + Normative References + + + 1 + . + + + + Normative References + + + + Clause + 1 +

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.

International Organization for Standardization and International Electrotechnical Commission. International vocabulary of metrology — Basic and general concepts and associated terms (VIM). First edition. 2007. https://www.iso.org/standard/45324.html. [viewed: #{Date.today.strftime('%B %-d, %Y')}]. @@ -1409,13 +1623,14 @@ OUTPUT - doc = IsoDoc::PresentationXMLConvert.new(presxml_options) + pres_output = IsoDoc::PresentationXMLConvert + .new(presxml_options) .convert("test", input, true) - expect(strip_guid(Xml::C14n.format(Nokogiri::XML(doc) - .at("//xmlns:references").to_xml))) + expect(Xml::C14n.format(strip_guid(Nokogiri::XML(pres_output) + .at("//xmlns:references").to_xml))) .to be_equivalent_to Xml::C14n.format(presxml) - expect(strip_guid(Xml::C14n.format(IsoDoc::HtmlConvert.new({}) - .convert("test", doc, true)))) + expect(Xml::C14n.format(strip_guid(IsoDoc::HtmlConvert.new({}) + .convert("test", pres_output, true)))) .to be_equivalent_to Xml::C14n.format(html) end @@ -1484,12 +1699,26 @@ - Table of contents + Table of contents - 1.<tab/>Normative References + Normative References + + + 1 + . + + + + Normative References + + + + Clause + 1 +

Text

@@ -1504,7 +1733,21 @@

More text

- 1.1.<tab/>Normative 1 + Normative 1 + + + 1.1 + . + + + + Normative 1 + + + + Clause + 1.1 + Standard @@ -1519,7 +1762,12 @@
- Bibliography + Bibliography + + + Bibliography + +

Text

@@ -1534,7 +1782,12 @@

More text

- Bibliography 1 + Bibliography 1 + + + Bibliography 1 + + Standard @@ -1606,14 +1859,14 @@ OUTPUT - doc = IsoDoc::PresentationXMLConvert.new(presxml_options) + pres_output = IsoDoc::PresentationXMLConvert.new(presxml_options) .convert("test", input, true) - xml = Nokogiri::XML(doc) + xml = Nokogiri::XML(pres_output) xml.at("//xmlns:localized-strings").remove expect(strip_guid(Xml::C14n.format(xml.to_xml))) .to be_equivalent_to Xml::C14n.format(presxml) expect(strip_guid(Xml::C14n.format(IsoDoc::HtmlConvert.new({}) - .convert("test", doc, true)))) + .convert("test", pres_output, true)))) .to be_equivalent_to Xml::C14n.format(html) end @@ -1641,10 +1894,11 @@

OUTPUT - xml = Nokogiri::XML(IsoDoc::PresentationXMLConvert + pres_output = IsoDoc::PresentationXMLConvert .new(presxml_options) - .convert("test", input, true)) - expect(strip_guid(Xml::C14n.format(xml.at("//xmlns:foreword").to_xml))) + .convert("test", input, true) + expect(strip_guid(Xml::C14n.format(Nokogiri::XML(pres_output) + .at("//xmlns:foreword").to_xml))) .to be_equivalent_to Xml::C14n.format(presxml) end @@ -1675,33 +1929,90 @@ INPUT presxml = <<~OUTPUT - - - Table of contents - - - - - 1.<tab/>First References - - 1.1.<tab/>Normative References 1 - - - 1.2.<tab/>Normative References 2 - - - - - - Bibliography - - Bibliography Subsection 1 - - - Bibliography Subsection 2 - - - + + + Table of contents + + + + + First References + + + 1 + . + + + + First References + + + + Clause + 1 + + + Normative References 1 + + + 1.1 + . + + + + Normative References 1 + + + + Clause + 1.1 + + + + Normative References 2 + + + 1.2 + . + + + + Normative References 2 + + + + Clause + 1.2 + + + + + + + Bibliography + + + Bibliography + + + + Bibliography Subsection 1 + + + Bibliography Subsection 1 + + + + + Bibliography Subsection 2 + + + Bibliography Subsection 2 + + + + + OUTPUT @@ -1730,10 +2041,14 @@ OUTPUT - expect(Xml::C14n.format(strip_guid(IsoDoc::PresentationXMLConvert.new(presxml_options) - .convert("test", input, true)))).to be_equivalent_to Xml::C14n.format(presxml) - expect(Xml::C14n.format(IsoDoc::HtmlConvert.new({}) - .convert("test", presxml, true))).to be_equivalent_to Xml::C14n.format(html) + pres_output = IsoDoc::PresentationXMLConvert + .new(presxml_options) + .convert("test", input, true) + expect(Xml::C14n.format(strip_guid(pres_output))) + .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) end it "sets NO ID to nil" do @@ -1758,12 +2073,26 @@ - Table of contents + Table of contents - 1.<tab/>Normative References 2 + Normative References 2 + + + 1 + . + + + + Normative References 2 + + + + Clause + 1 + Reference 2 (NO ID), @@ -1776,7 +2105,7 @@ OUTPUT expect(Xml::C14n.format(strip_guid(IsoDoc::PresentationXMLConvert.new(presxml_options) .convert("test", input, true)) - .sub(%r{.*}m, ""))) + .sub(%r{.*}m, ""))) .to be_equivalent_to Xml::C14n.format(presxml) mock_i18n @@ -1787,12 +2116,26 @@ - + <fmt-title depth="1"/> </clause> </preface> <sections> <references id="C" obligation="informative" normative="true" displayorder="2"> - <title depth="1">1.<tab/>Normative References 2 + Normative References 2 + + + 1 + . + + + + Normative References 2 + + + + klaŭzo + 1 + Reference 2 @@ -1805,7 +2148,7 @@ OUTPUT expect(Xml::C14n.format(strip_guid(IsoDoc::PresentationXMLConvert.new(presxml_options) .convert("test", input.sub(">en<", ">eo<"), true)) - .sub(%r{.*}m, ""))) + .sub(%r{.*}m, ""))) .to be_equivalent_to Xml::C14n.format(presxml) end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 614a70aa..03b1ef06 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -66,9 +66,11 @@ def strip_guid(xml) .gsub(%r{ target="_[^"]+"}, ' target="_"') .gsub(%r{ source="_[^"]+"}, ' source="_"') .gsub(%r( href="#_?[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12,13}"), ' href="#_"') + .gsub(%r( href="#fn:[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12,13}"), ' href="#fn:_"') .gsub(%r( id="[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12,13}"), ' id="_"') .gsub(%r( id="ftn[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{13}"), ' id="ftn_"') - .gsub(%r( id="fn:[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{13}"), ' id="fn:_"') + .gsub(%r( id="fn:[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12,13}"), ' id="fn:_"') + .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/_.') end