require "spec_helper" RSpec.describe IsoDoc do it "processes English" do input = <<~"INPUT" en Foreword

See

Introduction Introduction Subsection
Scope

Text

Terms, definitions, symbols and abbreviated terms Normal Terms Term2
Symbol
Definition
Symbol
Definition
Clause 4 Introduction Clause 4.2
Annex Annex A.1 Annex A.1a Normative References Bibliography Bibliography Subsection
INPUT presxml = <<~"PRESXML" en Foreword

See Clause 5

Introduction Introduction Subsection
1.<tab/>Scope

Text

3.<tab/>Terms, definitions, symbols and abbreviated terms 3.1.<tab/>Normal Terms 3.1.1. Term2 3.2.
Symbol
Definition
4.
Symbol
Definition
5.<tab/>Clause 4 5.1.<tab/>Introduction 5.2.<tab/>Clause 4.2
<strong>Annex A</strong><br/>(normative)<br/><br/><strong>Annex</strong> A.1.<tab/>Annex A.1 A.1.1.<tab/>Annex A.1a 2.<tab/>Normative References Bibliography Bibliography Subsection
PRESXML output = <<~"OUTPUT" #{HTML_HDR}

Foreword

See Clause 5


Introduction

Introduction Subsection

1.  Scope

Text

2.  Normative References

3.  Terms, definitions, symbols and abbreviated terms

3.1.  Normal Terms

3.1.1.

Term2

3.2.

Symbol

Definition

4.

Symbol

Definition

5.  Clause 4

5.1.  Introduction

5.2.  Clause 4.2


Annex A
(normative)

Annex

A.1.  Annex A.1

A.1.1.  Annex A.1a


Bibliography

Bibliography Subsection

OUTPUT expect(xmlpp(IsoDoc::PresentationXMLConvert .new({}).convert("test", input, true) .sub(%r{.*}m, ""))) .to be_equivalent_to xmlpp(presxml) expect(xmlpp(IsoDoc::HtmlConvert.new({}) .convert("test", presxml, true))).to be_equivalent_to xmlpp(output) end it "defaults to English" do input = <<~INPUT tlh Foreword

See

Introduction Introduction Subsection
Scope

Text

Terms, definitions, symbols and abbreviated terms Normal Terms Term2
Symbol
Definition
Symbol
Definition
Clause 4 Introduction Clause 4.2
Annex Annex A.1 Annex A.1a Normative References Bibliography Bibliography Subsection
INPUT output = <<~OUTPUT tlh Foreword

See Clause 5

Introduction Introduction Subsection
1.<tab/>Scope

Text

3.<tab/>Terms, definitions, symbols and abbreviated terms 3.1.<tab/>Normal Terms 3.1.1. Term2 3.2.
Symbol
Definition
4.
Symbol
Definition
5.<tab/>Clause 4 5.1.<tab/>Introduction 5.2.<tab/>Clause 4.2
<strong>Annex A</strong><br/>(normative)<br/><br/><strong>Annex</strong> A.1.<tab/>Annex A.1 A.1.1.<tab/>Annex A.1a 2.<tab/>Normative References Bibliography Bibliography Subsection
OUTPUT expect(xmlpp(IsoDoc::PresentationXMLConvert.new({}) .convert("test", input, true) .sub(%r{.*}m, ""))) .to be_equivalent_to xmlpp(output) end it "processes French" do input = <<~"INPUT" fr Foreword

See

Introduction Introduction Subsection
Scope

Text

Terms, definitions, symbols and abbreviated terms Normal Terms Term2
Symbol
Definition
Symbol
Definition
Clause 4 Introduction Clause 4.2
Annex Annex A.1 Annex A.1a Normative References Bibliographie Bibliography Subsection
INPUT presxml = <<~"PRESXML" fr Foreword

See Article 5

Introduction Introduction Subsection
1.<tab/>Scope

Text

3.<tab/>Terms, definitions, symbols and abbreviated terms 3.1.<tab/>Normal Terms 3.1.1. Term2 3.2.
Symbol
Definition
4.
Symbol
Definition
5.<tab/>Clause 4 5.1.<tab/>Introduction 5.2.<tab/>Clause 4.2
<strong>Annexe A</strong><br/>(normative)<br/><br/><strong>Annex</strong> A.1.<tab/>Annex A.1 A.1.1.<tab/>Annex A.1a 2.<tab/>Normative References Bibliographie Bibliography Subsection
PRESXML output = <<~"OUTPUT" #{HTML_HDR.gsub(/ lang="en">/, ' lang="fr">')}

Foreword

See Article 5


Introduction

Introduction Subsection

1.  Scope

Text

2.  Normative References

3.  Terms, definitions, symbols and abbreviated terms

3.1.  Normal Terms

3.1.1.

Term2

3.2.

Symbol

Definition

4.

Symbol

Definition

5.  Clause 4

5.1.  Introduction

5.2.  Clause 4.2


Annexe A
(normative)

Annex

A.1.  Annex A.1

A.1.1.  Annex A.1a


Bibliographie

Bibliography Subsection

OUTPUT expect(xmlpp(IsoDoc::PresentationXMLConvert.new({}) .convert("test", input, true) .sub(%r{.*}m, ""))) .to be_equivalent_to xmlpp(presxml) expect(xmlpp(IsoDoc::HtmlConvert.new({}) .convert("test", presxml, true))).to be_equivalent_to xmlpp(output) end it "processes Simplified Chinese" do input = <<~"INPUT" zh Foreword

See

Introduction Introduction Subsection
Scope

11

Terms, definitions, symbols and abbreviated terms Normal Terms Term2
Symbol
Definition
Symbol
Definition
Clause 4 Introduction Clause 4.2
Annex Annex A.1 Annex A.1a Normative References Cereals and cereal products ISO 712 ISO Bibliography Bibliography Subsection
INPUT presxml = <<~"PRESXML" zh Foreword

See 条5

Introduction Introduction Subsection
1.<tab/>Scope

11ISO 712、第1–1表

3.<tab/>Terms, definitions, symbols and abbreviated terms 3.1.<tab/>Normal Terms 3.1.1. Term2 3.2.
Symbol
Definition
4.
Symbol
Definition
5.<tab/>Clause 4 5.1.<tab/>Introduction 5.2.<tab/>Clause 4.2
<strong>附件A</strong><br/>(规范性附录)<br/><br/><strong>Annex</strong> A.1.<tab/>Annex A.1 A.1.1.<tab/>Annex A.1a 2.<tab/>Normative References Cereals and cereal products ISO 712 ISO Bibliography Bibliography Subsection
PRESXML output = <<~"OUTPUT" #{HTML_HDR.gsub(/ lang="en">/, ' lang="zh">')}

Foreword

See 条5


Introduction

Introduction Subsection

1. Scope

ISO 712、第1–1表

2. Normative References

ISO 712, Cereals and cereal products

3. Terms, definitions, symbols and abbreviated terms

3.1. Normal Terms

3.1.1.

Term2

3.2.

Symbol

Definition

4.

Symbol

Definition

5. Clause 4

5.1. Introduction

5.2. Clause 4.2


附件A
(规范性附录)

Annex

A.1. Annex A.1

A.1.1. Annex A.1a


Bibliography

Bibliography Subsection

OUTPUT expect(xmlpp(IsoDoc::PresentationXMLConvert.new({}) .convert("test", input, true) .sub(%r{.*}m, ""))) .to be_equivalent_to xmlpp(presxml) expect(xmlpp(IsoDoc::HtmlConvert.new({}) .convert("test", presxml, true))).to be_equivalent_to xmlpp(output) end it "processes i18n file" do mock_i18n input = <<~"INPUT" eo published withdrawn brochure Foreword

See

See

Introduction Introduction Subsection Scope

11

Terms, definitions, symbols and abbreviated terms Normal Terms Term2
Symbol
Definition
Symbol
Definition
Clause 4 Introduction Clause 4.2
Annex Annex A.1 Annex A.1a Normative References Cereals and cereal products ISO 712 ISO Bibliography Bibliography Subsection INPUT presxml = <<~OUTPUT eo publishedpublikigita withdrawnfortirita brochurebroŝuro AntaŭparoloEnkondukoklaŭzotabeloSOURCEmodifiedAmpleksoSimboloj kai mallongigitaj terminojaldonoNormaj citaĵojBibliografioinformaĉiuj partojnormativefigur-etikedo duvortaEkzempl-etikedo DuvortaNOTOTabelobroŝurokonferencaktojpublikigitafortiritaelem1elem2elem4elem6eoLatn Foreword

See klaŭzo 5

See tabelo 1

Tabelo 1
Introduction Introduction Subsection
1.<tab/>Scope

11ISO 712, Tabelo 1–1

3.<tab/>Terms, definitions, symbols and abbreviated terms 3.1.<tab/>Normal Terms 3.1.1. Term2 3.2.
Symbol
Definition
4.
Symbol
Definition
5.<tab/>Clause 4 5.1.<tab/>Introduction NOTO 5.2.<tab/>Clause 4.2
<strong><strong>Aldono</strong> A</strong><br/>(normative)<br/><br/><strong>Annex</strong> A.1.<tab/>Annex A.1 A.1.1.<tab/>Annex A.1a 2.<tab/>Normative References Cereals and cereal products ISO 712 ISO Bibliography Bibliography Subsection
OUTPUT output = <<~OUTPUT

 


 



Foreword

See klaŭzo 5

See tabelo 1

Tabelo 1


Introduction

Introduction Subsection

2.  Normative References

ISO 712, Cereals and cereal products

3.  Terms, definitions, symbols and abbreviated terms

3.1.  Normal Terms

3.1.1.

Term2

3.2.

Symbol

Definition

4.

Symbol

Definition

5.  Clause 4

5.1.  Introduction

NOTO  

5.2.  Clause 4.2


Aldono A
(normative)

Annex

A.1.  Annex A.1

A.1.1.  Annex A.1a


Bibliography

Bibliography Subsection

OUTPUT expect(xmlpp(IsoDoc::PresentationXMLConvert .new({ i18nyaml: "spec/assets/i18n.yaml" }) .convert("test", input, true))) .to be_equivalent_to xmlpp(presxml) expect(xmlpp(IsoDoc::HtmlConvert .new({ i18nyaml: "spec/assets/i18n.yaml" }) .convert("test", presxml, true))) .to be_equivalent_to xmlpp(output) end it "processes LTR within RTL" do c = IsoDoc::Convert.new({}) c.convert_init(<<~"INPUT", "test", false) fa INPUT expect(c.i18n.l10n("hello!", "en", "Latn")).to eq "‎hello!‎" end it "processes Hebrew RTL within LTR" do c = IsoDoc::Convert.new({}) c.convert_init(<<~"INPUT", "test", false) en INPUT expect(c.i18n.l10n("hello!", "he", "Hebr")).to eq "‏hello!‏" end it "processes Arabic RTL within LTR" do c = IsoDoc::Convert.new({}) c.convert_init(<<~"INPUT", "test", false) en INPUT expect(c.i18n.l10n("hello!", "fa", "Arab")).to eq "؜hello!؜" end private def mock_i18n allow_any_instance_of(::IsoDoc::I18n) .to receive(:load_yaml) .with("eo", "Latn", "spec/assets/i18n.yaml") .and_return(IsoDoc::I18n.new("eo", "Latn") .normalise_hash(YAML.load_file("spec/assets/i18n.yaml"))) end end