UNPKG

19.3 kBJavaScriptView Raw
1/* @flow */
2
3import 'babel-polyfill'
4
5import MakeIndex from '../../src/Rules/MakeIndex'
6import { initializeRule } from '../helpers'
7
8import type { RuleDefinition } from '../helpers'
9
10async function initialize ({
11 RuleClass = MakeIndex,
12 parameters = [{
13 filePath: 'IndexControlFile.idx'
14 }, {
15 filePath: 'LaTeX.log-ParsedLaTeXLog'
16 }],
17 ...rest }: RuleDefinition = {}) {
18 return initializeRule({ RuleClass, parameters, ...rest })
19}
20
21describe('MakeIndex', () => {
22 describe('appliesToParameters', () => {
23 it('returns true if there are no splitindex notices in the log.', async (done) => {
24 const { dicy, rule, options } = await initialize({
25 parameters: [{
26 filePath: 'IndexControlFile.idx'
27 }, {
28 filePath: 'LaTeX.log-ParsedLaTeXLog',
29 value: {
30 inputs: [],
31 outputs: [],
32 messages: [],
33 calls: []
34 }
35 }]
36 })
37
38 expect(await MakeIndex.appliesToParameters(dicy.state, 'build', 'execute', options, ...rule.parameters)).toBe(true)
39
40 done()
41 })
42
43 it('returns false if there are splitindex notices in the log.', async (done) => {
44 const { dicy, rule, options } = await initialize({
45 parameters: [{
46 filePath: 'IndexControlFile.idx'
47 }, {
48 filePath: 'LaTeX.log-ParsedLaTeXLog',
49 value: {
50 inputs: [],
51 outputs: [],
52 messages: [{
53 severity: 'info',
54 text: 'Using splitted index at IndexControlFile.idx'
55 }],
56 calls: []
57 }
58 }]
59 })
60
61 expect(await MakeIndex.appliesToParameters(dicy.state, 'build', 'execute', options, ...rule.parameters)).toBe(false)
62
63 done()
64 })
65
66 it('returns false if there are splitindex calls in the log.', async (done) => {
67 const { dicy, rule, options } = await initialize({
68 parameters: [{
69 filePath: 'IndexControlFile.idx'
70 }, {
71 filePath: 'LaTeX.log-ParsedLaTeXLog',
72 value: {
73 inputs: [],
74 outputs: [],
75 messages: [],
76 calls: [{
77 args: ['splitindex', 'IndexControlFile.idx'],
78 options: { makeindex: '' },
79 status: 'executed (allowed)'
80 }]
81 }
82 }]
83 })
84
85 expect(await MakeIndex.appliesToParameters(dicy.state, 'build', 'execute', options, ...rule.parameters)).toBe(false)
86
87 done()
88 })
89 })
90
91 describe('getFileActions', () => {
92 it('returns a run action for a index control file.', async (done) => {
93 const { dicy, rule } = await initialize()
94 const file = await dicy.getFile('IndexControlFile.idx')
95
96 if (file) {
97 const actions = await rule.getFileActions(file)
98 expect(actions).toEqual(['run'])
99 }
100
101 done()
102 })
103
104 it('returns a updateDependencies action for a makeindex log file.', async (done) => {
105 const { dicy, rule } = await initialize()
106 const file = await dicy.getFile('IndexControlFile.ilg-ParsedMakeIndexLog')
107
108 if (file) {
109 const actions = await rule.getFileActions(file)
110 expect(actions).toEqual(['updateDependencies'])
111 }
112
113 done()
114 })
115
116 it('returns a updateDependencies action for a mendex log file.', async (done) => {
117 const { dicy, rule } = await initialize()
118 const file = await dicy.getFile('IndexControlFile.ilg-ParsedMendexLog')
119
120 if (file) {
121 const actions = await rule.getFileActions(file)
122 expect(actions).toEqual(['updateDependencies'])
123 }
124
125 done()
126 })
127
128 it('returns a updateDependencies action for a xindy log file.', async (done) => {
129 const { dicy, rule } = await initialize()
130 const file = await dicy.getFile('IndexControlFile.ilg-ParsedXindyLog')
131
132 if (file) {
133 const actions = await rule.getFileActions(file)
134 expect(actions).toEqual(['updateDependencies'])
135 }
136
137 done()
138 })
139
140 it('returns a no actions for a latex log file.', async (done) => {
141 const { dicy, rule } = await initialize()
142 const file = await dicy.getFile('LaTeX.log-ParsedLaTeXLog')
143
144 if (file) {
145 const actions = await rule.getFileActions(file)
146 expect(actions).toEqual([])
147 }
148
149 done()
150 })
151 })
152
153 describe('preEvaluate', () => {
154 it('retains run action if no makeindex calls present.', async (done) => {
155 const { rule } = await initialize()
156
157 rule.addActions()
158 await rule.preEvaluate()
159 expect(rule.actions.has('run')).toBe(true)
160
161 done()
162 })
163
164 it('removes run action if makeindex call present.', async (done) => {
165 const { rule } = await initialize({
166 parameters: [{
167 filePath: 'IndexControlFile.idx'
168 }, {
169 filePath: 'LaTeX.log-ParsedLaTeXLog',
170 value: {
171 inputs: [],
172 outputs: [],
173 messages: [],
174 calls: [{
175 args: ['makeindex', 'IndexControlFile.idx'],
176 options: {},
177 status: 'executed (allowed)'
178 }]
179 }
180 }]
181 })
182
183 rule.addActions()
184 await rule.preEvaluate()
185 expect(rule.actions.has('run')).toBe(false)
186
187 done()
188 })
189
190 it('retains run action if makeindex call failed.', async (done) => {
191 const { rule } = await initialize({
192 parameters: [{
193 filePath: 'IndexControlFile.idx'
194 }, {
195 filePath: 'LaTeX.log-ParsedLaTeXLog',
196 value: {
197 inputs: [],
198 outputs: [],
199 messages: [],
200 calls: [{
201 args: ['makeindex', 'IndexControlFile.idx'],
202 options: {},
203 status: 'clobbered'
204 }]
205 }
206 }]
207 })
208
209 rule.addActions()
210 await rule.preEvaluate()
211 expect(rule.actions.has('run')).toBe(true)
212
213 done()
214 })
215
216 it('retains run action if makeindex call was for another index.', async (done) => {
217 const { rule } = await initialize({
218 parameters: [{
219 filePath: 'IndexControlFile.idx'
220 }, {
221 filePath: 'LaTeX.log-ParsedLaTeXLog',
222 value: {
223 inputs: [],
224 outputs: [],
225 messages: [],
226 calls: [{
227 args: ['makeindex', 'foo.idx'],
228 options: {},
229 status: 'execute (allowed)'
230 }]
231 }
232 }]
233 })
234
235 rule.addActions()
236 await rule.preEvaluate()
237 expect(rule.actions.has('run')).toBe(true)
238
239 done()
240 })
241 })
242
243 describe('initialize', () => {
244 it('verifies that makeindex call overrides default options.', async (done) => {
245 const { rule } = await initialize({
246 parameters: [{
247 filePath: 'IndexControlFile.idx'
248 }, {
249 filePath: 'LaTeX.log-ParsedLaTeXLog',
250 value: {
251 inputs: [],
252 outputs: [],
253 messages: [],
254 calls: [{
255 args: ['makeindex', 'IndexControlFile.idx'],
256 options: {
257 c: true,
258 g: true,
259 l: true,
260 o: 'foo.ind',
261 p: 'odd',
262 r: true,
263 s: 'foo.ist',
264 t: 'foo.ilg'
265 },
266 status: 'executed (allowed)'
267 }]
268 }
269 }]
270 })
271
272 expect(rule.options.indexAutomaticRanges).toBe(false)
273 expect(rule.options.indexCompressBlanks).toBe(true)
274 expect(rule.options.indexLogPath).toBe('foo.ilg')
275 expect(rule.options.indexOutputPath).toBe('foo.ind')
276 expect(rule.options.indexOrdering).toBe('letter')
277 expect(rule.options.indexSorting).toBe('german')
278 expect(rule.options.indexStartPage).toBe('odd')
279 expect(rule.options.indexStyle).toBe('foo.ist')
280
281 done()
282 })
283
284 it('verifies that makeindex call with -T option results in Thai sorting.', async (done) => {
285 const { rule } = await initialize({
286 parameters: [{
287 filePath: 'IndexControlFile.idx'
288 }, {
289 filePath: 'LaTeX.log-ParsedLaTeXLog',
290 value: {
291 inputs: [],
292 outputs: [],
293 messages: [],
294 calls: [{
295 args: ['makeindex', 'IndexControlFile.idx'],
296 options: { T: true },
297 status: 'executed (allowed)'
298 }]
299 }
300 }]
301 })
302
303 expect(rule.options.indexSorting).toBe('thai')
304 done()
305 })
306
307 it('verifies that makeindex call with -L option results in locale sorting.', async (done) => {
308 const { rule } = await initialize({
309 parameters: [{
310 filePath: 'IndexControlFile.idx'
311 }, {
312 filePath: 'LaTeX.log-ParsedLaTeXLog',
313 value: {
314 inputs: [],
315 outputs: [],
316 messages: [],
317 calls: [{
318 args: ['makeindex', 'IndexControlFile.idx'],
319 options: { L: true },
320 status: 'executed (allowed)'
321 }]
322 }
323 }]
324 })
325
326 expect(rule.options.indexSorting).toBe('locale')
327 done()
328 })
329
330 it('verifies that makeindex call on a different index does not override default options.', async (done) => {
331 const { rule } = await initialize({
332 parameters: [{
333 filePath: 'IndexControlFile.idx'
334 }, {
335 filePath: 'LaTeX.log-ParsedLaTeXLog',
336 value: {
337 inputs: [],
338 outputs: [],
339 messages: [],
340 calls: [{
341 args: ['makeindex', 'foo.idx'],
342 options: {
343 c: true
344 },
345 status: 'executed (allowed)'
346 }]
347 }
348 }]
349 })
350
351 expect(rule.options.indexCompressBlanks).toBe(false)
352
353 done()
354 })
355
356 it('verifies that mendex call overrides default options and sets indexEngine.', async (done) => {
357 const { rule } = await initialize({
358 parameters: [{
359 filePath: 'IndexControlFile.idx'
360 }, {
361 filePath: 'LaTeX.log-ParsedLaTeXLog',
362 value: {
363 inputs: [],
364 outputs: [],
365 messages: [],
366 calls: [{
367 args: ['mendex', 'IndexControlFile.idx'],
368 options: {
369 d: 'foo',
370 f: true,
371 I: 'euc',
372 U: true
373 },
374 status: 'executed (allowed)'
375 }]
376 }
377 }]
378 })
379
380 expect(rule.options.indexDictionary).toBe('foo')
381 expect(rule.options.indexEngine).toBe('mendex')
382 expect(rule.options.indexForceKanji).toBe(true)
383 expect(rule.options.kanji).toBe('utf8')
384 expect(rule.options.kanjiInternal).toBe('euc')
385
386 done()
387 })
388
389 it('verifies that mendex call with -E option results in kanji setting of euc.', async (done) => {
390 const { rule } = await initialize({
391 parameters: [{
392 filePath: 'IndexControlFile.idx'
393 }, {
394 filePath: 'LaTeX.log-ParsedLaTeXLog',
395 value: {
396 inputs: [],
397 outputs: [],
398 messages: [],
399 calls: [{
400 args: ['mendex', 'IndexControlFile.idx'],
401 options: { E: true },
402 status: 'executed (allowed)'
403 }]
404 }
405 }]
406 })
407
408 expect(rule.options.kanji).toBe('euc')
409
410 done()
411 })
412
413 it('verifies that mendex call with -J option results in kanji setting of jis.', async (done) => {
414 const { rule } = await initialize({
415 parameters: [{
416 filePath: 'IndexControlFile.idx'
417 }, {
418 filePath: 'LaTeX.log-ParsedLaTeXLog',
419 value: {
420 inputs: [],
421 outputs: [],
422 messages: [],
423 calls: [{
424 args: ['mendex', 'IndexControlFile.idx'],
425 options: { J: true },
426 status: 'executed (allowed)'
427 }]
428 }
429 }]
430 })
431
432 expect(rule.options.kanji).toBe('jis')
433
434 done()
435 })
436
437 it('verifies that mendex call with -S option results in kanji setting of sjis.', async (done) => {
438 const { rule } = await initialize({
439 parameters: [{
440 filePath: 'IndexControlFile.idx'
441 }, {
442 filePath: 'LaTeX.log-ParsedLaTeXLog',
443 value: {
444 inputs: [],
445 outputs: [],
446 messages: [],
447 calls: [{
448 args: ['mendex', 'IndexControlFile.idx'],
449 options: { S: true },
450 status: 'executed (allowed)'
451 }]
452 }
453 }]
454 })
455
456 expect(rule.options.kanji).toBe('sjis')
457
458 done()
459 })
460 })
461
462 describe('constructCommand', () => {
463 it('returns correct arguments and command options for index file.', async (done) => {
464 const { rule } = await initialize()
465
466 expect(rule.constructCommand()).toEqual({
467 args: [
468 'makeindex',
469 '-t',
470 '{{$DIR_0/$NAME_0.ilg}}',
471 '-o',
472 '{{$DIR_0/$NAME_0.ind}}',
473 '{{$FILEPATH_0}}'
474 ],
475 cd: '$ROOTDIR',
476 severity: 'error',
477 inputs: ['$DIR_0/$NAME_0.ilg-ParsedMakeIndexLog'],
478 outputs: ['$DIR_0/$NAME_0.ind', '$DIR_0/$NAME_0.ilg']
479 })
480
481 done()
482 })
483
484 it('returns correct arguments and command options for nomenclature file.', async (done) => {
485 const { rule } = await initialize({
486 parameters: [{
487 filePath: 'NomenclatureControlFile.nlo'
488 }, {
489 filePath: 'LaTeX.log-ParsedLaTeXLog'
490 }]
491 })
492
493 expect(rule.constructCommand()).toEqual({
494 args: [
495 'makeindex',
496 '-t',
497 '{{$DIR_0/$NAME_0.nlg}}',
498 '-o',
499 '{{$DIR_0/$NAME_0.nls}}',
500 '-s',
501 'nomencl.ist',
502 '{{$FILEPATH_0}}'
503 ],
504 cd: '$ROOTDIR',
505 severity: 'error',
506 inputs: ['$DIR_0/$NAME_0.nlg-ParsedMakeIndexLog'],
507 outputs: ['$DIR_0/$NAME_0.nls', '$DIR_0/$NAME_0.nlg']
508 })
509
510 done()
511 })
512
513 it('returns correct arguments and command options for bibref file.', async (done) => {
514 const { rule } = await initialize({
515 parameters: [{
516 filePath: 'BibRefControlFile.bdx'
517 }, {
518 filePath: 'LaTeX.log-ParsedLaTeXLog'
519 }]
520 })
521
522 expect(rule.constructCommand()).toEqual({
523 args: [
524 'makeindex',
525 '-t',
526 '{{$DIR_0/$NAME_0.brlg}}',
527 '-o',
528 '{{$DIR_0/$NAME_0.bnd}}',
529 '-s',
530 'bibref.ist',
531 '{{$FILEPATH_0}}'
532 ],
533 cd: '$ROOTDIR',
534 severity: 'error',
535 inputs: ['$DIR_0/$NAME_0.brlg-ParsedMakeIndexLog'],
536 outputs: ['$DIR_0/$NAME_0.bnd', '$DIR_0/$NAME_0.brlg']
537 })
538
539 done()
540 })
541
542 it('use correct engine when indexEngine is set.', async (done) => {
543 const { rule } = await initialize({
544 options: { indexEngine: 'texindy' }
545 })
546
547 expect(rule.constructCommand().args[0]).toBe('texindy')
548
549 done()
550 })
551
552 it('add -c to command line when indexCompressBlanks is enabled.', async (done) => {
553 const { rule } = await initialize({
554 options: { indexCompressBlanks: true }
555 })
556
557 expect(rule.constructCommand().args).toContain('-c')
558
559 done()
560 })
561
562 it('add -l to command line when indexOrdering is set to \'letter\'.', async (done) => {
563 const { rule } = await initialize({
564 options: { indexOrdering: 'letter' }
565 })
566
567 expect(rule.constructCommand().args).toContain('-l')
568
569 done()
570 })
571
572 it('add -g to command line when indexSorting is set to \'german\'.', async (done) => {
573 const { rule } = await initialize({
574 options: { indexSorting: 'german' }
575 })
576
577 expect(rule.constructCommand().args).toContain('-g')
578
579 done()
580 })
581
582 it('add -T to command line when indexSorting is set to \'thai\'.', async (done) => {
583 const { rule } = await initialize({
584 options: { indexSorting: 'thai' }
585 })
586
587 expect(rule.constructCommand().args).toContain('-T')
588
589 done()
590 })
591
592 it('add -L to command line when indexSorting is set to \'locale\'.', async (done) => {
593 const { rule } = await initialize({
594 options: { indexSorting: 'locale' }
595 })
596
597 expect(rule.constructCommand().args).toContain('-L')
598
599 done()
600 })
601
602 it('add -r to command line when indexAutomaticRanges is disabled.', async (done) => {
603 const { rule } = await initialize({
604 options: { indexAutomaticRanges: false }
605 })
606
607 expect(rule.constructCommand().args).toContain('-r')
608
609 done()
610 })
611
612 it('add -p to command line when indexStartPage is set.', async (done) => {
613 const { rule } = await initialize({
614 options: { indexStartPage: 'odd' }
615 })
616
617 expect(rule.constructCommand().args).toEqual(jasmine.arrayContaining(['-p', 'odd']))
618
619 done()
620 })
621
622 it('add -s to command line when indexStyle is set.', async (done) => {
623 const { rule } = await initialize({
624 options: { indexStyle: 'foo.ist' }
625 })
626
627 expect(rule.constructCommand().args).toEqual(jasmine.arrayContaining(['-s', 'foo.ist']))
628
629 done()
630 })
631
632 it('add -E to command line when kanji is set to euc.', async (done) => {
633 const { rule } = await initialize({
634 options: { indexEngine: 'mendex', kanji: 'euc' }
635 })
636
637 expect(rule.constructCommand().args).toContain('-E')
638
639 done()
640 })
641
642 it('add -J to command line when kanji is set to jis.', async (done) => {
643 const { rule } = await initialize({
644 options: { indexEngine: 'mendex', kanji: 'jis' }
645 })
646
647 expect(rule.constructCommand().args).toContain('-J')
648
649 done()
650 })
651
652 it('add -S to command line when kanji is set to sjis.', async (done) => {
653 const { rule } = await initialize({
654 options: { indexEngine: 'mendex', kanji: 'sjis' }
655 })
656
657 expect(rule.constructCommand().args).toContain('-S')
658
659 done()
660 })
661
662 it('add -U to command line when kanji is set to utf8.', async (done) => {
663 const { rule } = await initialize({
664 options: { indexEngine: 'mendex', kanji: 'utf8' }
665 })
666
667 expect(rule.constructCommand().args).toContain('-U')
668
669 done()
670 })
671
672 it('add -I to command line when kanjiInternal set.', async (done) => {
673 const { rule } = await initialize({
674 options: { indexEngine: 'mendex', kanjiInternal: 'euc' }
675 })
676
677 expect(rule.constructCommand().args).toEqual(jasmine.arrayContaining(['-I', 'euc']))
678
679 done()
680 })
681
682 it('add -d to command line when indexDictionary is set.', async (done) => {
683 const { rule } = await initialize({
684 options: { indexEngine: 'mendex', indexDictionary: 'foo' }
685 })
686
687 expect(rule.constructCommand().args).toEqual(jasmine.arrayContaining(['-d', '{{foo}}']))
688
689 done()
690 })
691
692 it('add -f to command line when indexForceKanji is set.', async (done) => {
693 const { rule } = await initialize({
694 options: { indexEngine: 'mendex', indexForceKanji: true }
695 })
696
697 expect(rule.constructCommand().args).toContain('-f')
698
699 done()
700 })
701 })
702})