require "spec_helper" require "iecbib" require "fileutils" RSpec.describe Asciidoctor::Standoc do it "applies smartquotes by default" do expect(strip_guid(Asciidoctor.convert(<<~"INPUT", backend: :standoc, header_footer: true))).to be_equivalent_to <<~"OUTPUT" #{ASCIIDOC_BLANK_HDR} == "Quotation" INPUT #{BLANK_HDR} “Quotation” OUTPUT end it "applies smartquotes when requested" do expect(strip_guid(Asciidoctor.convert(<<~"INPUT", backend: :standoc, header_footer: true))).to be_equivalent_to <<~"OUTPUT" = Document title Author :docfile: test.adoc :nodoc: :novalid: :no-isobib: :smartquotes: true == "Quotation" INPUT #{BLANK_HDR} “Quotation” OUTPUT end it "does not apply smartquotes when requested not to" do expect(strip_guid(Asciidoctor.convert(<<~"INPUT", backend: :standoc, header_footer: true))).to be_equivalent_to <<~"OUTPUT" = Document title Author :docfile: test.adoc :nodoc: :novalid: :no-isobib: :smartquotes: false == "Quotation" INPUT #{BLANK_HDR} "Quotation" OUTPUT end it "does not apply smartquotes to sourcecode, tt, pre" do expect(strip_guid(Asciidoctor.convert(<<~"INPUT", backend: :standoc, header_footer: true))).to be_equivalent_to <<~"OUTPUT" = Document title Author :docfile: test.adoc :nodoc: :novalid: :no-isobib: :smartquotes: true == "Quotation" "Quotation" `"quote"` [source] ---- "quote" ---- INPUT #{BLANK_HDR} “Quotation”

“Quotation”

"quote"

"quote"
OUTPUT end it "handles < > & in Asciidoctor correctly" do expect(strip_guid(Asciidoctor.convert(<<~"INPUT", backend: :standoc, header_footer: true))).to be_equivalent_to <<~"OUTPUT" #{ASCIIDOC_BLANK_HDR} == {blank} <&> INPUT #{BLANK_HDR}

<&>

OUTPUT end it "removes empty text elements" do expect(strip_guid(Asciidoctor.convert(<<~"INPUT", backend: :standoc, header_footer: true))).to be_equivalent_to <<~"OUTPUT" #{ASCIIDOC_BLANK_HDR} == {blank} INPUT #{BLANK_HDR} OUTPUT end it "processes stem-only terms as admitted" do expect(strip_guid(Asciidoctor.convert(<<~"INPUT", backend: :standoc, header_footer: true))).to be_equivalent_to <<~"OUTPUT" #{ASCIIDOC_BLANK_HDR} == Terms and Definitions === stem:[t_90] stem:[t_91] Time INPUT #{BLANK_HDR} Terms and definitions t90t91

Time

OUTPUT end it "moves term domains out of the term definition paragraph" do expect(strip_guid(Asciidoctor.convert(<<~"INPUT", backend: :standoc, header_footer: true))).to be_equivalent_to <<~"OUTPUT" #{ASCIIDOC_BLANK_HDR} == Terms and Definitions === Tempus domain:[relativity] Time INPUT #{BLANK_HDR} Terms and definitions Tempus relativity

Time

OUTPUT end it "permits multiple blocks in term definition paragraph" do expect(strip_guid(Asciidoctor.convert(<<~"INPUT", backend: :standoc, header_footer: true))).to be_equivalent_to <<~"OUTPUT" = Document title Author :docfile: test.adoc :nodoc: :novalid: :stem: == Terms and Definitions === stem:[t_90] [stem] ++++ t_A ++++ This paragraph is extraneous INPUT #{BLANK_HDR} Terms and definitions t90 tA

This paragraph is extraneous

OUTPUT end it "strips any initial boilerplate from terms and definitions" do expect(strip_guid(Asciidoctor.convert(<<~"INPUT", backend: :standoc, header_footer: true))).to be_equivalent_to <<~"OUTPUT" #{ASCIIDOC_BLANK_HDR} == Terms and Definitions I am boilerplate * So am I === Time This paragraph is extraneous INPUT #{BLANK_HDR} Terms and definitions Time

This paragraph is extraneous

OUTPUT end it "moves notes inside preceding blocks, if they are not at clause end, and the blocks are not delimited" do expect(strip_guid(Asciidoctor.convert(<<~"INPUT", backend: :standoc, header_footer: true))).to be_equivalent_to <<~"OUTPUT" #{ASCIIDOC_BLANK_HDR} [stem] ++++ r = 1 % r = 1 % ++++ NOTE: That formula does not do much Indeed. INPUT #{BLANK_HDR} r = 1 % r = 1 %

That formula does not do much

Indeed.

OUTPUT end it "does not move notes inside preceding blocks, if they are at clause end" do expect(strip_guid(Asciidoctor.convert(<<~"INPUT", backend: :standoc, header_footer: true))).to be_equivalent_to <<~"OUTPUT" #{ASCIIDOC_BLANK_HDR} [source,ruby] [1...x].each do |y| puts y end NOTE: That loop does not do much INPUT #{BLANK_HDR} [1...x].each do |y| puts y end

That loop does not do much

OUTPUT end it "converts xrefs to references into erefs" do expect(strip_guid(Asciidoctor.convert(<<~"INPUT", backend: :standoc, header_footer: true))).to be_equivalent_to <<~"OUTPUT" #{ASCIIDOC_BLANK_HDR} <> [bibliography] == Normative References * [[[iso216,ISO 216:2001]]], _Reference_ INPUT #{BLANK_HDR} Foreword

Normative References Reference ISO 216:2001 2001 ISO OUTPUT end it "extracts localities from erefs" do expect(strip_guid(Asciidoctor.convert(<<~"INPUT", backend: :standoc, header_footer: true))).to be_equivalent_to <<~"OUTPUT" #{ASCIIDOC_BLANK_HDR} <> [bibliography] == Normative References * [[[iso216,ISO 216]]], _Reference_ INPUT #{BLANK_HDR} Foreword

391133the reference

Normative References Reference ISO 216 ISO OUTPUT end it "strips type from xrefs" do expect(strip_guid(Asciidoctor.convert(<<~"INPUT", backend: :standoc, header_footer: true))).to be_equivalent_to <<~"OUTPUT" #{ASCIIDOC_BLANK_HDR} <> [bibliography] == Clause * [[[iso216,ISO 216]]], _Reference_ INPUT #{BLANK_HDR} Foreword

Bibliography Reference ISO 216 ISO OUTPUT end it "processes localities in term sources" do expect(strip_guid(Asciidoctor.convert(<<~"INPUT", backend: :standoc, header_footer: true))).to be_equivalent_to <<~"OUTPUT" #{ASCIIDOC_BLANK_HDR} == Terms and Definitions === Term1 [.source] <> INPUT #{BLANK_HDR} Terms and definitions Term1 1 OUTPUT end it "removes extraneous material from Normative References" do expect(strip_guid(Asciidoctor.convert(<<~"INPUT", backend: :standoc, header_footer: true))).to be_equivalent_to <<~"OUTPUT" #{ASCIIDOC_BLANK_HDR} [bibliography] == Normative References This is extraneous information * [[[iso216,ISO 216]]], _Reference_ INPUT #{BLANK_HDR} Normative References Reference ISO 216 ISO OUTPUT end it "inserts IDs into paragraphs" do expect(strip_guid(Asciidoctor.convert(<<~"INPUT", backend: :standoc, header_footer: true))).to be_equivalent_to <<~"OUTPUT" #{ASCIIDOC_BLANK_HDR} Paragraph INPUT #{BLANK_HDR}

Paragraph

OUTPUT end it "inserts IDs into notes" do expect(strip_guid(Asciidoctor.convert(<<~"INPUT", backend: :standoc, header_footer: true))).to be_equivalent_to <<~"OUTPUT" #{ASCIIDOC_BLANK_HDR} [example] ==== NOTE: This note has no ID ==== INPUT #{BLANK_HDR}

This note has no ID

OUTPUT end it "moves table key inside table" do expect(strip_guid(Asciidoctor.convert(<<~"INPUT", backend: :standoc, header_footer: true))).to be_equivalent_to <<~"OUTPUT" #{ASCIIDOC_BLANK_HDR} |=== |a |b |c |=== Key a:: b INPUT #{BLANK_HDR}
a

b

a b c
OUTPUT end it "processes headerrows attribute for table without header rows" do expect(strip_guid(Asciidoctor.convert(<<~"INPUT", backend: :standoc, header_footer: true))).to be_equivalent_to <<~"OUTPUT" #{ASCIIDOC_BLANK_HDR} [headerrows=3] |=== |a |b |c |a |b |c |a |b |c |a |b |c |=== INPUT #{BLANK_HDR}
a b c
a b c
a b c
a b c
OUTPUT end it "processes headerrows attribute for table with header rows" do expect(strip_guid(Asciidoctor.convert(<<~"INPUT", backend: :standoc, header_footer: true))).to be_equivalent_to <<~"OUTPUT" #{ASCIIDOC_BLANK_HDR} [headerrows=3] |=== |a |b |c |a |b |c |a |b |c |a |b |c |=== INPUT #{BLANK_HDR}
a b c
a b c
a b c
a b c
OUTPUT end it "moves table notes inside table" do expect(strip_guid(Asciidoctor.convert(<<~"INPUT", backend: :standoc, header_footer: true))).to be_equivalent_to <<~"OUTPUT" #{ASCIIDOC_BLANK_HDR} |=== |a |b |c |=== NOTE: Note 1 NOTE: Note 2 INPUT #{BLANK_HDR}

Note 1

Note 2

a b c
OUTPUT end it "moves formula key inside formula" do expect(strip_guid(Asciidoctor.convert(<<~"INPUT", backend: :standoc, header_footer: true))).to be_equivalent_to <<~"OUTPUT" #{ASCIIDOC_BLANK_HDR} [stem] ++++ Formula ++++ Where, a:: b INPUT #{BLANK_HDR} Forμla
a

b

OUTPUT end it "moves footnotes inside figures" do expect(strip_guid(Asciidoctor.convert(<<~"INPUT", backend: :standoc, header_footer: true))).to be_equivalent_to <<~"OUTPUT" #{ASCIIDOC_BLANK_HDR} image::spec/examples/rice_images/rice_image1.png[] footnote:[This is a footnote to a figure] footnote:[This is another footnote to a figure] INPUT #{BLANK_HDR}

This is a footnote to a figure

This is another footnote to a figure

OUTPUT end it "moves figure key inside figure" do expect(strip_guid(Asciidoctor.convert(<<~"INPUT", backend: :standoc, header_footer: true))).to be_equivalent_to <<~"OUTPUT" #{ASCIIDOC_BLANK_HDR} image::spec/examples/rice_images/rice_image1.png[] key: a:: b INPUT #{BLANK_HDR}
a

b

OUTPUT end it "processes subfigures" do expect(strip_guid(Asciidoctor.convert(<<~"INPUT", backend: :standoc, header_footer: true))).to be_equivalent_to <<~"OUTPUT" #{ASCIIDOC_BLANK_HDR} [[figureC-2]] .Stages of gelatinization ==== .Initial stages: No grains are fully gelatinized (ungelatinized starch granules are visible inside the kernels) image::spec/examples/rice_images/rice_image3_1.png[] .Intermediate stages: Some fully gelatinized kernels are visible image::spec/examples/rice_images/rice_image3_2.png[] .Final stages: All kernels are fully gelatinized image::spec/examples/rice_images/rice_image3_3.png[] ==== INPUT #{BLANK_HDR}
Initial stages: No grains are fully gelatinized (ungelatinized starch granules are visible inside the kernels)
Intermediate stages: Some fully gelatinized kernels are visible
Final stages: All kernels are fully gelatinized
OUTPUT end it "numbers bibliographic notes and footnotes sequentially" do expect(strip_guid(Asciidoctor.convert(<<~"INPUT", backend: :standoc, header_footer: true))).to be_equivalent_to <<~"OUTPUT" #{ASCIIDOC_BLANK_HDR} footnote:[Footnote] [bibliography] == Normative References * [[[iso123,ISO 123:--]]] footnote:[The standard is in press] _Standard_ == Clause footnote:[Footnote2] INPUT #{BLANK_HDR} Foreword

Footnote

Clause

Footnote2

Normative References Standard ISO 123:— -- ISO ISO DATE: The standard is in press OUTPUT end it "defaults section obligations" do expect(strip_guid(Asciidoctor.convert(<<~"INPUT", backend: :standoc, header_footer: true))).to be_equivalent_to <<~"OUTPUT" #{ASCIIDOC_BLANK_HDR} == Clause Text [appendix] == Clause Text INPUT #{BLANK_HDR} Clause

Text

Clause

Text

OUTPUT end it "rearranges term note, term example, term source" do expect(strip_guid(Asciidoctor.convert(<<~"INPUT", backend: :standoc, header_footer: true))).to be_equivalent_to <<~"OUTPUT" #{ASCIIDOC_BLANK_HDR} == Terms and definitions === Term [.source] <> NOTE: Note [example] Example 1 NOTE: Note 2 [example] Example 2 INPUT #{BLANK_HDR} Terms and definitions Term

Note

Note 2

Example 1

Example 2

1
OUTPUT end it "extends clause levels past 5" do expect(strip_guid(Asciidoctor.convert(<<~"INPUT", backend: :standoc, header_footer: true))).to be_equivalent_to <<~"OUTPUT" #{ASCIIDOC_BLANK_HDR} == Clause1 === Clause2 ==== Clause3 ===== Clause4 ====== Clause 5 [level=6] ====== Clause 6 [level=7] ====== Clause 7A [level=7] ====== Clause 7B [level=6] ====== Clause 6B ====== Clause 5B INPUT #{BLANK_HDR} Clause1 Clause2 Clause3 Clause4 Clause 5 Clause 6 Clause 7A Clause 7B Clause 6B Clause 5B OUTPUT end it "separates IEV citations by top-level clause" do FileUtils.rm_rf File.expand_path("~/.relaton-bib.pstore1") FileUtils.mv File.expand_path("~/.relaton/cache"), File.expand_path("~/.relaton-bib.pstore1"), force: true FileUtils.rm_rf File.expand_path("~/.iev.pstore1") FileUtils.mv File.expand_path("~/.iev.pstore"), File.expand_path("~/.iev.pstore1"), force: true FileUtils.rm_rf "relaton/cache" FileUtils.rm_rf "test.iev.pstore" # mock_iecbib_get_iec60050_102_01 # mock_iecbib_get_iec60050_103_01 # mock_iev VCR.use_cassette "separates_iev_citations_by_top_level_clause" do expect(strip_guid(Asciidoctor.convert(<<~"INPUT", backend: :standoc, header_footer: true))).to be_equivalent_to <<~"OUTPUT" #{CACHED_ISOBIB_BLANK_HDR} [bibliography] == Normative References * [[[iev,IEV]]], _iev_ == Terms and definitions === Automation1 [.source] <> === Automation2 [.source] <> === Automation3 [.source] <> INPUT #{BLANK_HDR} Terms and definitions Automation1 103-01-02 Automation2 102-01-02 Automation3 103-01-02 Normative References #{Date.today} International Electrotechnical Vocabulary — Part 102: Mathematics — General concepts and linear algebra https://webstore.iec.ch/publication/160 /preview/info_iec60050-102%7Bed1.0%7Db.pdf IEC 60050-102:2007 2007 International Electrotechnical Commission IEC www.iec.ch 1.0 en This part of IEC 60050 gives the general mathematical terminology used in the fields of electricity, electronics and telecommunications, together with basic concepts in linear algebra. It maintains a clear distinction between mathematical concepts and physical concepts, even if some terms are used in both cases. Another part will deal with functions. It has the status of a horizontal standard in accordance with IEC Guide 108. 60 60 2007 International Electrotechnical Commission IEC www.iec.ch TC 1 - Terminology 01.040.07 Natural and applied sciences (Vocabularies) 07.020 Mathematics #{Date.today} International Electrotechnical Vocabulary — Part 103: Mathematics — Functions https://webstore.iec.ch/publication/161 /preview/info_iec60050-103%7Bed1.0%7Db.pdf IEC 60050-103:2009 2009 International Electrotechnical Commission IEC www.iec.ch 1.0 en IEC 60050-103:2009 gives the terminology relative to functions of one or more variables. Together with IEC 60050-102, it covers the mathematical terminology used in the fields of electricity, electronics and telecommunications. It maintains a clear distinction between mathematical concepts and physical concepts, even if some terms are used in both cases. Mathematical symbols are generally in accordance with IEC 60027-1 and ISO 80000-2. This standard cancels and replaces Sections 101-13, 101-14 and 101-15 of International Standard IEC 60050-101:1998. It has the status of a horizontal standard in accordance with IEC Guide 108. 60 60 2009 International Electrotechnical Commission IEC www.iec.ch TC 1 - Terminology 01.040.07 Natural and applied sciences (Vocabularies) 07.020 Mathematics OUTPUT end FileUtils.rm_rf File.expand_path("~/.iev.pstore") FileUtils.mv File.expand_path("~/.iev.pstore1"), File.expand_path("~/.iev.pstore"), force: true FileUtils.rm_rf File.expand_path("~/.relaton/cache") FileUtils.mv File.expand_path("~/.relaton-bib.pstore1"), File.expand_path("~/.relaton/cache"), force: true end it "counts footnotes with link-only content as separate footnotes" do expect(strip_guid(Asciidoctor.convert(<<~"INPUT", backend: :standoc, header_footer: true))).to be_equivalent_to <<~"OUTPUT" #{ASCIIDOC_BLANK_HDR} footnote:[http://www.example.com] footnote:[http://www.example.com] footnote:[http://www.example1.com] INPUT #{BLANK_HDR}

OUTPUT end it "retains AsciiMath on request" do expect(strip_guid(Asciidoctor.convert(<<~"INPUT", backend: :standoc, header_footer: true))).to be_equivalent_to <<~"OUTPUT" = Document title Author :docfile: test.adoc :nodoc: :novalid: :no-isobib: :mn-keep-asciimath: stem:[1/r] INPUT #{BLANK_HDR}

1/r

OUTPUT end it "converts AsciiMath to MathML by default" do expect(strip_guid(Asciidoctor.convert(<<~"INPUT", backend: :standoc, header_footer: true))).to be_equivalent_to <<~"OUTPUT" = Document title Author :docfile: test.adoc :nodoc: :novalid: :no-isobib: stem:[1/r] INPUT #{BLANK_HDR}

1r

OUTPUT end it "cleans up text MathML" do expect(strip_guid(Asciidoctor.convert(<<~"INPUT", backend: :standoc, header_footer: true))).to be_equivalent_to <<~"OUTPUT" = Document title Author :docfile: test.adoc :nodoc: :novalid: :no-isobib: ++++ <math xmlns="http://www.w3.org/1998/Math/MathML"><mfrac><mn>1</mn><mi>r</mi></mfrac></math> ++++ INPUT #{BLANK_HDR} /www.w3.org/1998/Math/MathML”>1r OUTPUT end private def mock_iecbib_get_iec60050_103_01 expect(Iecbib::IecBibliography).to receive(:get).with("IEC 60050-103", nil, {keep_year: true}) do IsoBibItem::XMLParser.from_xml(<<~"OUTPUT") International Electrotechnical Vocabulary IEC 60050-103:2009 2009 International Electrotechnical Commission IEC www.iec.ch en fr 60 2018 International Electrotechnical Commission IEC www.iec.ch OUTPUT end end def mock_iecbib_get_iec60050_102_01 expect(Iecbib::IecBibliography).to receive(:get).with("IEC 60050-102", nil, {keep_year: true}) do IsoBibItem::XMLParser.from_xml(<<~"OUTPUT") International Electrotechnical Vocabulary IEC 60050-102:2007 2007 International Electrotechnical Commission IEC www.iec.ch en fr 60 2018 International Electrotechnical Commission IEC www.iec.ch OUTPUT end end def mock_iev expect(Iecbib::IecBibliography).to receive(:get).with("IEV", nil, {}) do IsoBibItem::XMLParser.from_xml(<<~"OUTPUT") International Electrotechnical Vocabulary IEC 60050:2011 2007 International Electrotechnical Commission IEC www.iec.ch en fr 60 2018 International Electrotechnical Commission IEC www.iec.ch OUTPUT end.at_least :once end end