require "spec_helper" require "fileutils" RSpec.describe IsoDoc do it "maps styles for DIS" do FileUtils.rm_f "test.doc" IsoDoc::Iso::WordConvert .new({}) .convert("test", <<~"INPUT", false) 30 First Second INPUT expect(File.exist?("test.doc")).to be true html = File.read("test.doc", encoding: "UTF-8") expect(html).to include 'class="AltTerms"' expect(html).not_to include 'class="AdmittedTerm"' FileUtils.rm_f "test.doc" IsoDoc::Iso::WordConvert .new({}) .convert("test", <<~"INPUT", false) 50 First Second INPUT expect(File.exist?("test.doc")).to be true html = File.read("test.doc", encoding: "UTF-8") expect(html).not_to include 'class="AltTerms"' expect(html).to include 'class="AdmittedTerm"' FileUtils.rm_f "test.doc" IsoDoc::Iso::WordConvert .new({ isowordtemplate: "simple" }) .convert("test", <<~"INPUT", false) 50 First Second INPUT expect(File.exist?("test.doc")).to be true html = File.read("test.doc", encoding: "UTF-8") expect(html).to include 'class="AltTerms"' expect(html).not_to include 'class="AdmittedTerm"' FileUtils.rm_f "test.doc" IsoDoc::Iso::WordConvert .new({ isowordtemplate: "dis" }) .convert("test", <<~"INPUT", false) 30 First Second INPUT expect(File.exist?("test.doc")).to be true html = File.read("test.doc", encoding: "UTF-8") expect(html).not_to include 'class="AltTerms"' expect(html).to include 'class="AdmittedTerm"' end it "deals with span" do input = <<~INPUT 30

H I

INPUT word = <<~OUTPUT

H I

OUTPUT output = IsoDoc::Iso::WordConvert.new({}).convert("test", input, true) expect(xmlpp(Nokogiri::XML(output) .at("//div[@class = 'WordSection3']").to_xml)) .to be_equivalent_to xmlpp(word) input = <<~INPUT 50

H I

INPUT word = <<~OUTPUT

H I

OUTPUT output = IsoDoc::Iso::WordConvert.new({}).convert("test", input, true) expect(xmlpp(Nokogiri::XML(output) .at("//div[@class = 'WordSection3']").to_xml)) .to be_equivalent_to xmlpp(word) end it "deals with foreword and intro" do input = <<~INPUT 30 Foreword

Para

Foreword

Para

INPUT word = <<~OUTPUT

Contents


Foreword

Para


Foreword

Para

 

OUTPUT FileUtils.rm_f "test.doc" IsoDoc::Iso::WordConvert.new({}).convert("test", input, false) expect(File.exist?("test.doc")).to be true output = File.read("test.doc", encoding: "UTF-8") .sub(/^.*.*$/m, "") doc = Nokogiri::XML(output) .xpath("//xmlns:p[@class = 'MsoToc1']").each(&:remove) .at("//xmlns:div[@class = 'WordSection2']") expect(xmlpp(doc.to_xml)) .to be_equivalent_to xmlpp(word) input = <<~INPUT 50 Foreword

Para

Foreword

Para

INPUT word = <<~OUTPUT

Contents


Foreword

Para


Foreword

Para

 

OUTPUT FileUtils.rm_f "test.doc" IsoDoc::Iso::WordConvert.new({}).convert("test", input, false) expect(File.exist?("test.doc")).to be true output = File.read("test.doc", encoding: "UTF-8") .sub(/^.*.*$/m, "") doc = Nokogiri::XML(output) .xpath("//xmlns:p[@class = 'MsoToc1']").each(&:remove) .at("//xmlns:div[@class = 'WordSection2']") expect(xmlpp(doc.to_xml)) .to be_equivalent_to xmlpp(word) end it "formats references" do input = <<~INPUT 50 Normative References

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.

ALUFFI, Paolo, ed. (2022). Facets of Algebraic Geometry: A Collection in Honor of William Fulton's 80th Birthday, 1st edition. Cambridge, UK: CUP. ISO/IEC 712-3:2022
INPUT word = <<~OUTPUT

Normative References

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.

ISO/IEC 712-3:2022, ALUFFI, Paolo, ed. (2022). Facets of Algebraic Geometry: A Collection in Honor of William Fulton's 80th Birthday , 1st edition. Cambridge, UK: CUP.

OUTPUT FileUtils.rm_f "test.doc" IsoDoc::Iso::WordConvert.new({}).convert("test", input, false) expect(File.exist?("test.doc")).to be true output = File.read("test.doc", encoding: "UTF-8") .sub(/^.*.*$/m, "") doc = Nokogiri::XML(output) .at("//xmlns:div[@class = 'WordSection3']") expect(xmlpp(doc.to_xml)) .to be_equivalent_to xmlpp(word) end it "formats tt" do input = <<~INPUT 50

A B C DEF GHI

A B CDE

A B CDE

INPUT word = <<~OUTPUT

Contents


Foreword

A B C D E F G H I

A B C D E

A B C D E

 

OUTPUT FileUtils.rm_f "test.doc" IsoDoc::Iso::WordConvert.new({}).convert("test", input, false) expect(File.exist?("test.doc")).to be true output = File.read("test.doc", encoding: "UTF-8") .sub(/^.*.*$/m, "") doc = Nokogiri::XML(output) .xpath("//xmlns:p[@class = 'MsoToc1']").each(&:remove) .at("//xmlns:div[@class = 'WordSection2']") expect(xmlpp(doc.to_xml)) .to be_equivalent_to xmlpp(word) end it "deals with lists" do input = <<~INPUT 50

  1. A

  2. B

    1. C
    2. D
      1. E
      2. F
        1. G
        2. H
          1. I
          2. J
            1. K
            2. L
            3. M
          3. N
        3. O
      3. P
    3. Q
  3. R
  • A

  • B

  • B1

    • C
    • D
      • E
      • F
        • G
        • H
          • I
          • J
            • K
            • L
            • M
          • N
        • O
      • P
    • Q
  • R

INPUT word = <<~OUTPUT

1

a)   A

b)   B

1)   C

2)   D

i)   E

ii)   F

A)   G

B)   H

I)   I

II)   J

a)   K

b)   L

c)   M

III)   N

C)   O

iii)   P

3)   Q

c)   R

  A

  B

  B1

  C

  D

  E

  F

  G

  H

  I

  J

  K

  L

  M

  N

  O

  P

  Q

  R

OUTPUT FileUtils.rm_f "test.doc" presxml = IsoDoc::Iso::PresentationXMLConvert.new({}) .convert("test", input, true) IsoDoc::Iso::WordConvert.new({}).convert("test", presxml, false) expect(File.exist?("test.doc")).to be true output = File.read("test.doc", encoding: "UTF-8") .sub(/^.*.*$/m, "") expect(xmlpp(Nokogiri::XML(output) .at("//xmlns:div[@class = 'WordSection3']").to_xml)) .to be_equivalent_to xmlpp(word) end it "deals with lists and paragraphs" do input = <<~INPUT 50

ISO and IEC maintain terminological databases for use in standardization at the following addresses:

  • ISO Online browsing platform: available at

  • IEC Electropedia: available at

INPUT word = <<~OUTPUT

1

ISO and IEC maintain terminological databases for use in standardization at the following addresses:

  ISO Online browsing platform: available at https://www.iso.org/obp

  IEC Electropedia: available at https://www.electropedia.org

OUTPUT FileUtils.rm_f "test.doc" presxml = IsoDoc::Iso::PresentationXMLConvert.new({}) .convert("test", input, true) IsoDoc::Iso::WordConvert.new({}).convert("test", presxml, false) expect(File.exist?("test.doc")).to be true output = File.read("test.doc", encoding: "UTF-8") .sub(/^.*.*$/m, "") expect(xmlpp(Nokogiri::XML(output) .at("//xmlns:div[@class = 'WordSection3']").to_xml)) .to be_equivalent_to xmlpp(word) end it "deals with ordered list start" do input = <<~INPUT 50

  1. A

  2. B

    1. C
    2. D
      1. E
      2. F
        1. G
        2. H
          1. I
          2. J
            1. K
            2. L
            3. M
          3. N
        3. O
      3. P
    3. Q
  3. R
INPUT word = <<~OUTPUT

1

c)   A

d)   B

3)   C

4)   D

iii)   E

iv)   F

C)   G

D)   H

III)   I

IV)   J

c)   K

d)   L

e)   M

V)   N

E)   O

v)   P

5)   Q

e)   R

OUTPUT FileUtils.rm_f "test.doc" presxml = IsoDoc::Iso::PresentationXMLConvert.new({}) .convert("test", input, true) IsoDoc::Iso::WordConvert.new({}).convert("test", presxml, false) expect(File.exist?("test.doc")).to be true output = File.read("test.doc", encoding: "UTF-8") .sub(/^.*.*$/m, "") expect(xmlpp(Nokogiri::XML(output) .at("//xmlns:div[@class = 'WordSection3']").to_xml)) .to be_equivalent_to xmlpp(word) end it "deals with tables" do input = <<~INPUT 50 Table1
A

B

C

D

E

F

INPUT word = <<~WORD

Table1

A

B

C

D

E

F

WORD FileUtils.rm_f "test.doc" IsoDoc::Iso::WordConvert.new({}).convert("test", input, false) expect(File.exist?("test.doc")).to be true output = File.read("test.doc", encoding: "UTF-8") .sub(/^.*.*$/m, "") expect(xmlpp(Nokogiri::XML(output) .at("//xmlns:div[@class = 'WordSection3']").to_xml)) .to be_equivalent_to xmlpp(word) end it "deals with figures" do input = <<~INPUT 50
Table1 FIGURENOTE

Note

Example

INPUT word = <<~WORD

WORD FileUtils.rm_f "test.doc" IsoDoc::Iso::WordConvert.new({}).convert("test", input, false) expect(File.exist?("test.doc")).to be true output = File.read("test.doc", encoding: "UTF-8") .sub(/^.*.*$/m, "") expect(strip_guid(xmlpp(Nokogiri::XML(output) .at("//xmlns:div[@class = 'WordSection3']").to_xml))) .to be_equivalent_to xmlpp(word) end it "deals with examples" do input = <<~INPUT 50 EXAMPLE

First example

Second example

Code

Continuation

INPUT word = <<~WORD

EXAMPLE   First example

  Second example

Code

Continuation

WORD FileUtils.rm_f "test.doc" IsoDoc::Iso::WordConvert.new({}).convert("test", input, false) expect(File.exist?("test.doc")).to be true output = File.read("test.doc", encoding: "UTF-8") .sub(/^.*.*$/m, "") expect(strip_guid(xmlpp(Nokogiri::XML(output) .at("//xmlns:div[@class = 'WordSection3']").to_xml))) .to be_equivalent_to xmlpp(word) end it "deals with notes" do input = <<~INPUT 50 NOTE

First example

Second example

Code

Continuation

INPUT word = <<~WORD

NOTE   First example

  Second example

Code

Continuation

WORD FileUtils.rm_f "test.doc" IsoDoc::Iso::WordConvert.new({}).convert("test", input, false) expect(File.exist?("test.doc")).to be true output = File.read("test.doc", encoding: "UTF-8") .sub(/^.*.*$/m, "") expect(strip_guid(xmlpp(Nokogiri::XML(output) .at("//xmlns:div[@class = 'WordSection3']").to_xml))) .to be_equivalent_to xmlpp(word) end it "deals with unordered lists embedded within notes and examples" do input = <<~INPUT 50
  • A

  • B

    • C
    • D
      • E
      • F
        • G
        • H
          • I
          • J
            • K
            • L
            • M
          • N
        • O
      • P
    • Q
  • R
INPUT word = <<~WORD

1

NOTE  

  A

  B

  C

  D

  E

  F

  G

  H

  I

  J

  K

  L

  M

  N

  O

  P

  Q

  R

WORD FileUtils.rm_f "test.doc" presxml = IsoDoc::Iso::PresentationXMLConvert.new({}) .convert("test", input, true) IsoDoc::Iso::WordConvert.new({}).convert("test", presxml, false) expect(File.exist?("test.doc")).to be true output = File.read("test.doc", encoding: "UTF-8") .sub(/^.*.*$/m, "") expect(strip_guid(xmlpp(Nokogiri::XML(output) .at("//xmlns:div[@class = 'WordSection3']").to_xml))) .to be_equivalent_to xmlpp(word) end it "deals with ordered lists embedded within notes and examples" do input = <<~INPUT 50
  1. A

  2. B

    1. C
    2. D
      1. E
      2. F
        1. G
        2. H
          1. I
          2. J
            1. K
            2. L
            3. M
          3. N
        3. O
      3. P
    3. Q
  3. R
INPUT word = <<~WORD

1

EXAMPLE  

a)   A

b)   B

1)   C

2)   D

i)   E

ii)   F

A)   G

B)   H

I)   I

II)   J

a)   K

b)   L

c)   M

III)   N

C)   O

iii)   P

3)   Q

c)   R

WORD FileUtils.rm_f "test.doc" presxml = IsoDoc::Iso::PresentationXMLConvert.new({}) .convert("test", input, true) IsoDoc::Iso::WordConvert.new({}).convert("test", presxml, false) expect(File.exist?("test.doc")).to be true output = File.read("test.doc", encoding: "UTF-8") .sub(/^.*.*$/m, "") expect(strip_guid(xmlpp(Nokogiri::XML(output) .at("//xmlns:div[@class = 'WordSection3']").to_xml))) .to be_equivalent_to xmlpp(word) end it "ignores intervening ul in numbering ol" do input = <<~INPUT 50
  • A
    1. List
      • B
        1. List 2
INPUT word = <<~WORD

1

  A

a)   List

  B

1)   List 2

WORD FileUtils.rm_f "test.doc" presxml = IsoDoc::Iso::PresentationXMLConvert.new({}) .convert("test", input, true) IsoDoc::Iso::WordConvert.new({}).convert("test", presxml, false) expect(File.exist?("test.doc")).to be true output = File.read("test.doc", encoding: "UTF-8") .sub(/^.*.*$/m, "") expect(strip_guid(xmlpp(Nokogiri::XML(output) .at("//xmlns:div[@class = 'WordSection3']").to_xml))) .to be_equivalent_to xmlpp(word) end it "deals with definition lists embedded within notes and examples" do input = <<~INPUT 50 EXAMPLE
A
B
INPUT word = <<~WORD

EXAMPLE  

A

B

WORD FileUtils.rm_f "test.doc" IsoDoc::Iso::WordConvert.new({}).convert("test", input, false) expect(File.exist?("test.doc")).to be true output = File.read("test.doc", encoding: "UTF-8") .sub(/^.*.*$/m, "") expect(strip_guid(xmlpp(Nokogiri::XML(output) .at("//xmlns:div[@class = 'WordSection3']").to_xml))) .to be_equivalent_to xmlpp(word) end it "deals with annexes" do input = <<~INPUT 50 Annex Subannex Subsubannex INPUT word = <<~WORD


Annex

Subannex

Subsubannex

WORD FileUtils.rm_f "test.doc" IsoDoc::Iso::WordConvert.new({}).convert("test", input, false) expect(File.exist?("test.doc")).to be true output = File.read("test.doc", encoding: "UTF-8") .sub(/^.*.*$/m, "") expect(strip_guid(xmlpp(Nokogiri::XML(output) .at("//xmlns:div[@class = 'WordSection3']").to_xml))) .to be_equivalent_to xmlpp(word) end it "deals with blockquotes" do input = <<~INPUT 50

Normal clause

Note clause

Example start

X

Example continued

X
INPUT word = <<~WORD

Normal clause

  Note clause

  Example start

X

Example continued

X

WORD FileUtils.rm_f "test.doc" IsoDoc::Iso::WordConvert.new({}).convert("test", input, false) expect(File.exist?("test.doc")).to be true output = File.read("test.doc", encoding: "UTF-8") .sub(/^.*.*$/m, "") expect(strip_guid(xmlpp(Nokogiri::XML(output) .at("//xmlns:div[@class = 'WordSection3']").to_xml))) .to be_equivalent_to xmlpp(word) end it "deals with title" do input = <<~INPUT Date and time Representations for information interchange Basic rules 50 international-standard 8601 First clause INPUT word = <<~WORD

Date and time — Representations for information interchange — Part 1: Basic rules

First clause

WORD title = <<~WORD

Reference number of project:

Committee identification: /

Date and time — Representations for information interchange — Part 1: Basic rules

WORD FileUtils.rm_f "test.doc" IsoDoc::Iso::WordConvert.new({}).convert("test", input, false) expect(File.exist?("test.doc")).to be true output = File.read("test.doc", encoding: "UTF-8") .sub(/^.*.*$/m, "") expect(strip_guid(xmlpp(Nokogiri::XML(output) .at("//xmlns:div[@class = 'WordSection3']").to_xml))) .to be_equivalent_to xmlpp(word) expect(strip_guid(xmlpp(Nokogiri::XML(output) .at("//xmlns:div[@class = 'WordSection1']").to_xml))) .to be_equivalent_to xmlpp(title) end it "deals with amendments" do input = <<~INPUT Date and time Representations for information interchange Basic rules Technical corrections 50 amendment 8601 Foreword First clause INPUT word = <<~WORD

Date and time — Representations for information interchange — Part 1: Basic rules AMENDMENT 1: Technical corrections

First clause

WORD FileUtils.rm_f "test.doc" IsoDoc::Iso::WordConvert.new({}).convert("test", input, false) expect(File.exist?("test.doc")).to be true output = File.read("test.doc", encoding: "UTF-8") .sub(/^.*.*$/m, "") expect(strip_guid(xmlpp(Nokogiri::XML(output) .at("//xmlns:div[@class = 'WordSection3']").to_xml))) .to be_equivalent_to xmlpp(word) end it "deals with copyright boilerplate" do presxml = <<~OUTPUT 50 COPYRIGHT PROTECTED DOCUMENT

© ISO 2019, Published in Switzerland

I am the Walrus.

ISO copyright office

ISO copyright office
Ch. de Blandonnet 8 ?~@? CP 401
CH-1214 Vernier, Geneva, Switzerland
Phone: +41 22 749 01 11
Email: copyright@iso.org
www.iso.org

Warning for Stuff

This document is not an ISO International Standard. It is distributed for review and comment. It is subject to change without notice and may not be referred to as an International Standard.

Recipients of this draft are invited to submit, with their comments, notification of any relevant patent rights of which they are aware and to provide supporting documentation.

OUTPUT FileUtils.rm_f "test.doc" IsoDoc::Iso::WordConvert.new(wordstylesheet: "spec/assets/word.css") .convert("test", presxml, false) word = File.read("test.doc", encoding: "UTF-8") expect(xmlpp(word .sub(%r{^.*"))) .to be_equivalent_to xmlpp(<<~"OUTPUT")
OUTPUT FileUtils.rm_f "test.doc" IsoDoc::Iso::WordConvert.new(wordstylesheet: "spec/assets/word.css") .convert("test", presxml.sub(%r{50}, "6000"), false) word = File.read("test.doc", encoding: "UTF-8") expect(xmlpp(word .sub(%r{^.*"))) .to be_equivalent_to xmlpp(<<~"OUTPUT") OUTPUT end it "deals with Simple Template styles" do input = <<~INPUT 20 Clause Title
  • List

Note

  • Note List

Example

  • Example List
Figure Title
XYZ Table
Annex Title Annex Table
Annex Clause Title
Bibliography ALUFFI, Paolo, ed. (2022). Facets of Algebraic Geometry: A Collection in Honor of William Fulton's 80th Birthday, 1st edition. Cambridge, UK: CUP. ISO/IEC 712-3:2022
INPUT word = <<~WORD

Clause Title

List

XYZ

Table



Bibliography

[1]   ISO/IEC 712-3:2022, ALUFFI, Paolo, ed. (2022). Facets of Algebraic Geometry: A Collection in Honor of William Fulton's 80th Birthday , 1st edition. Cambridge, UK: CUP.

WORD FileUtils.rm_f "test.doc" IsoDoc::Iso::WordConvert.new({}).convert("test", input, false) expect(File.exist?("test.doc")).to be true output = File.read("test.doc", encoding: "UTF-8") .sub(/^.*.*$/m, "") expect(strip_guid(xmlpp(Nokogiri::XML(output) .at("//xmlns:div[@class = 'WordSection3']").to_xml))) .to be_equivalent_to xmlpp(word) end end