UNPKG

3.81 kBJavaScriptView Raw
1/* @flow */
2
3import 'babel-polyfill'
4
5import SplitIndex from '../../src/Rules/SplitIndex'
6import { initializeRule } from '../helpers'
7
8import type { RuleDefinition } from '../helpers'
9
10async function initialize ({
11 RuleClass = SplitIndex,
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('SplitIndex', () => {
22 describe('appliesToParameters', () => {
23 it('returns false if there are no splitindex notices in the log.', async (done) => {
24 const { rule, options } = await initialize()
25
26 expect(await SplitIndex.appliesToParameters(rule.state, 'build', 'execute', options, ...rule.parameters)).toBe(false)
27
28 done()
29 })
30
31 it('returns true if there are splitindex notices in the log.', async (done) => {
32 const { rule, options } = await initialize({
33 parameters: [{
34 filePath: 'IndexControlFile.idx'
35 }, {
36 filePath: 'LaTeX.log-ParsedLaTeXLog',
37 value: {
38 inputs: [],
39 outputs: [],
40 messages: [{
41 severity: 'info',
42 text: 'Using splitted index at IndexControlFile.idx'
43 }],
44 calls: []
45 }
46 }]
47 })
48
49 expect(await SplitIndex.appliesToParameters(rule.state, 'build', 'execute', options, ...rule.parameters)).toBe(true)
50
51 done()
52 })
53
54 it('returns true if there are splitindex calls in the log.', async (done) => {
55 const { rule, options } = await initialize({
56 parameters: [{
57 filePath: 'IndexControlFile.idx'
58 }, {
59 filePath: 'LaTeX.log-ParsedLaTeXLog',
60 value: {
61 inputs: [],
62 outputs: [],
63 messages: [],
64 calls: [{
65 args: ['splitindex', 'IndexControlFile.idx'],
66 options: { makeindex: '' },
67 status: 'executed (allowed)'
68 }]
69 }
70 }]
71 })
72
73 expect(await SplitIndex.appliesToParameters(rule.state, 'build', 'execute', options, ...rule.parameters)).toBe(true)
74
75 done()
76 })
77 })
78
79 describe('getFileActions', () => {
80 it('returns a run action for a index control file.', async (done) => {
81 const { rule } = await initialize()
82 const file = await rule.getFile('IndexControlFile.idx')
83
84 if (file) {
85 const actions = await rule.getFileActions(file)
86 expect(actions).toEqual(['run'])
87 }
88
89 done()
90 })
91
92 it('returns a updateDependencies action for a splitindex log file.', async (done) => {
93 const { rule } = await initialize()
94 const file = await rule.getFile('IndexControlFile.ilg-ParsedSplitIndexLog')
95
96 if (file) {
97 const actions = await rule.getFileActions(file)
98 expect(actions).toEqual(['updateDependencies'])
99 }
100
101 done()
102 })
103
104 it('returns a no actions for a latex log file.', async (done) => {
105 const { rule } = await initialize()
106 const file = await rule.getFile('LaTeX.log-ParsedLaTeXLog')
107
108 if (file) {
109 const actions = await rule.getFileActions(file)
110 expect(actions).toEqual([])
111 }
112
113 done()
114 })
115 })
116
117 describe('constructCommand', () => {
118 it('returns correct arguments and command options for index file.', async (done) => {
119 const { rule } = await initialize()
120
121 expect(rule.constructCommand()).toEqual({
122 args: ['splitindex', '-v', '-v', '-m', '', '{{$FILEPATH_0}}'],
123 cd: '$ROOTDIR',
124 severity: 'error',
125 inputs: ['$DIR_0/$NAME_0.log-ParsedSplitIndexStdOut'],
126 stdout: '$DIR_0/$NAME_0.log-SplitIndexStdOut',
127 stderr: '$DIR_0/$NAME_0.log-SplitIndexStdErr'
128 })
129
130 done()
131 })
132 })
133})