require "spec_helper" require "nokogiri" RSpec.describe IsoDoc::Iso::Metadata do it "processes IsoXML metadata" do c = IsoDoc::Iso::HtmlConvert.new({}) _ = c.convert_init(<<~"INPUT", "test", false) INPUT input = <<~INPUT Cereals and pulses Specifications and test methods Rice Céréales et légumineuses Spécification et méthodes d'essai Riz ISO/PreCD3 17301-1 ISO/PreCD3 17301-1 (E) ISO/PreCD3 17301-1:2000 (E) 17301 17302 1730 2011 2012 2010 2011 2013 2014 2 2016-05-01 0.4 ISO International Organization for Standardization ISO en 30 92 3 2016 ISO kw2 kw1 international-standard true Food products Cereals and pulses Rice Group GB Food products A Cereals and pulses A Rice Group A ISO/PreCD3 17301 Committee draft INPUT output = <<~OUTPUT {:accesseddate=>"2012", :activateddate=>"2013", :agency=>"ISO", :approvalgroup=>["TC 34a", "SC 4a", "WG 3a"], :createddate=>"2010–2011", :docnumber=>"ISO/PreCD3 17301-1", :docnumber_lang=>"ISO/PreCD3 17301-1 (E)", :docnumber_reference=>"ISO/PreCD3 17301-1:2000 (E)", :docnumeric=>"1730", :docsubtitle=>"Céréales et légumineuses — Spécification et méthodes d'essai — Partie 1: Riz", :docsubtitleintro=>"Céréales et légumineuses", :docsubtitlemain=>"Spécification et méthodes d'essai", :docsubtitlepart=>"Riz", :docsubtitlepartlabel=>"Partie 1", :doctitle=>"Cereals and pulses — Specifications and test methods — Part 1: Rice", :doctitleintro=>"Cereals and pulses", :doctitlemain=>"Specifications and test methods", :doctitlepart=>"Rice", :doctitlepartlabel=>"Part 1", :doctype=>"International Standard", :doctype_display=>"International Standard", :docyear=>"2016", :draft=>"0.4", :draftinfo=>" (draft 0.4, 2016-05-01)", :edition=>"2", :editorialgroup=>["TC 34", "SC 4", "WG 3"], :horizontal=>"true", :keywords=>["kw2", "kw1"], :lang=>"en", :obsoleteddate=>"2014", :publisheddate=>"2011", :publisher=>"International Organization for Standardization", :revdate=>"2016-05-01", :revdate_monthyear=>"May 2016", :sc=>"SC 4", :script=>"Latn", :secretariat=>"GB", :stage=>"30", :stage_int=>30, :stageabbr=>"CD", :statusabbr=>"PreCD3", :substage_int=>"92", :tc=>"TC 34", :tc_docnumber=>["17301", "17302"], :unpublished=>true, :wg=>"WG 3"} OUTPUT expect(metadata(c.info(Nokogiri::XML(input), nil))).to be_equivalent_to output end it "processes IsoXML metadata #2" do c = IsoDoc::Iso::HtmlConvert.new({}) _ = c.convert_init(<<~"INPUT", "test", false) INPUT input = <<~INPUT Cereals and pulses Specifications and test methods Rice ISO/IEC/CD 17301-1-3 ISO/IEC/CD 17301-1-3 (E) ISO/IEC/CD 17301-1-3 (E) 17301 ISO International Organization for Standardization ISO International Electrotechnical Commission IEC en 60 92 2016 International Organization for Standardization 3.1 IEC 8121 international-standard Food products Cereals and pulses Rice Group Food products Cereals and pulses Rice Group 1.2.3 1.2.3 ISO/IEC/CD 17301 International standard INPUT output = <<~OUTPUT {:agency=>"ISO/IEC", :approvalgroup=>["ABC 34", "DEF 4", "GHI 3"], :docnumber=>"ISO/IEC/CD 17301-1-3", :docnumber_lang=>"ISO/IEC/CD 17301-1-3 (E)", :docnumber_reference=>"ISO/IEC/CD 17301-1-3 (E)", :docsubtitlepartlabel=>"Partie 1–3", :doctitle=>"Cereals and pulses — Specifications and test methods — Part 1–3: Rice", :doctitleintro=>"Cereals and pulses", :doctitlemain=>"Specifications and test methods", :doctitlepart=>"Rice", :doctitlepartlabel=>"Part 1–3", :doctype=>"International Standard", :doctype_display=>"International Standard", :docyear=>"2016", :editorialgroup=>["ABC 34", "DEF 4", "GHI 3"], :ics=>"1.2.3, 1.2.3", :lang=>"en", :obsoletes=>"IEC 8121", :obsoletes_part=>"3.1", :publisher=>"International Organization for Standardization and International Electrotechnical Commission", :sc=>"DEF 4", :script=>"Latn", :stage=>"60", :stage_int=>60, :statusabbr=>"IS", :substage_int=>"92", :tc=>"ABC 34", :tc_docnumber=>["17301"], :unpublished=>false, :wg=>"GHI 3"} OUTPUT expect(metadata(c.info(Nokogiri::XML(input), nil))).to be_equivalent_to output end it "processes IsoXML metadata in French" do c = IsoDoc::Iso::HtmlConvert.new({}) _ = c.convert_init(<<~"INPUT", "test", false) fr INPUT input = <<~INPUT Cereals and pulses Specifications and test methods Rice Céréales et légumineuses Spécification et méthodes d'essai Riz ISO/IEC/CD 17301-1-3 ISO/IEC/CD 17301-1-3 (E) ISO/IEC/CD 17301-1-3 (E) 17301 ISO International Organization for Standardization ISO International Electrotechnical Commission IEC fr 60 92 2016 International Organization for Standardization 3.1 IEC 8121 international-standard Standard International Food products Cereals and pulses Rice Group 1.2.3 1.2.3 ISO/IEC/CD 17301 International standard INPUT output = <<~OUTPUT {:agency=>"ISO/IEC", :docnumber=>"ISO/IEC/CD 17301-1-3", :docnumber_lang=>"ISO/IEC/CD 17301-1-3 (E)", :docnumber_reference=>"ISO/IEC/CD 17301-1-3 (E)", :docsubtitle=>"Cereals and pulses — Specifications and test methods — Part 1–3: Rice", :docsubtitleintro=>"Cereals and pulses", :docsubtitlemain=>"Specifications and test methods", :docsubtitlepart=>"Rice", :docsubtitlepartlabel=>"Part 1–3", :doctitle=>"Céréales et légumineuses — Spécification et méthodes d'essai — Partie 1–3: Riz", :doctitleintro=>"Céréales et légumineuses", :doctitlemain=>"Spécification et méthodes d'essai", :doctitlepart=>"Riz", :doctitlepartlabel=>"Partie 1–3", :doctype=>"International Standard", :doctype_display=>"Standard International", :docyear=>"2016", :editorialgroup=>["ABC 34", "DEF 4", "GHI 3"], :ics=>"1.2.3, 1.2.3", :lang=>"fr", :obsoletes=>"IEC 8121", :obsoletes_part=>"3.1", :publisher=>"International Organization for Standardization et International Electrotechnical Commission", :sc=>"DEF 4", :script=>"Latn", :stage=>"60", :stage_int=>60, :statusabbr=>"IS", :substage_int=>"92", :tc=>"ABC 34", :tc_docnumber=>["17301"], :unpublished=>false, :wg=>"GHI 3"} OUTPUT expect(metadata(c.info(Nokogiri::XML(input), nil))).to be_equivalent_to output end it "processes IsoXML metadata in Russian" do c = IsoDoc::Iso::HtmlConvert.new({}) _ = c.convert_init(<<~"INPUT", "test", false) ru INPUT input = <<~INPUT Cereals and pulses Specifications and test methods Rice Céréales et légumineuses Spécification et méthodes d'essai Riz Зерновые и бобовые Технические характеристики и методы испытаний Рис ISO/IEC/CD 17301-1-3 ISO/IEC/CD 17301-1-3 (E) ISO/IEC/CD 17301-1-3 (E) 17301 ISO International Organization for Standardization ISO International Electrotechnical Commission IEC ru 60 92 2016 International Organization for Standardization 3.1 IEC 8121 international-standard Standard International Food products Cereals and pulses Rice Group 1.2.3 1.2.3 ISO/IEC/CD 17301 International standard INPUT output = <<~OUTPUT {:agency=>"ISO/IEC", :docnumber=>"ISO/IEC/CD 17301-1-3", :docnumber_lang=>"ISO/IEC/CD 17301-1-3 (E)", :docnumber_reference=>"ISO/IEC/CD 17301-1-3 (E)", :docsubtitle=>"Cereals and pulses — Specifications and test methods — Part 1–3: Rice", :docsubtitleintro=>"Cereals and pulses", :docsubtitlemain=>"Specifications and test methods", :docsubtitlepart=>"Rice", :docsubtitlepartlabel=>"Part 1–3", :doctitle=>"Зерновые и бобовые — Технические характеристики и методы испытаний — Часть 1–3: Рис", :doctitleintro=>"Зерновые и бобовые", :doctitlemain=>"Технические характеристики и методы испытаний", :doctitlepart=>"Рис", :doctitlepartlabel=>"Часть 1–3", :doctype=>"International Standard", :doctype_display=>"International Standard", :docyear=>"2016", :editorialgroup=>["ABC 34", "DEF 4", "GHI 3"], :ics=>"1.2.3, 1.2.3", :lang=>"ru", :obsoletes=>"IEC 8121", :obsoletes_part=>"3.1", :publisher=>"International Organization for Standardization и International Electrotechnical Commission", :sc=>"DEF 4", :script=>"Latn", :stage=>"60", :stage_int=>60, :statusabbr=>"IS", :substage_int=>"92", :tc=>"ABC 34", :tc_docnumber=>["17301"], :unpublished=>false, :wg=>"GHI 3"} OUTPUT expect(metadata(c.info(Nokogiri::XML(input), nil))).to be_equivalent_to output end it "warns of missing Secretariat" do input = <<~INPUT Specifications and test methods 30 2000 Clause 1 INPUT output = <<~OUTPUT <review date="#{Date.today}" reviewer="Metanorma" id="_"> <p> <strong> Metadata warnings: <strong/> <p>Secretariat is missing.</p> </strong> </p> </review> Clause 1 OUTPUT expect(xmlpp(strip_guid(Nokogiri::XML( IsoDoc::Iso::PresentationXMLConvert.new({}) .convert("test", input, true), ) .at("//xmlns:sections").to_xml))) .to be_equivalent_to xmlpp(output) end it "warns of missing publication date" do input = <<~INPUT Specifications and test methods 30 BSI Clause 1 INPUT output = <<~OUTPUT <review date="#{Date.today}" reviewer="Metanorma" id="_"> <p> <strong> Metadata warnings: <strong/> <p>Document date is missing.</p> </strong> </p> </review> Clause 1 OUTPUT expect(strip_guid(xmlpp(Nokogiri::XML( IsoDoc::Iso::PresentationXMLConvert.new({}) .convert("test", input, true), ) .at("//xmlns:sections") .at("//xmlns:sections").to_xml))) .to be_equivalent_to xmlpp(output) end it "warns of missing editorial groups" do input = <<~INPUT Specifications and test methods 30 2000 BSI Clause 1 INPUT output = <<~OUTPUT <review date="#{Date.today}" reviewer="Metanorma" id="_"> <p> <strong> Metadata warnings: <strong/> <p>Editorial groups are missing.</p> </strong> </p> </review> Clause 1 OUTPUT expect(strip_guid(xmlpp(Nokogiri::XML( IsoDoc::Iso::PresentationXMLConvert.new({}) .convert("test", input, true), ) .at("//xmlns:sections") .at("//xmlns:sections").to_xml))) .to be_equivalent_to xmlpp(output) end it "does not warn of missing metadata in compliant document" do input = <<~INPUT Specifications and test methods 30 2000 BSI Clause 1 INPUT output = <<~OUTPUT Clause 1 OUTPUT expect(strip_guid(xmlpp(Nokogiri::XML( IsoDoc::Iso::PresentationXMLConvert.new({}) .convert("test", input, true), ) .at("//xmlns:sections").to_xml))) .to be_equivalent_to xmlpp(output) end it "does not warn of missing metadata in published document" do input = <<~INPUT Specifications and test methods 90 BSI Clause 1 INPUT output = <<~OUTPUT Clause 1 OUTPUT expect(strip_guid(xmlpp(Nokogiri::XML( IsoDoc::Iso::PresentationXMLConvert.new({}) .convert("test", input, true), ) .at("//xmlns:sections").to_xml))) .to be_equivalent_to xmlpp(output) end end