metanorma-iso 1.0.7 → 1.0.8

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,332 +0,0 @@
1
- require "spec_helper"
2
- require "isobib"
3
- require "fileutils"
4
-
5
- RSpec.describe Asciidoctor::ISO do
6
-
7
- ISO_123_SHORT = <<~EOS
8
- <bibitem type="international-standard" id="ISO123">
9
- <title format="text/plain" language="en" script="Latn">Rubber latex -- Sampling</title>
10
- <docidentifier>ISO 123</docidentifier>
11
- <contributor> <role type="publisher"/> <organization> <name>International Organization for Standardization</name> <abbreviation>ISO</abbreviation> <uri>www.iso.org</uri> </organization> </contributor>
12
- <status>Published</status>
13
- </bibitem>
14
- EOS
15
-
16
- ISO_124_SHORT = <<~EOS
17
- <bibitem type="international-standard" id="ISO124">
18
- <title format="text/plain" language="en" script="Latn">Latex, rubber -- Determination of total solids content</title>
19
- <docidentifier>ISO 124</docidentifier>
20
- <contributor> <role type="publisher"/> <organization> <name>International Organization for Standardization</name> <abbreviation>ISO</abbreviation> <uri>www.iso.org</uri> </organization> </contributor>
21
- <status>Published</status>
22
- </bibitem>
23
- EOS
24
-
25
- ISO_124_SHORT_ALT = <<~EOS
26
- <bibitem type="international-standard" id="ISO124">
27
- <title format="text/plain" language="en" script="Latn">Latex, rubber -- Replacement</title>
28
- <docidentifier>ISO 124</docidentifier>
29
- <contributor> <role type="publisher"/> <organization> <name>International Organization for Standardization</name> <abbreviation>ISO</abbreviation> <uri>www.iso.org</uri> </organization> </contributor>
30
- <status>Published</status>
31
- </bibitem>
32
- EOS
33
-
34
- ISOBIB_123_DATED = <<~EOS
35
- <bibitem type="international-standard" id="ISO123"> <title format="text/plain" language="en" script="Latn">Rubber latex -- Sampling</title> <title format="text/plain" language="fr" script="Latn">Latex de caoutchouc -- ?chantillonnage</title> <uri type="src">https://www.iso.org/standard/23281.html</uri> <uri type="obp">https://www.iso.org/obp/ui/#!iso:std:23281:en</uri> <uri type="rss">https://www.iso.org/contents/data/standard/02/32/23281.detail.rss</uri> <docidentifier>ISO 123</docidentifier> <date type="published"> <on>2001</on> </date> <contributor> <role type="publisher"/> <organization> <name>International Organization for Standardization</name> <abbreviation>ISO</abbreviation> <uri>www.iso.org</uri> </organization> </contributor> <edition>3</edition> <language>en</language> <language>fr</language> <script>Latn</script> <status>Published</status> <copyright> <from>2001</from> <owner> <organization> <name>ISO</name> </organization> </owner> </copyright> <relation type="obsoletes"> <bibitem> <formattedref>ISO 123:1985</formattedref> </bibitem> </relation> <relation type="updates"> <bibitem> <formattedref>ISO 123:2001</formattedref> </bibitem> </relation></bibitem>
36
- EOS
37
-
38
- ISOBIB_123_UNDATED = <<~EOS
39
- <bibitem type="international-standard" id="ISO123"> <title format="text/plain" language="en" script="Latn">Rubber latex -- Sampling</title> <title format="text/plain" language="fr" script="Latn">Latex de caoutchouc -- ?chantillonnage</title> <uri type="src">https://www.iso.org/standard/23281.html</uri> <uri type="obp">https://www.iso.org/obp/ui/#!iso:std:23281:en</uri> <uri type="rss">https://www.iso.org/contents/data/standard/02/32/23281.detail.rss</uri> <docidentifier>ISO 123</docidentifier> <date type="published"> <on>2001</on> </date> <contributor> <role type="publisher"/> <organization> <name>International Organization for Standardization</name> <abbreviation>ISO</abbreviation> <uri>www.iso.org</uri> </organization> </contributor> <edition>3</edition> <language>en</language> <language>fr</language> <script>Latn</script> <status>Published</status> <copyright> <from>2001</from> <owner> <organization> <name>ISO</name> </organization> </owner> </copyright> <relation type="obsoletes"> <bibitem> <formattedref>ISO 123:1985</formattedref> </bibitem> </relation> <relation type="updates"> <bibitem> <formattedref>ISO 123:2001</formattedref> </bibitem> </relation></bibitem>
40
- EOS
41
-
42
-
43
- ISOBIB_124_DATED = <<~EOS
44
- <bibitem type="international-standard" id="ISO124"> <title format="text/plain" language="en" script="Latn">Latex, rubber -- Determination of total solids content</title> <title format="text/plain" language="fr" script="Latn">Latex de caoutchouc -- Détermination des matières solides totales</title> <uri type="src">https://www.iso.org/standard/61884.html</uri> <uri type="obp">https://www.iso.org/obp/ui/#!iso:std:61884:en</uri> <uri type="rss">https://www.iso.org/contents/data/standard/06/18/61884.detail.rss</uri> <docidentifier>ISO 124</docidentifier> <date type="published"> <on>2014</on> </date> <contributor> <role type="publisher"/> <organization> <name>International Organization for Standardization</name> <abbreviation>ISO</abbreviation> <uri>www.iso.org</uri> </organization> </contributor> <edition>7</edition> <language>en</language> <language>fr</language> <script>Latn</script> <abstract format="plain" language="en" script="Latn">ISO 124:2014 specifies methods for the determination of the total solids content of natural rubber field and concentrated latices and synthetic rubber latex. These methods are not necessarily suitable for latex from natural sources other than the Hevea brasiliensis, for vulcanized latex, for compounded latex, or for artificial dispersions of rubber.</abstract> <abstract format="plain" language="fr" script="Latn">L'ISO 124:2014 spécifie des méthodes pour la détermination des matières solides totales dans le latex de plantation, le latex de concentré de caoutchouc naturel et le latex de caoutchouc synthétique. Ces méthodes ne conviennent pas nécessairement au latex d'origine naturelle autre que celui de l'Hevea brasiliensis, au latex vulcanisé, aux mélanges de latex, ou aux dispersions artificielles de caoutchouc.</abstract> <status>Published</status> <copyright> <from>2014</from> <owner> <organization> <name>ISO</name> </organization> </owner> </copyright> <relation type="obsoletes"> <bibitem> <formattedref>ISO 124:2011</formattedref> </bibitem> </relation></bibitem>
45
- EOS
46
-
47
- it "does not activate biblio caches if isobib disabled" do
48
- FileUtils.mv File.expand_path("~/.relaton-bib.pstore"), File.expand_path("~/.relaton-bib.pstore1"), force: true
49
- FileUtils.mv File.expand_path("~/.iev.pstore"), File.expand_path("~/.iev.pstore1"), force: true
50
- FileUtils.rm_f "test.relaton.pstore"
51
- FileUtils.rm_f "test.iev.pstore"
52
- Asciidoctor.convert(<<~"INPUT", backend: :iso, header_footer: true)
53
- #{ASCIIDOC_BLANK_HDR}
54
- [bibliography]
55
- == Normative References
56
-
57
- * [[[iso123,ISO 123:2001]]] _Standard_
58
- INPUT
59
- expect(File.exist?("#{Dir.home}/.relaton-bib.pstore")).to be false
60
- expect(File.exist?("#{Dir.home}/.iev.pstore")).to be false
61
- expect(File.exist?("test.relaton.pstore")).to be false
62
- expect(File.exist?("test.iev.pstore")).to be false
63
-
64
- FileUtils.rm_f File.expand_path("~/.relaton-bib.pstore")
65
- FileUtils.rm_f File.expand_path("~/.iev.pstore")
66
- FileUtils.mv File.expand_path("~/.relaton-bib.pstore1"), File.expand_path("~/.relaton-bib.pstore"), force: true
67
- FileUtils.mv File.expand_path("~/.iev.pstore1"), File.expand_path("~/.iev.pstore"), force: true
68
- end
69
-
70
- it "does not activate biblio caches if isobib caching disabled" do
71
- FileUtils.mv File.expand_path("~/.relaton-bib.pstore"), File.expand_path("~/.relaton-bib.pstore1"), force: true
72
- FileUtils.mv File.expand_path("~/.iev.pstore"), File.expand_path("~/.iev.pstore1"), force: true
73
- FileUtils.rm_f "test.relaton.pstore"
74
- FileUtils.rm_f "test.iev.pstore"
75
- mock_isobib_get_123
76
- Asciidoctor.convert(<<~"INPUT", backend: :iso, header_footer: true)
77
- #{ISOBIB_BLANK_HDR}
78
- [bibliography]
79
- == Normative References
80
-
81
- * [[[iso123,ISO 123:2001]]] _Standard_
82
- INPUT
83
- expect(File.exist?("#{Dir.home}/.relaton-bib.pstore")).to be false
84
- expect(File.exist?("#{Dir.home}/.iev.pstore")).to be false
85
- expect(File.exist?("test.relaton.pstore")).to be false
86
- expect(File.exist?("test.iev.pstore")).to be false
87
-
88
- FileUtils.rm_f File.expand_path("~/.relaton-bib.pstore")
89
- FileUtils.rm_f File.expand_path("~/.iev.pstore")
90
- FileUtils.mv File.expand_path("~/.relaton-bib.pstore1"), File.expand_path("~/.relaton-bib.pstore"), force: true
91
- FileUtils.mv File.expand_path("~/.iev.pstore1"), File.expand_path("~/.iev.pstore"), force: true
92
- end
93
-
94
- it "flushes biblio caches" do
95
- FileUtils.cp File.expand_path("~/.relaton-bib.pstore"), File.expand_path("~/.relaton-bib.pstore1")
96
- FileUtils.cp File.expand_path("~/.iev.pstore"), File.expand_path("~/.iev.pstore1")
97
-
98
- File.open("#{Dir.home}/.relaton-bib.pstore", "w") { |f| f.write "XXX" }
99
- FileUtils.rm_f File.expand_path("~/.iev.pstore")
100
-
101
- mock_isobib_get_123
102
- Asciidoctor.convert(<<~"INPUT", backend: :iso, header_footer: true)
103
- #{FLUSH_CACHE_ISOBIB_BLANK_HDR}
104
- [bibliography]
105
- == Normative References
106
-
107
- * [[[iso123,ISO 123:2001]]] _Standard_
108
- INPUT
109
- expect(File.exist?("#{Dir.home}/.relaton-bib.pstore")).to be true
110
- expect(File.exist?("#{Dir.home}/.iev.pstore")).to be true
111
-
112
- db = Relaton::Db.new "#{Dir.home}/.relaton-bib.pstore", nil
113
- entry = db.load_entry("ISO(ISO 123:2001)")
114
- expect(entry["fetched"].to_s).to eq(Date.today.to_s)
115
- expect(entry["bib"].to_xml).to be_equivalent_to(ISOBIB_123_DATED)
116
-
117
- FileUtils.rm_f File.expand_path("~/.relaton-bib.pstore")
118
- FileUtils.rm_f File.expand_path("~/.iev.pstore")
119
- FileUtils.mv File.expand_path("~/.relaton-bib.pstore1"), File.expand_path("~/.relaton-bib.pstore"), force: true
120
- FileUtils.mv File.expand_path("~/.iev.pstore1"), File.expand_path("~/.iev.pstore"), force: true
121
- end
122
-
123
- it "activates global cache" do
124
- FileUtils.mv File.expand_path("~/.relaton-bib.pstore"), File.expand_path("~/.relaton-bib.pstore1"), force: true
125
- FileUtils.rm_f "test.relaton.pstore"
126
- mock_isobib_get_123
127
- Asciidoctor.convert(<<~"INPUT", backend: :iso, header_footer: true)
128
- #{CACHED_ISOBIB_BLANK_HDR}
129
- [bibliography]
130
- == Normative References
131
-
132
- * [[[iso123,ISO 123:2001]]] _Standard_
133
- INPUT
134
- expect(File.exist?("#{Dir.home}/.relaton-bib.pstore")).to be true
135
- expect(File.exist?("test.relaton.pstore")).to be false
136
-
137
- db = Relaton::Db.new "#{Dir.home}/.relaton-bib.pstore", nil
138
- entry = db.load_entry("ISO(ISO 123:2001)")
139
- expect(entry).to_not be nil
140
-
141
- FileUtils.rm_f File.expand_path("~/.relaton-bib.pstore")
142
- FileUtils.mv File.expand_path("~/.relaton-bib.pstore1"), File.expand_path("~/.relaton-bib.pstore"), force: true
143
- end
144
-
145
- it "activates local cache" do
146
- FileUtils.mv File.expand_path("~/.relaton-bib.pstore"), File.expand_path("~/.relaton-bib.pstore1"), force: true
147
- FileUtils.rm_f "test.relaton.pstore"
148
- mock_isobib_get_123
149
- Asciidoctor.convert(<<~"INPUT", backend: :iso, header_footer: true)
150
- #{LOCAL_CACHED_ISOBIB_BLANK_HDR}
151
- [bibliography]
152
- == Normative References
153
-
154
- * [[[iso123,ISO 123:2001]]] _Standard_
155
- INPUT
156
- expect(File.exist?("#{Dir.home}/.relaton-bib.pstore")).to be true
157
- expect(File.exist?("test.relaton.pstore")).to be true
158
-
159
- db = Relaton::Db.new "#{Dir.home}/.relaton-bib.pstore", nil
160
- entry = db.load_entry("ISO(ISO 123:2001)")
161
- expect(entry).to_not be nil
162
-
163
- db = Relaton::Db.new "test.relaton.pstore", nil
164
- entry = db.load_entry("ISO(ISO 123:2001)")
165
- expect(entry).to_not be nil
166
-
167
- FileUtils.rm_f File.expand_path("~/.relaton-bib.pstore")
168
- FileUtils.mv File.expand_path("~/.relaton-bib.pstore1"), File.expand_path("~/.relaton-bib.pstore"), force: true
169
- end
170
-
171
- it "fetches uncached references" do
172
- FileUtils.mv File.expand_path("~/.relaton-bib.pstore"), File.expand_path("~/.relaton-bib.pstore1"), force: true
173
- db = Relaton::Db.new "#{Dir.home}/.relaton-bib.pstore", nil
174
- db.save_entry("ISO(ISO 123:2001)",
175
- {
176
- "fetched" => Date.today.to_s,
177
- "bib" => IsoBibItem.from_xml(ISO_123_SHORT)
178
- }
179
- )
180
-
181
- mock_isobib_get_124
182
-
183
- Asciidoctor.convert(<<~"INPUT", backend: :iso, header_footer: true)
184
- #{CACHED_ISOBIB_BLANK_HDR}
185
- [bibliography]
186
- == Normative References
187
-
188
- * [[[iso123,ISO 123:2001]]] _Standard_
189
- * [[[iso124,ISO 124:2014]]] _Standard_
190
- INPUT
191
-
192
- entry = db.load_entry("ISO(ISO 123:2001)")
193
- expect(entry["fetched"].to_s).to eq(Date.today.to_s)
194
- expect(entry["bib"].to_xml).to be_equivalent_to(ISO_123_SHORT)
195
- entry = db.load_entry("ISO(ISO 124:2014)")
196
- expect(entry["fetched"].to_s).to eq(Date.today.to_s)
197
- expect(entry["bib"].to_xml).to be_equivalent_to(ISOBIB_124_DATED)
198
-
199
- FileUtils.rm_f File.expand_path("~/.relaton-bib.pstore")
200
- FileUtils.mv File.expand_path("~/.relaton-bib.pstore1"), File.expand_path("~/.relaton-bib.pstore"), force: true
201
- end
202
-
203
- it "expires stale undated references" do
204
- FileUtils.mv File.expand_path("~/.relaton-bib.pstore"), File.expand_path("~/.relaton-bib.pstore1"), force: true
205
-
206
- db = Relaton::Db.new "#{Dir.home}/.relaton-bib.pstore", nil
207
- db.save_entry("ISO 123",
208
- {
209
- "fetched" => (Date.today - 90),
210
- "bib" => IsoBibItem.from_xml(ISO_123_SHORT)
211
- }
212
- )
213
-
214
- mock_isobib_get_123_undated
215
-
216
- Asciidoctor.convert(<<~"INPUT", backend: :iso, header_footer: true)
217
- #{CACHED_ISOBIB_BLANK_HDR}
218
- [bibliography]
219
- == Normative References
220
-
221
- * [[[iso123,ISO 123]]] _Standard_
222
- INPUT
223
-
224
- entry = db.load_entry("ISO(ISO 123)")
225
- expect(entry["fetched"].to_s).to eq(Date.today.to_s)
226
- expect(entry["bib"].to_xml).to be_equivalent_to(ISOBIB_123_UNDATED)
227
-
228
- FileUtils.rm_f File.expand_path("~/.relaton-bib.pstore")
229
- FileUtils.mv File.expand_path("~/.relaton-bib.pstore1"), File.expand_path("~/.relaton-bib.pstore"), force: true
230
- end
231
-
232
- it "does not expire stale dated references" do
233
- FileUtils.mv File.expand_path("~/.relaton-bib.pstore"), File.expand_path("~/.relaton-bib.pstore1"), force: true
234
-
235
- db = Relaton::Db.new "#{Dir.home}/.relaton-bib.pstore", nil
236
- db.save_entry("ISO(ISO 123:2001)",
237
- {
238
- "fetched" => (Date.today - 90),
239
- "bib" => IsoBibItem.from_xml(ISO_123_SHORT)
240
- }
241
- )
242
-
243
- Asciidoctor.convert(<<~"INPUT", backend: :iso, header_footer: true)
244
- #{CACHED_ISOBIB_BLANK_HDR}
245
- [bibliography]
246
- == Normative References
247
-
248
- * [[[iso123,ISO 123:2001]]] _Standard_
249
- INPUT
250
-
251
- entry = db.load_entry("ISO(ISO 123:2001)")
252
- expect(entry["fetched"].to_s).to eq((Date.today - 90).to_s)
253
- expect(entry["bib"].to_xml).to be_equivalent_to(ISO_123_SHORT)
254
-
255
- FileUtils.rm_f File.expand_path("~/.relaton-bib.pstore")
256
- FileUtils.mv File.expand_path("~/.relaton-bib.pstore1"), File.expand_path("~/.relaton-bib.pstore"), force: true
257
- end
258
-
259
- it "prioritises local over global cache values" do
260
- FileUtils.mv File.expand_path("~/.relaton-bib.pstore"), File.expand_path("~/.relaton-bib.pstore1"), force: true
261
- FileUtils.rm_f "test.relaton.pstore"
262
-
263
- db = Relaton::Db.new "#{Dir.home}/.relaton-bib.pstore", nil
264
- db.save_entry("ISO(ISO 123:2001)",
265
- {
266
- "fetched" => Date.today,
267
- "bib" => IsoBibItem.from_xml(ISO_123_SHORT)
268
- }
269
- )
270
- db.save_entry("ISO(ISO 124)",
271
- {
272
- "fetched" => Date.today,
273
- "bib" => IsoBibItem.from_xml(ISO_124_SHORT)
274
- }
275
- )
276
-
277
- localdb = Relaton::Db.new "test.relaton.pstore", nil
278
- localdb.save_entry("ISO(ISO 124)",
279
- {
280
- "fetched" => Date.today,
281
- "bib" => IsoBibItem.from_xml(ISO_124_SHORT_ALT)
282
- }
283
- )
284
-
285
- input = <<~EOS
286
- #{LOCAL_CACHED_ISOBIB_BLANK_HDR}
287
- [bibliography]
288
- == Normative References
289
-
290
- * [[[ISO123,ISO 123:2001]]] _Standard_
291
- * [[[ISO124,ISO 124]]] _Standard_
292
- EOS
293
-
294
- output = <<~EOS
295
- #{BLANK_HDR}
296
- <sections>
297
- </sections>
298
- <bibliography>
299
- <references id="_" obligation="informative">
300
- <title>Normative References</title>
301
- #{ISO_123_SHORT}
302
- #{ISO_124_SHORT_ALT}
303
- </references></bibliography>
304
- </iso-standard>
305
- EOS
306
-
307
- expect(strip_guid(Asciidoctor.convert(input, backend: :iso, header_footer: true))).to be_equivalent_to(output)
308
-
309
- expect(db.load_entry("ISO(ISO 123:2001)")["bib"].to_xml).to be_equivalent_to(ISO_123_SHORT)
310
- expect(db.load_entry("ISO(ISO 124)")["bib"].to_xml).to be_equivalent_to(ISO_124_SHORT)
311
- expect(localdb.load_entry("ISO(ISO 123:2001)")["bib"].to_xml).to be_equivalent_to(ISO_123_SHORT)
312
- expect(localdb.load_entry("ISO(ISO 124)")["bib"].to_xml).to be_equivalent_to(ISO_124_SHORT_ALT)
313
-
314
- FileUtils.rm_f File.expand_path("~/.relaton-bib.pstore")
315
- FileUtils.mv File.expand_path("~/.relaton-bib.pstore1"), File.expand_path("~/.relaton-bib.pstore"), force: true
316
- end
317
-
318
- private
319
-
320
- def mock_isobib_get_123
321
- expect(Isobib::IsoBibliography).to receive(:get).with("ISO 123", "2001", {}).and_return(IsoBibItem.from_xml(ISOBIB_123_DATED))
322
- end
323
-
324
- def mock_isobib_get_123_undated
325
- expect(Isobib::IsoBibliography).to receive(:get).with("ISO 123", nil, {}).and_return(IsoBibItem.from_xml(ISOBIB_123_UNDATED))
326
- end
327
-
328
- def mock_isobib_get_124
329
- expect(Isobib::IsoBibliography).to receive(:get).with("ISO 124", "2014", {}).and_return(IsoBibItem.from_xml(ISOBIB_124_DATED))
330
- end
331
-
332
- end