Debian Codegraph @

texmf-dist/source/generic/hyph-utf8/spec/tex/hyphen/language_spec.rb

raw
1 require_relative '../../spec_helper'
2
3 include TeX::Hyphen
4 include Language::TeXLive
5 include TeXLive
6 include Loader
7
8 describe String do
9 describe '#superstrip' do
10 it "calls String#strip" do
11 str = " foo bar "
12 expect(str).to receive(:strip).and_return "foo bar"
13 str.superstrip
14 end
15
16 it "strips TeX comments" do
17 expect("foo % bar".superstrip).to eq "foo "
18 end
19 end
20
21 describe '#supersplit' do
22 it "calls String#strip" do
23 str = "foo bar "
24 expect(str).to receive(:strip).and_return "foo bar"
25 str.supersplit
26 end
27
28 it "splits across whitespace ranges" do
29 expect("foo bar".supersplit).to eq ["foo", "bar"]
30 end
31 end
32
33 describe '#safe' do
34 it "strips hyphens" do
35 expect("foo-bar".safe).to eq "foobar"
36 end
37
38 it "strips spaces" do
39 expect("ancient greek".safe).to eq "ancientgreek"
40 end
41 end
42
43 describe '#titlecase' do
44 it "capitalises each word" do
45 expect("modern greek".titlecase).to eq "Modern Greek"
46 end
47 end
48 end
49
50 # TODO? Spec out PATH module
51
52 describe Author do
53 describe 'Class methods' do
54 describe '.authors' do
55 it "returns a hash of authors" do
56 expect(Author.authors).to be_a Hash
57 end
58 end
59
60 describe '.all' do
61 it "returns the array of authors" do
62 expect(Author.all).to be_an Array
63 end
64 end
65
66 describe '.[]' do
67 it "returns the author for the key" do
68 expect(Author['donald_knuth']).to be_an Author
69 end
70 end
71 end
72
73 describe 'Instance methods' do
74 let(:dek) { Author['donald_knuth'] }
75
76 describe '#name' do
77 it "returns the author’s name" do
78 expect(dek.name).to eq 'Donald'
79 end
80 end
81
82 describe '#surname' do
83 it "returns the author’s surname" do
84 expect(dek.surname).to eq 'Knuth'
85 end
86 end
87
88 describe '#email' do
89 it "returns the email" do
90 expect(dek.email).to be_nil
91 end
92 end
93 end
94 end
95
96 describe Language do
97 describe 'Class variables' do
98 it "has an end-of-header marker" do
99 expect(Language.class_variable_get :@@eohmarker).to match /^\={42}$/
100 end
101 end
102
103 describe '.new' do
104 it "creates a new Language instance" do
105 expect(Language.new).to be_a Language
106 end
107
108 it "takes an optional BCP47 tag as argument" do
109 language = Language.new('ro')
110 expect(language.instance_variable_get :@bcp47).to eq 'ro'
111 end
112
113 # it "calls .languages" do
114 # expect(Language).to receive(:languages).and_return({ 'pa' => nil })
115 # Language.new('pa')
116 # end
117 end
118
119 describe '.languages' do
120 it "sets the @@languages class variable" do
121 Language.languages
122 expect(Language.class_variable_get :@@languages).to be_a Hash
123 end
124
125 it "lists all languages" do
126 # All the TeX files. Note [no] and [mn-cyrl-x-lmc] don’t have corresponding plain text files.
127 expect(Language.languages.count).to eq 88 # Was 87 # Was 79; 3 more “TeX Live dummies” [ar] [fa] [grc-x-ibycus] TODO Maybe remove # Now 87 on 2025-02-14
128 end
129 end
130
131 describe '.all' do
132 it "returns the list of languages as an array" do
133 expect(Language.all).to be_an Array
134 end
135
136 it "returns 86 languages" do # That’s all of them except for [sr-cyrl]
137 expect(Language.all.count).to eq 87
138 end
139 end
140
141 describe '.all_by_iso639' do
142 it "returns a hash of arrays" do
143 expect(Language.all_by_iso639).to be_a Hash
144 expect(Language.all_by_iso639.values.map(&:class).uniq).to eq [Array]
145 end
146
147 it "groups languages by ISO 639 code elements" do
148 expect(Language.all_by_iso639['en'].count).to eq 2
149 end
150 end
151
152 describe '.find_by_bcp47' do
153 it "finds the language for that BCP47 tag" do
154 language = Language.find_by_bcp47 'bn'
155 expect(language).to be_a Language
156 end
157
158 it "calls .languages first" do
159 expect(Language).to receive(:languages).and_return({ 'cy' => Language.new('cy') })
160 Language.find_by_bcp47('cy')
161 end
162 end
163
164 describe '#bcp47' do # TODO Add #8bitenc
165 it "returns the BCP47 tag of the language" do
166 language = Language.new('oc')
167 expect(language.bcp47).to eq 'oc'
168 end
169 end
170
171 describe '#iso639' do
172 it "returns the ISO 639 primary tag" do
173 expect(Language.new('en-gb').iso639).to eq 'en'
174 end
175
176 it "works on 3-character tags" do
177 expect(Language.new('grc-x-ibycus').iso639).to eq 'grc'
178 end
179 end
180
181 # describe '#name' do
182 # let(:new_orthography_german) { Language.new('de-1996') }
183 #
184 # it "returns the name" do
185 # expect(new_orthography_german.name).to eq 'German, reformed spelling'
186 # end
187 #
188 # it "calls #extract_metadata first if necessary" do
189 # expect(new_orthography_german).to receive(:extract_metadata).and_return({ 'name' => 'German, reformed spelling' })
190 # new_orthography_german.name
191 # end
192 #
193 # it "doesn’t call #extract_metadata if @name is already set" do
194 # new_orthography_german.instance_variable_set :@name, 'Deutch in neuer Rechtschreibung'
195 # expect(new_orthography_german).not_to receive :extract_metadata
196 # new_orthography_german.name
197 # end
198 # end
199
200 # describe '#displayname' do
201 # it "returns @name most of the name" do
202 # romansh = Language.new('rm')
203 # expect(romansh.displayname).to eq 'Romansh'
204 # end
205
206 # it "strips to the language subtag part" do
207 # polytonic_greek = Language.new('el-polyton')
208 # expect(polytonic_greek.displayname).to eq 'Greek'
209 # end
210
211 # it "returns Norwegian for [nb] and [no]" do
212 # bokmål = Language.new('nb')
213 # expect(bokmål.displayname).to eq 'Norwegian'
214 # end
215
216 # it "returns Serbian for [sh]" do
217 # serbocroatian_cyrillic = Language.new('sh-cyrl')
218 # expect(serbocroatian_cyrillic.displayname).to eq 'Serbian'
219 # end
220
221 # it "calls #extract_metadata if needed" do
222 # friulan = Language.new('fur')
223 # expect(friulan).to receive :extract_metadata
224 # friulan.displayname
225 # end
226 # end
227
228 describe '#babelname' do
229 it "returns the Babel name" do
230 expect(Language.new('de-1996').babelname).to eq 'ngerman'
231 end
232
233 it "calls #extract_metadata first" do
234 german_CH = Language.new('de-ch-1901')
235 expect(german_CH).to receive :extract_metadata
236 german_CH.babelname
237 end
238 end
239
240 # describe '#packagename' do
241 # it "returns the package name for TeX Live" do
242 # expect(Language.new('gu').packagename).to eq 'indic'
243 # end
244
245 # it "uses some questionable choices" do
246 # expect(Language.new('grc').packagename).to eq 'ancient greek'
247 # end
248 # end
249
250 describe '#licences' do
251 let(:church_slavonic) { Language.new('cu') }
252
253 it "returns the licences as an array" do
254 expect(church_slavonic.licences).to eq ['MIT']
255 end
256
257 it "call #extract_metadata first if necessary" do
258 expect(church_slavonic).to receive(:extract_metadata)
259 church_slavonic.licences
260 end
261
262 it "doesn’t call #extract_metadata if @licences is already set" do
263 church_slavonic.instance_variable_set :@licences, ['MIT licence']
264 expect(church_slavonic).not_to receive :extract_metadata
265 church_slavonic.licences
266 end
267
268 it "raises an exception if @licences is nil or empty" do
269 nolicence = Language.new('qnl')
270 allow(File).to receive(:read).and_return("code: qnl\nauthors:\n - me")
271 expect { nolicence.licences }.to raise_exception NoLicence
272 end
273 end
274
275 describe '#lefthyphenmin' do
276 let(:swiss_spelling_german) { Language.new('de-ch-1901') }
277
278 it "returns the left hyphenmin value for typesetting" do
279 expect(swiss_spelling_german.lefthyphenmin).to eq 2
280 end
281
282 it "calls #extract_metadata first if necessary" do
283 expect(swiss_spelling_german).to receive :extract_metadata
284 swiss_spelling_german.lefthyphenmin
285 end
286
287 it "doesn’t call #extract_metadata if @lefthyphenmin is already set" do
288 swiss_spelling_german.instance_variable_set :@lefthyphenmin, 1
289 expect(swiss_spelling_german).not_to receive :extract_metadata
290 swiss_spelling_german.lefthyphenmin
291 end
292
293 it "uses the generation value if typesetting is missing" do
294 ethiopic = Language.new('mul-ethi')
295 expect(ethiopic.lefthyphenmin).to eq 1
296 end
297 end
298
299 describe '#righthyphenmin' do
300 let(:french) { Language.new('fr') }
301
302 it "returns the right hyphenmin value for typesetting" do
303 expect(french.righthyphenmin).to eq 2
304 end
305
306 it "call #extract_metadata first if necessary" do
307 expect(french).to receive :extract_metadata
308 french.righthyphenmin
309 end
310
311 it "doesn’t call #extract_metadata if @righthyphenmin is already set" do
312 french.instance_variable_set :@righthyphenmin, 2
313 expect(french).not_to receive :extract_metadata
314 french.righthyphenmin
315 end
316
317 it "uses the generation value if typesetting is missing" do
318 ethiopic = Language.new('mul-ethi')
319 expect(ethiopic.righthyphenmin).to eq 1
320 end
321 end
322
323 describe '#authors' do
324 let(:traditional_orthography_german) { Language.new('de-1901') }
325
326 it "returns the authors as an array" do
327 expect(traditional_orthography_german.authors).to eq ['Deutschsprachige Trennmustermannschaft']
328 end
329
330 it "calls #extract_metadata first if necessary" do
331 expect(traditional_orthography_german).to receive(:extract_metadata).and_return({ authors: ['Werner Lemberg', 'others'] })
332 traditional_orthography_german.authors
333 end
334
335 it "doesn’t call #extract_metadata if @authors is already set" do
336 traditional_orthography_german.instance_variable_set :@authors, ['German hyphenation patterns team']
337 expect(traditional_orthography_german).not_to receive :extract_metadata
338 traditional_orthography_german.authors
339 end
340 end
341
342 describe '#synonyms' do
343 it "returns the synonyms as an array" do
344 expect(Language.new('sl').synonyms).to eq ['slovene']
345 end
346
347 it "returns an empty array instead of nil if there are no synonyms" do
348 expect(Language.new('sk').synonyms).to eq []
349 end
350 end
351
352 describe '#encoding' do
353 it "returns the encoding" do
354 expect(Language.new('sh-cyrl').encoding).to eq 't2a'
355 end
356
357 it "returns “ascii” if applicable" do
358 expect(Language.new('pms').encoding).to eq 'ascii'
359 end
360
361 it "can also return something else" do
362 expect(Language.new('fur').encoding).to eq 'ec'
363 end
364
365 it "returns nil if patterns are Unicode-only" do
366 expect(Language.new('sa').encoding).to be_nil
367 end
368 end
369
370 describe '#github_link' do
371 it "returns the GitHub link" do
372 upper_sorbian = Language.new('hsb')
373 expect(upper_sorbian.github_link).to eq 'https://github.com/hyphenation/tex-hyphen/tree/master/hyph-utf8/tex/generic/hyph-utf8/patterns/tex/hyph-hsb.tex'
374 end
375 end
376
377 describe '#<=>' do
378 # it "compares Language’s using @name’s" do
379 # expect(Language.new('de-1996') <=> Language.new('fr')).to eq 1
380 # end
381
382 it "uses BCP47 codes if names are not available" do
383 expect(Language.new('zh-latn-pinyin') <=> Language.new('cu')).to eq 1
384 end
385 end
386
387 describe '#readtexfile' do
388 let(:basque) { Language.new('eu') }
389
390 it "reads the TeX file" do
391 expect(File).to receive(:read)
392 basque.readtexfile
393 end
394
395 it "stores the contents into the @@texfile class variable" do
396 basque.readtexfile
397 expect(Language.class_variable_get(:@@texfile)['eu']).to match /1ba.*1ko.*1t2xe.*su2b2r/m
398 end
399
400 it "recovers gracefully from nonexistent files" do
401 expect { Language.new('kl').readtexfile }.not_to raise_exception
402 end
403 end
404
405 describe '#patterns' do
406 it "returns the patterns" do
407 danish = Language.new('da')
408 expect(['.ae3', '.an3k', '.an1s'].all? { |p| danish.patterns.include? p }).to be_truthy
409 end
410
411 it "calls .languages first" do
412 language = Language.new('eu')
413 expect(Language).to receive(:languages).and_return({ 'eu' => Language.new('eu') })
414 pending "Needs pondering"
415 language.patterns
416 end
417
418 it "loads the patterns" do
419 language = Language.new('fi')
420 expect(language.patterns[151..154]).to eq ['uu1a2', 'uu1e2', 'uu1o2', 'uu1i2']
421 end
422
423 it "doesn’t crash on inexistent patterns" do
424 expect { Language.new('zu').patterns }.not_to raise_exception
425 end
426
427 it "caches the list of patterns" do
428 language = Language.new('ru')
429 language.patterns
430 expect(language.instance_variable_get(:@patterns)[0..2]).to eq ['.аб1р', '.аг1ро', '.ади2']
431 end
432
433 it "uses the [no] patterns for [nb]" do
434 expect(Language.new('nb').patterns).to eq Language.new('no').patterns
435 end
436
437 it "expands the Esperanto patterns" do
438 esperanto = Language.new('eo')
439 expect(['.di3s2a.', '.di3s2aj.', '.di3s2ajn.', '.di3s2an.', '.di3s2e.'].any? { |p| esperanto.patterns.include? p }).to be_truthy
440 end
441 end
442
443 describe '#exceptions' do
444 it "returns the hyphenation exceptions" do
445 language = Language.new('ga')
446 expect(language.exceptions[0..2]).to eq ['bhrachtaí', 'mbrachtaí', 'cháintí']
447 end
448
449 it "calls .languages first" do
450 language = Language.new('hu')
451 pending "Needs examining"
452 expect(Language).to receive(:all).and_return({ 'hu' => Language.new('hu') })
453 language.patterns
454 end
455
456 it "loads the exceptions" do
457 language = Language.new('is')
458 expect(File).to receive(:read).and_return("alc-un alc-u-nis-si-me alc-un-men-te")
459 language.patterns
460 end
461
462 it "doesn’t crash on inexistent patterns" do
463 expect { Language.new('iu').exceptions}.not_to raise_exception
464 end
465
466 it "caches the exceptions" do
467 language = Language.new('sk')
468 language.exceptions
469 expect(language.instance_variable_get(:@exceptions)[0..2]).to match ['dosť', 'me-tó-da', 'me-tó-dy']
470 end
471
472 it "hashes the exceptions" do
473 language = Language.new('en-gb')
474 language.exceptions
475 hyphenation = language.instance_variable_get :@hyphenation
476 expect(hyphenation.count).to eq 8
477 expect(hyphenation['however']).to eq 'how-ever'
478 end
479 end
480
481 describe '#hyphenate' do
482 it "hyphenates with the appropriate patterns" do
483 czech = Language.new('cs')
484 expect(czech.hyphenate('ubrousek')).to eq 'ubrou-sek'
485 end
486
487 it "takes hyphenmins in account if available" do
488 language = Language.new('de-1996')
489 expect(language.hyphenate('Zwangsvollstreckungsmaßnahme')).to eq 'zwangs-voll-stre-ckungs-maß-nah-me'
490 end
491
492 it "takes exceptions in account if available" do
493 american_english = Language.new('en-us')
494 expect(american_english.hyphenate('project')).to eq 'project'
495 end
496
497 it "initialises the hydra if needed" do
498 language = Language.new('de-1901')
499 language.hyphenate('Zwangsvollstreckungsmaßnahme')
500 expect(language.instance_variable_get(:@hydra)).to be_a Hydra
501 end
502
503 it "calls #exceptions" do
504 esperanto = Language.new('eo')
505 expect(esperanto).to receive(:exceptions)
506 esperanto.instance_variable_set :@hyphenation, { 'ŝtatregosciencon' => 'ŝta-tre-go-scien-con' }
507 esperanto.hyphenate('ŝtatregosciencon')
508 end
509 end
510
511 describe '#private_use?' do
512 it "returns true for languages with private use BCP 47 tags" do
513 expect(Language.new('qls').private_use?).to be_truthy
514 end
515
516 it "returns true otherwise" do
517 expect(Language.new('qyz').private_use?).to be_falsey
518 end
519
520 it "doesn’t crash on two-letter tags" do
521 expect { Language.new('qa').private_use? }.not_to raise_exception
522 end
523
524 it "returns false on two-letter tags" do
525 expect(Language.new('qt').private_use?).to be_falsey
526 end
527
528 it "works correctly on four-letter tags" do
529 expect(Language.new('qaaa').private_use?).to be_falsey
530 end
531
532 it "works correctly in the presence of subtags" do
533 expect(Language.new('qtz-GB').private_use?).to be_truthy
534 end
535 end
536
537 describe '#extract_metadata' do
538 it "returns a hash with the metadata" do
539 language = Language.new('bg')
540 expect(language.extract_metadata).to be_a Hash
541 end
542
543 it "raises an exception if the metadata is just a string" do
544 language = Language.new('qls')
545 allow(File).to receive(:read).and_return("just a string")
546 expect { language.extract_metadata }.to raise_exception InvalidMetadata
547 end
548
549 it "raises an exception if the licence is missing" do
550 language = Language.new('qlv')
551 allow(File).to receive(:read).and_return("name: language virtual\ncode: qlv")
552 expect { language.extract_metadata }.to raise_exception InvalidMetadata
553 end
554
555 it "raises an exception if @authors is nil or empty" do
556 not_church_slavonic = Language.new('qcu')
557 allow(File).to receive(:read).and_return "code: qcu\nlicence:\n name:\n MIT"
558 expect { not_church_slavonic.authors }.to raise_exception NoAuthor
559 end
560
561 it "doesn’t crash on invalid licence entries" do
562 syntax_error = Language.new('qse')
563 allow(File).to receive(:read).and_return "foo:\nbar"
564 expect { syntax_error.extract_metadata }.not_to raise_exception Psych::SyntaxError
565 end
566
567 it "sets the language name" do
568 language = Language.new('th')
569 language.extract_metadata
570 expect(language.instance_variable_get :@name).to eq 'Thai'
571 end
572
573 it "sets the licence list" do
574 language = Language.new('la')
575 language.extract_metadata
576 expect(language.instance_variable_get :@licences).to eq ['MIT', 'LPPL']
577 end
578
579 it "sets lefthyphenmin" do
580 pali = Language.new('pi')
581 pali.extract_metadata
582 expect(pali.instance_variable_get :@lefthyphenmin).to eq 1
583 end
584
585 it "sets righthyphenmin" do
586 german = Language.new('de-1996')
587 german.extract_metadata
588 expect(german.instance_variable_get :@righthyphenmin).to eq 2
589 end
590
591 it "sets the list of authors" do
592 liturgical_latin = Language.new('la-x-liturgic')
593 liturgical_latin.extract_metadata
594 expect(liturgical_latin.instance_variable_get :@authors).to eq ['Claudio Beccari', 'Monastery of Solesmes', 'Élie Roux']
595 end
596
597 context "With Swedish as an example" do
598 let(:swedish) { Language.new('sv') }
599
600 it "sets the message" do
601 swedish.extract_metadata
602 expect(swedish.instance_variable_get :@message).to eq "Swedish hyphenation patterns"
603 end
604
605 it "sets the old pattern file name" do
606 swedish.extract_metadata
607 expect(swedish.instance_variable_get :@legacy_patterns).to eq "svhyph.tex"
608 end
609
610 it "leaves @use_old_loader to nil in most cases" do
611 swedish.extract_metadata
612 expect(swedish.instance_variable_get :@use_old_loader).to be_nil
613 end
614
615 it "sets the @use_old_loader boolean to true if applicable" do
616 norwegian = Language.new('no')
617 norwegian.extract_metadata
618 expect(norwegian.instance_variable_get :@use_old_loader).to be_truthy
619 end
620
621 it "leaves @use_old_patterns_comment to nil in most cases" do
622 swedish.extract_metadata
623 expect(swedish.instance_variable_get :@use_old_patterns_comment).to be_nil
624 end
625
626 it "sets the @use_old_patterns_comment to string if applicable" do
627 german_AR = Language.new('de-1901')
628 german_AR.extract_metadata
629 expect(german_AR.instance_variable_get :@use_old_patterns_comment).to eq "Kept for the sake of backward compatibility, but newer and better patterns by WL are available."
630 end
631
632 it "sets the long description" do
633 swedish.extract_metadata
634 expect(swedish.instance_variable_get :@description).to eq "Hyphenation patterns for Swedish in T1/EC and UTF-8 encodings."
635 end
636
637 it "sets the Babel name" do
638 swedish.extract_metadata
639 expect(swedish.instance_variable_get :@babelname).to eq "swedish"
640 end
641
642 it "sets the Babel name even if it is slightly silly ;-)" do
643 german_NR = Language.new('de-1996')
644 german_NR.extract_metadata
645 expect(german_NR.instance_variable_get :@babelname).to eq "ngerman"
646 end
647
648 it "sets @package to nil in most cases" do
649 expect(swedish.instance_variable_get :@package).to be_nil
650 end
651
652 it "sets @package for a few languages" do
653 gujarati = Language.new('gu')
654 gujarati.extract_metadata
655 expect(gujarati.instance_variable_get :@package).to eq 'indic'
656 end
657 end
658 end
659
660 describe '#has_apostrophes?' do
661 it "returns if patterns have apostrophes" do
662 expect(Language.new('be').has_apostrophes?).to be_truthy
663 end
664
665 it "returns false otherwise" do
666 expect(Language.new('bn').has_apostrophes?).to be_falsey
667 end
668 end
669
670 describe '#has_hyphens?' do
671 it "returns true if patterns have dashes" do
672 expect(Language.new('uk').has_hyphens?).to be_truthy
673 end
674
675 it "returns false otherwise" do
676 expect(Language.new('tr').has_hyphens?).to be_falsey
677 end
678 end
679
680 describe '#isgreek?' do
681 it "returns true if language is Greek (sort of)" do
682 expect(Language.new('grc').isgreek?).to be_truthy
683 end
684
685 it "returns false if not" do
686 expect(Language.new('la').isgreek?).to be_falsey
687 end
688
689 it "now returns true for Ibycus too" do
690 expect(Language.new('grc-x-ibycus').isgreek?).to be_truthy
691 end
692 end
693
694 describe '#message' do
695 it "returns the message to be displayed on the terminal" do
696 expect(Language.new('af').message).to eq 'Afrikaans hyphenation patterns'
697 end
698 end
699
700 describe '#known_bugs' do
701 it "returns the known bugs" do
702 american_english = Language.new('en-us')
703 expect(american_english.known_bugs.keys).to eq ['de-mo-c-rat']
704 end
705 end
706
707 describe TeXLive do
708 describe '#loadhyph' do
709 it "returns the name of the pattern loader file" do
710 expect(Language.new('cy').loadhyph).to eq 'loadhyph-cy.tex'
711 end
712
713 it "replaces the main sh subtag by sr" do
714 expect(Language.new('sh-latn').loadhyph).to eq 'loadhyph-sr-latn.tex'
715 end
716
717 it "returns the old loader name if applicable" do
718 expect(Language.new('grc-x-ibycus').loadhyph).to eq 'ibyhyph.tex'
719 end
720 end
721
722 describe '#list_loader' do
723 it "returns the tlpsrc line with the loader" do
724 expect(Language.new('hr').list_loader).to eq 'file=loadhyph-hr.tex'
725 end
726
727 it "no longer includes an empty line for Arabic and Farsi" do
728 expect(Language.new('ar').list_loader).to eq "file=hyph-ar.tex" # was "file=hyph-ar.tex \\\n\tfile_patterns="
729 end
730
731 it "includes a Lua special line for Ibycus" do
732 expect(Language.new('grc-x-ibycus').list_loader).to eq "file=ibyhyph.tex \\\n\tluaspecial=\"disabled:8-bit only\""
733 end
734 end
735
736 describe '#list_run_files' do
737 it "returns the list of TeX file" do
738 # pending "Something changed" # ... and changed back
739 expect(Language.new('ka').list_run_files).to eq ['tex/generic/hyph-utf8/loadhyph/loadhyph-ka.tex',
740 'tex/generic/hyph-utf8/patterns/tex/hyph-ka.tex',
741 'tex/generic/hyph-utf8/patterns/ptex/hyph-ka.t8m.tex',
742 'tex/generic/hyph-utf8/patterns/txt/hyph-ka.pat.txt']
743 end
744
745 it "works correctly" do
746 pending "change"
747 expect(Language.new('zh-latn-pinyin').list_run_files).to eq [
748 'tex/generic/hyph-utf8/loadhyph/loadhyph-zh-latn-pinyin.tex',
749 'tex/generic/hyph-utf8/patterns/tex/hyph-zh-latn-pinyin.tex',
750 'tex/generic/hyph-utf8/patterns/txt/hyph-zh-latn-pinyin.pat.txt']
751 end
752 end
753
754 describe '#patterns_line' do
755 it "returns the patterns line for TLPSRC" do
756 expect(Language.new('tk').patterns_line).to eq "file_patterns=hyph-tk.pat.txt"
757 end
758
759 it "returns two files for Serbian" do
760 expect(Language.new('sh-cyrl').patterns_line).to eq "file_patterns=hyph-sh-latn.pat.txt,hyph-sh-cyrl.pat.txt"
761 end
762 end
763
764 describe '#exceptions_line' do
765 it "returns the exceptions line for TLPSRC" do
766 expect(Language.new('nn').exceptions_line).to eq "file_exceptions=hyph-nn.hyp.txt"
767 end
768
769 it "returns two files for Serbian" do
770 expect(Language.new('sh-latn').exceptions_line).to eq "file_exceptions=hyph-sh-latn.hyp.txt,hyph-sh-cyrl.hyp.txt"
771 end
772 end
773
774 describe '#extract_apostrophes' do
775 it "returns the list of patterns with apostrophes" do
776 expect(Language.new('af').extract_apostrophes[:with_apostrophe]).to eq ['.af6ro’', '.a7fro’s', '.l’7etji', '.m’7etji', '.r’7etji', 's’9ie.', 'x’9ie.']
777 end
778
779 it "returns nil otherwise" do
780 expect(Language.new('nl').extract_apostrophes[:with_apostrophe]).to be_nil
781 end
782 end
783
784 describe '#extract_characters' do
785 it "extracts the list of characters with in lowercase and uppercase" do
786 expect(Language.new('id').extract_characters).to eq (('a'..'z').to_a - ['x']).map { |c| c + c.upcase }
787 end
788 end
789
790 describe '#comments_and_licence' do
791 it "extracts the header" do
792 expect(Language.new('kmr').comments_and_licence).to match /^% title: Hyphenation patterns for Kurmanji \(Northern Kurdish\).*The patterns are generated by patgen from a word list of approx\. 2500\n% hyphenated words provided by Medeni Shemdê$/m
793 end
794 end
795
796 describe '#list_synonyms' do
797 it "returns a list of synonyms" do
798 expect(Language.new('es').list_synonyms).to eq ' synonyms=espanol'
799 end
800 end
801
802 describe '#list_hyphenmins' do
803 it "returns the hyphenmins" do
804 expect(Language.new('gl').list_hyphenmins).to eq "lefthyphenmin=2 \\\n\trighthyphenmin=2"
805 end
806 end
807
808 describe '#message' do
809 it "returns the message to be displayed to TeX users" do
810 expect(Language.new('de-1996').message).to eq 'German hyphenation patterns (reformed orthography)'
811 end
812 end
813
814 describe '#legacy_patterns' do
815 it "returns the file name of the legacy patterns" do
816 expect(Language.new('de-1996').legacy_patterns).to eq 'dehyphn.tex'
817 end
818 end
819
820 describe '#use_old_loader' do
821 it "says whether to use old loader or not" do
822 expect(Language.new('de-1996').use_old_loader).to be_nil
823 end
824
825 it "returns true if applicable" do
826 # pending "Refactor in progress"
827 expect(Language.new('no').use_old_loader).to be_truthy
828 end
829 end
830
831 describe '#use_old_patterns_comment' do
832 it "returns true if language uses old patterns" do
833 expect(Language.new('de-1996').use_old_patterns_comment).to be_truthy
834 end
835
836 it "returns nil otherwise" do
837 expect(Language.new('no').use_old_patterns_comment).to be_nil
838 end
839
840 it "is a string" do
841 expect(Language.new('cop').use_old_patterns_comment).to be_a String
842 end
843 end
844
845 describe '#luaspecial' do
846 it "returns the Lua special comment" do
847 expect(Language.new('mn-cyrl-x-lmc').luaspecial).to be == 'disabled:only for 8bit montex with lmc encoding'
848 end
849
850 it "returns nil otherwise" do
851 expect(Language.new('mn-cyrl').luaspecial).to be_nil
852 end
853 end
854
855 describe '#description' do
856 it "returns the long description" do
857 text = <<-EOD
858 Hyphenation patterns for Dutch in T1/EC and UTF-8 encodings.
859 These patterns don't handle cases like 'menuutje' > 'menu-tje',
860 and don't hyphenate words that have different hyphenations according
861 to their meaning.
862 EOD
863 description = text.split("\n").map(&:strip).join("\n")
864 expect(Language.new('nl').description).to eq description
865 end
866
867 it "returns nil for new spelling German, for some reason" do
868 expect(Language.new('de-1996').description).to be_nil
869 end
870 end
871
872 describe '#package' do
873 it "returns the package name if applicable" do
874 expect(Language.new('bn').package).to eq 'indic'
875 end
876
877 it "returns nil in most cases" do
878 expect(Language.new('bg').package).to be_nil
879 end
880
881 it "calls #extract_metadata first" do
882 hindi = Language.new('hi')
883 expect(hindi).to receive :extract_metadata
884 hindi.package
885 end
886 end
887 end
888 end
889
890 describe Package do
891 let(:latin) { Package.find('latin') }
892 let(:german) { Package.find('german') }
893 let(:hungarian) { Package.find('hungarian') }
894 let(:norwegian) { Package.find('norwegian') }
895
896 describe "Instance variables" do
897 it "has a @name" do
898 expect(latin.name).to eq 'latin'
899 end
900 end
901
902 describe '.new' do
903 it "initialises @languages to an empty array" do
904 package = Package.new('mongolian')
905 expect(package.instance_variable_get :@languages).to eq []
906 end
907 end
908
909 describe "#description_s" do
910 it "returns the short description" do
911 expect(latin.description_s).to eq 'Latin hyphenation patterns'
912 end
913 end
914
915 describe "#description" do
916 it "returns the long description" do
917 expect(latin.description).to match /^Hyphenation patterns for.*modern spelling.*medieval spelling/m
918 expect(latin.description).to match /Classical Latin/
919 expect(latin.description).to match /Liturgical Latin/
920 end
921
922 it "returns the long package description" do
923 text = <<-EOD
924 Hyphenation patterns for German in T1/EC and UTF-8 encodings,
925 for traditional and reformed spelling, including Swiss German.
926 The package includes the latest patterns from dehyph-exptl
927 (known to TeX under names 'german', 'ngerman' and 'swissgerman'),
928 however 8-bit engines still load old versions of patterns
929 for 'german' and 'ngerman' for backward-compatibility reasons.
930 Swiss German patterns are suitable for Swiss Standard German
931 (Hochdeutsch) not the Alemannic dialects spoken in Switzerland
932 (Schwyzerduetsch).
933 There are no known patterns for written Schwyzerduetsch.
934 EOD
935 description = text.split("\n").map(&:strip).join("\n")
936 expect(Package.find('german').description).to match description
937 end
938 end
939
940 describe '#add_language' do
941 it "adds a language to the package" do
942 package = Package.new('indic')
943 assamese = Language.new('as')
944 package.add_language(assamese)
945 expect(package.instance_variable_get(:@languages).first).to eq assamese
946 end
947 end
948
949 describe "#languages" do
950 it "returns the list of languages" do
951 expect(latin.languages.map(&:bcp47).sort).to eq ['la', 'la-x-classic', 'la-x-liturgic']
952 end
953 end
954
955 describe "#has_dependency?" do
956 it "returns the external dependencies" do
957 expect(german.has_dependency?).to eq "dehyph"
958 end
959
960 it "returns nil for most packages" do
961 expect(hungarian.has_dependency?).to be_nil
962 end
963 end
964
965 describe "#list_dependencies" do
966 it "lists the dependencies" do
967 # FIXME Should return ['depend hyphen-base', 'depend hyph-utf8', 'depend dehyph'] or nothing
968 expect(german.has_dependency?).to eq 'dehyph'
969 end
970 end
971
972 describe "#list_support_files" do # FIXME? list_non_run_files
973 it "lists doc and source files" do
974 expect(hungarian.list_support_files('doc')).to eq ['doc/generic/hyph-utf8/languages/hu', 'doc/generic/huhyphen']
975 # FIXME Should return ['texmf-dist/doc/generic/huhyphen', 'texmf-dist/doc/generic/hyph-utf8/languages/hu'] or nothing
976 end
977 end
978
979 describe "#list_run_files" do
980 it "lists the run-time files" do
981 # pending "it crashes ;-)"
982 norwegian_run = norwegian.list_run_files
983 # pending "it crashes again ;-)" # Fixed now
984 expect(norwegian_run.count).to eq 11
985 expect(norwegian_run.select { |f| f =~ /tex\/hyph-[^\.]*\.tex$/ }).to eq ['tex/generic/hyph-utf8/patterns/tex/hyph-no.tex',
986 'tex/generic/hyph-utf8/patterns/tex/hyph-nb.tex',
987 'tex/generic/hyph-utf8/patterns/tex/hyph-nn.tex']
988 end
989 end
990
991 describe '#<=>' do
992 it "compares two Package’s" do
993 # puts hungarian.class, german.class
994 expect(hungarian.<=> german).to eq 1
995 end
996 end
997
998 describe '#find' do
999 it "returns the package with that name" do
1000 expect(Package.find('norwegian')).to eq norwegian
1001 end
1002 end
1003 end
1004
1005 describe Converter do
1006 describe '#read' do
1007 it "reads the conversion data" do
1008 converter = Converter.new
1009 converter.read(File.join(File.expand_path(__dir__), '..', '..', '..', 'data', 'encodings', 'macedonian.dat'))
1010 mapping = converter.instance_variable_get(:@mapping)
1011 expect(mapping).to be_a Hash
1012 expect(mapping.count).to be_equal 42
1013 expect(mapping[248]).to be == 'ш'
1014 end
1015 end
1016
1017 describe '#convert' do
1018 it "runs one pass through the file" do
1019 converter = Converter.new
1020 converter.read(File.join(File.expand_path(__dir__), '..', '..', '..', 'data', 'encodings', 'macedonian.dat'))
1021 mkconv = converter.convert(File.join(File.expand_path(__dir__), '..', '..', '..', '..', '..', '..', '..', 'old', 'other', 'mk', 'mkhyphen.tex'))
1022 expect(mkconv.each_line.count).to eq 725
1023 expect(mkconv).to be =~ /1шу$/
1024 end
1025 end
1026 end