require "spec_helper" require "fileutils" RSpec.describe Metanorma::Standoc do it "has a version number" do expect(Metanorma::Standoc::VERSION).not_to be nil end it "applies Asciidoctor substitutions" do expect(Metanorma::Utils.asciidoc_sub("A -- B")) .to eq "A — B" expect(Metanorma::Utils.asciidoc_sub("*A* stem:[x]")) .to eq "A x" end it "processes named entities" do FileUtils.rm_f "test.doc" input = <<~INPUT = Document title Author :docfile: test.adoc :novalid: :no-pdf: Text × text INPUT output = <<~OUTPUT Document title en published #{Time.now.year} standard

Text × text

OUTPUT expect(xmlpp(strip_guid(Asciidoctor.convert(input, *OPTIONS)))) .to be_equivalent_to xmlpp(output) end it "assigns default scripts to major languages" do FileUtils.rm_f "test.doc" input = <<~INPUT = Document title Author :docfile: test.adoc :novalid: :no-pdf: :language: ar INPUT output = <<~OUTPUT Document title ar published #{Time.now.year} standard OUTPUT expect(xmlpp(Asciidoctor.convert(input, *OPTIONS))) .to be_equivalent_to xmlpp(output) end it "processes publisher abbreviations" do mock_org_abbrevs input = <<~INPUT = Document title Author :docfile: test.adoc :nodoc: :novalid: :publisher: International Electrotechnical Commission;IETF;ISO INPUT output = <<~OUTPUT Document title International Electrotechnical Commission IEC IETF International Standards Organization ISO International Electrotechnical Commission IEC IETF International Standards Organization ISO en published #{Time.now.year} International Electrotechnical Commission IEC #{Time.now.year} IETF #{Time.now.year} International Standards Organization ISO standard OUTPUT expect(xmlpp(Asciidoctor.convert(input, *OPTIONS))) .to be_equivalent_to xmlpp(output) end it "processes default metadata" do input = <<~INPUT = Document title Author :docfile: test.adoc :nodoc: :novalid: :docnumber: 1000 :partnumber: 1 :edition: 2 :revdate: 2000-01-01 :published-date: 1000-01-01 :accessed-date: 1001-01-01 :created-date: 1002-01-01 :implemented-date: 1003-01-01 :obsoleted-date: 1004-01-01 :confirmed-date: 1005-01-01 :updated-date: 1006-01-01 :issued-date: 1007-01-01 :circulated-date: 1008-01-01 :unchanged-date: 1009-01-01 :vote-started-date: 1011-01-01 :vote-ended-date: 1012-01-01 :date: Fred 1010-01-01 :date_2: Jack 1010-01-01 :draft: 3.4 :technical-committee: TC :technical-committee-number: 1 :technical-committee-type: A :subcommittee: SC :subcommittee-number: 2 :subcommittee-type: B :workgroup: WG :workgroup-number: 3 :workgroup-type: C :technical-committee_2: TC1 :technical-committee-number_2: 11 :technical-committee-type_2: A1 :subcommittee_2: SC1 :subcommittee-number_2: 21 :subcommittee-type_2: B1 :workgroup_2: WG1 :workgroup-number_2: 31 :workgroup-type_2: C1 :secretariat: SECRETARIAT :copyright-year: 2001 :docstage: 10 :docsubstage: 20 :iteration: 3 :language: en :title: Main Title -- Title :library-ics: 01.040.11,11.060.01 :fullname: Fred Flintstone :role: author :affiliation: Slate Rock and Gravel Company :affiliation_abbrev: SRG :affiliation_subdiv: Hermeneutics Unit; Exegetical Subunit :address: 6 Rubble Way, Bedrock :contributor-uri: http://slate.example.com :phone: 123 :fax: 456 :surname_2: Rubble :givenname_2: Barney :initials_2: B. X. :role_2: editor :affiliation_2: Rockhead and Quarry Cave Construction Company :affiliation_abbrev_2: RQCCC :affiliation_subdiv_2: Hermeneutics Unit; Exegetical Subunit :address_2: 6A Rubble Way, + \\ Bedrock :email_2: barney@rockhead.example.com :phone_2: 789 :fax_2: 012 :publisher: "Hanna Barbera"; "Cartoon Network"; "Ribose, Inc." :copyright-holder: "Ribose, Inc."; Hanna Barbera :part-of: ABC :translated-from: DEF,GHI;JKL MNO,PQR :keywords: a, b, c :pub-address: 1 Infinity Loop + \\ California :pub-phone: 3333333 :pub-fax: 4444444 :pub-email: x@example.com :pub-uri: http://www.example.com :isbn: ISBN-13 :isbn10: ISBN-10 :classification: a:b, c :toclevels: 2 :doctoclevels: 3 :htmltoclevels: 4 INPUT output = <<~OUTPUT Main Title — Title 1000-1 ISBN-13 ISBN-10 1000 1000-01-01 1001-01-01 1002-01-01 1003-01-01 1004-01-01 1005-01-01 1006-01-01 1007-01-01 1008-01-01 1009-01-01 1011-01-01 1012-01-01 1010-01-01 1010-01-01 Hanna Barbera Cartoon Network Ribose, Inc. Fred Flintstone Slate Rock and Gravel Company SRG Hermeneutics Unit Exegetical Subunit
6 Rubble Way, Bedrock
123 456 http://slate.example.com
Barney B. X. Rubble Rockhead and Quarry Cave Construction Company RQCCC Hermeneutics Unit Exegetical Subunit
6A Rubble Way,
Bedrock
789 012 barney@rockhead.example.com
Hanna Barbera
1 Infinity Loop
California
3333333 4444444 x@example.com http://www.example.com
Cartoon Network
1 Infinity Loop
California
3333333 4444444 x@example.com http://www.example.com
Ribose, Inc.
1 Infinity Loop
California
3333333 4444444 x@example.com http://www.example.com
2 2000-01-01 3.4 en 10 20 3 2001 Ribose, Inc.
1 Infinity Loop
California
3333333 4444444 x@example.com http://www.example.com
2001 Hanna Barbera
1 Infinity Loop
California
3333333 4444444 x@example.com http://www.example.com
-- ABC GHI DEF PQR JKL MNO b c a b c standard TC TC1 01.040.11 Health care technology (Vocabularies) 11.060.01 Dentistry in general
TOC Heading Levels 2 TOC Heading Levels 2 TOC Heading Levels 2
OUTPUT expect(xmlpp(Asciidoctor.convert(input, *OPTIONS))) .to be_equivalent_to xmlpp(output) end it "processes complex metadata" do input = <<~INPUT = Document title Author :docfile: test.adoc :nodoc: :novalid: :revdate: 2000-01 :published-date: 1000-01 :docnumber: 1000 :partnumber: 1-1 :tc-docnumber: 2000 :language: el :script: Grek :locale: CY :publisher: IEC;IETF;ISO :uri: A :xml-uri: B :html-uri: C :pdf-uri: D :doc-uri: E :relaton-uri: F :title-eo: Dokumenttitolo :doctype: This is a DocType :docsubtype: This is a DocSubType :subdivision: Subdivision :subdivision-abbr: SD :fullname: Fred Flintstone :affiliation: Slate Rock and Gravel Company :street: 1 Infinity Loop :city: Cupertino :state: CA :country: USA :postcode: 95014 :fullname_2: Barney Rubble :affiliation_2: Slate Rock and Gravel Company :street_2: Pavillon de Breteuil :city_2: Sèvres CEDEX :country_2: France :postcode_2: F-92312 :semantic-metadata-hello-world: A, B, "C, D" :semantic-metadata-hello: what-not :presentation-metadata-hello: Hello? :presentation-metadata-Manifold: "hello, world","yes" [abstract] == Abstract This is the abstract of the document This is the second paragraph of the abstract of the document. [language=en] == Clause 1 INPUT output = <<~OUTPUT Document title Dokumenttitolo A B C D E F 1000-1-1 1000 1000-01 IEC IETF ISO Fred Flintstone Slate Rock and Gravel Company
1 Infinity Loop Cupertino CA USA 95014
Barney Rubble Slate Rock and Gravel Company
Pavillon de Breteuil Sèvres CEDEX France F-92312
IEC IETF ISO 2000-01 el CY

This is the abstract of the document

This is the second paragraph of the abstract of the document.

published #{Date.today.year} IEC #{Date.today.year} IETF #{Date.today.year} ISO this-is-a-doctype This is a DocSubType
A B C, D what-not Hello? hello, world yes Abstract

This is the abstract of the document

This is the second paragraph of the abstract of the document.

Clause 1
OUTPUT expect(xmlpp(strip_guid(Asciidoctor.convert(input, *OPTIONS)))) .to be_equivalent_to xmlpp(output) end it "processes formatted address overridding address components" do input = <<~INPUT = Document title Author :docfile: test.adoc :nodoc: :novalid: :fullname: Fred Flintstone :affiliation: Slate Rock and Gravel Company :address: Address :city: Utopia :fullname_2: Barney Rubble :affiliation_2: Slate Rock and Gravel Company :city_2: Utopia INPUT output = <<~OUTPUT Document title Fred Flintstone Slate Rock and Gravel Company
Address
Barney Rubble Slate Rock and Gravel Company
Utopia
en published #{Time.now.year} standard
OUTPUT expect(xmlpp(Asciidoctor.convert(input, *OPTIONS))) .to be_equivalent_to xmlpp(output) end it "processes subdivisions" do mock_default_publisher input = <<~INPUT = Document title Author :docfile: test.adoc :nodoc: :novalid: :revdate: 2000-01 :published-date: 1000-01 :docnumber: 1000 :partnumber: 1-1 :tc-docnumber: 2000 :language: el :script: Grek :subdivision: Subdivision :subdivision-abbr: SD :doctype: This is a DocType :pub-address: 1 Infinity Loop + \\ California :pub-phone: 3333333 :pub-fax: 4444444 :pub-email: x@example.com :pub-uri: http://www.example.com INPUT output = <<~OUTPUT Document title 1000-1-1 1000 1000-01 International Standards Organization Subdivision SD International Standards Organization Subdivision SD
1 Infinity Loop
California
3333333 4444444 x@example.com http://www.example.com
2000-01 el published #{Time.now.year} International Standards Organization Subdivision SD
1 Infinity Loop
California
3333333 4444444 x@example.com http://www.example.com
this-is-a-doctype
OUTPUT expect(xmlpp(Asciidoctor.convert(input, *OPTIONS))) .to be_equivalent_to xmlpp(output) end it "processes document relations by description" do mock_relaton_relation_descriptions input = <<~INPUT = Document title Author :docfile: test.adoc :nodoc: :novalid: :normatively-cited-in: ABC INPUT output = <<~OUTPUT Document title en published #{Time.now.year} normatively cited in -- ABC standard OUTPUT expect(xmlpp(Asciidoctor.convert(input, *OPTIONS))) .to be_equivalent_to xmlpp(output) end it "reads scripts into blank HTML document" do FileUtils.rm_f "test.html" Asciidoctor.convert(<<~"INPUT", *OPTIONS) = Document title Author :docfile: test.adoc :novalid: :no-pdf: :scripts: spec/assets/scripts.html INPUT html = File.read("test.html", encoding: "utf-8") expect(html).to match(%r{