UNPKG

10.9 kBJavaScriptView Raw
1/* @flow */
2
3import 'babel-polyfill'
4
5import LaTeX from '../../src/Rules/LaTeX'
6import { initializeRule } from '../helpers'
7
8import type { RuleDefinition } from '../helpers'
9
10async function initialize ({
11 RuleClass = LaTeX,
12 ...rest }: RuleDefinition = {}) {
13 return initializeRule({ RuleClass, ...rest })
14}
15
16describe('LaTeX', () => {
17 describe('appliesToParameters', () => {
18 it('returns true if file type is \'LaTeX\'', async (done) => {
19 const { rule, options } = await initialize({
20 parameters: [{
21 filePath: 'LaTeX_article.tex'
22 }]
23 })
24
25 expect(await LaTeX.appliesToParameters(rule.state, 'build', 'execute', options, ...rule.parameters)).toBe(true)
26
27 done()
28 })
29
30 it('returns true if file type is \'LaTeX\' and sub type is standalone is master document.', async (done) => {
31 const { rule, options } = await initialize({
32 parameters: [{
33 filePath: 'LaTeX_standalone.tex'
34 }]
35 })
36
37 expect(await LaTeX.appliesToParameters(rule.state, 'build', 'execute', options, ...rule.parameters)).toBe(false)
38
39 done()
40 })
41
42 it('returns false if file type is \'LaTeX\' and sub type is standalone but not master document.', async (done) => {
43 const { rule, options } = await initialize({
44 parameters: [{
45 filePath: 'LaTeX_article.tex'
46 }]
47 })
48 const parameters = await rule.getFiles(['LaTeX_standalone.tex'])
49
50 expect(await LaTeX.appliesToParameters(rule.state, 'build', 'execute', options, ...parameters)).toBe(false)
51
52 done()
53 })
54
55 it('returns true if literateAgdaEngine is \'none\' and file type is \'LiterateAgda\'', async (done) => {
56 const { rule, options } = await initialize({
57 parameters: [{
58 filePath: 'LiterateAgda.lagda'
59 }],
60 options: { literateAgdaEngine: 'none' }
61 })
62
63 expect(await LaTeX.appliesToParameters(rule.state, 'build', 'execute', options, ...rule.parameters)).toBe(true)
64
65 done()
66 })
67
68 it('returns false if literateAgdaEngine is not \'none\' and file type is \'LiterateAgda\'', async (done) => {
69 const { rule, options } = await initialize({
70 parameters: [{
71 filePath: 'LiterateAgda.lagda'
72 }],
73 options: { literateAgdaEngine: 'agda' }
74 })
75
76 expect(await LaTeX.appliesToParameters(rule.state, 'build', 'execute', options, ...rule.parameters)).toBe(false)
77
78 done()
79 })
80
81 it('returns true if literateHaskellEngine is \'none\' and file type is \'LiterateHaskell\'', async (done) => {
82 const { rule, options } = await initialize({
83 parameters: [{
84 filePath: 'LiterateHaskell.lhs'
85 }],
86 options: { literateHaskellEngine: 'none' }
87 })
88
89 expect(await LaTeX.appliesToParameters(rule.state, 'build', 'execute', options, ...rule.parameters)).toBe(true)
90
91 done()
92 })
93
94 it('returns false if literateHaskellEngine is not \'none\' and file type is \'LiterateHaskell\'', async (done) => {
95 const { rule, options } = await initialize({
96 parameters: [{
97 filePath: 'LiterateHaskell.lhs'
98 }],
99 options: { literateHaskellEngine: 'lhs2TeX' }
100 })
101
102 expect(await LaTeX.appliesToParameters(rule.state, 'build', 'execute', options, ...rule.parameters)).toBe(false)
103
104 done()
105 })
106 })
107
108 describe('getFileActions', () => {
109 it('returns a run action for a LaTeX file.', async (done) => {
110 const { rule } = await initialize({
111 parameters: [{
112 filePath: 'LaTeX_article.tex'
113 }]
114 })
115 const file = await rule.getFile('LaTeX_article.tex')
116
117 if (file) {
118 const actions = await rule.getFileActions(file)
119 expect(actions).toEqual(['run'])
120 }
121
122 done()
123 })
124
125 it('returns a run and updateDependencies actions for a latex log file if a rerun LaTeX instruction is found.', async (done) => {
126 const { rule } = await initialize({
127 parameters: [{
128 filePath: 'LaTeX_article.tex'
129 }]
130 })
131 const file = await rule.getFile('LaTeX.log-ParsedLaTeXLog')
132
133 if (file) {
134 file.value = {
135 messages: [{
136 type: 'info',
137 text: 'Please (re)run Biber on the file: BiberControlFile and rerun LaTeX afterwards.'
138 }]
139 }
140 const actions = await rule.getFileActions(file)
141 expect(actions).toEqual(['updateDependencies', 'run'])
142 }
143
144 done()
145 })
146
147 it('returns an updateDependencies action for a latex log file if no rerun LaTeX instruction is found.', async (done) => {
148 const { rule } = await initialize({
149 parameters: [{
150 filePath: 'LaTeX_article.tex'
151 }]
152 })
153 const file = await rule.getFile('LaTeX.log-ParsedLaTeXLog')
154
155 if (file) {
156 file.value = {
157 messages: [{
158 type: 'info',
159 text: 'Please (re)run Biber on the file: BiberControlFile and rerun foo afterwards.'
160 }]
161 }
162 const actions = await rule.getFileActions(file)
163 expect(actions).toEqual(['updateDependencies'])
164 }
165
166 done()
167 })
168 })
169
170 describe('constructCommand', () => {
171 it('returns correct arguments and command options for LaTeX file.', async (done) => {
172 const { rule } = await initialize({
173 parameters: [{
174 filePath: 'LaTeX_article.tex'
175 }]
176 })
177
178 expect(rule.constructCommand()).toEqual({
179 args: [
180 'pdflatex',
181 '-file-line-error',
182 '-interaction=batchmode',
183 '-recorder',
184 '{{$FILEPATH_0}}'
185 ],
186 cd: '$ROOTDIR',
187 severity: 'error',
188 inputs: ['$OUTDIR/$JOB.aux'],
189 outputs: [
190 '$OUTDIR/$JOB.aux',
191 '$OUTDIR/$JOB.fls',
192 '$OUTDIR/$JOB.log',
193 '$OUTDIR/$JOB.synctex.gz'
194 ]
195 })
196
197 done()
198 })
199
200 it('change command name if engine is set.', async (done) => {
201 const { rule } = await initialize({
202 parameters: [{
203 filePath: 'LaTeX_article.tex'
204 }],
205 options: { engine: 'foo' }
206 })
207
208 expect(rule.constructCommand().args[0]).toEqual('foo')
209
210 done()
211 })
212
213 it('add -output-directory to command line when outputDirectory is set.', async (done) => {
214 const { rule } = await initialize({
215 parameters: [{
216 filePath: 'LaTeX_article.tex'
217 }],
218 options: { outputDirectory: 'foo' }
219 })
220
221 expect(rule.constructCommand().args).toContain('-output-directory=foo')
222
223 done()
224 })
225
226 it('add -jobname to command line when jobName is set.', async (done) => {
227 const { rule } = await initialize({
228 parameters: [{
229 filePath: 'LaTeX_article.tex'
230 }],
231 options: { jobName: 'foo' }
232 })
233
234 expect(rule.constructCommand().args).toContain('-jobname=foo')
235
236 done()
237 })
238
239 it('add -synctex to command line when synctex is enabled.', async (done) => {
240 const { rule } = await initialize({
241 parameters: [{
242 filePath: 'LaTeX_article.tex'
243 }],
244 options: { synctex: true }
245 })
246
247 expect(rule.constructCommand().args).toContain('-synctex=1')
248
249 done()
250 })
251
252 it('add -shell-escape to command line when shellEscape is enabled.', async (done) => {
253 const { rule } = await initialize({
254 parameters: [{
255 filePath: 'LaTeX_article.tex'
256 }],
257 options: { shellEscape: 'enabled' }
258 })
259
260 expect(rule.constructCommand().args).toContain('-shell-escape')
261
262 done()
263 })
264
265 it('add -no-shell-escape to command line when shellEscape is disabled.', async (done) => {
266 const { rule } = await initialize({
267 parameters: [{
268 filePath: 'LaTeX_article.tex'
269 }],
270 options: { shellEscape: 'disabled' }
271 })
272
273 expect(rule.constructCommand().args).toContain('-no-shell-escape')
274
275 done()
276 })
277
278 it('add -shell-restricted to command line when shellEscape is set to restricted.', async (done) => {
279 const { rule } = await initialize({
280 parameters: [{
281 filePath: 'LaTeX_article.tex'
282 }],
283 options: { shellEscape: 'restricted' }
284 })
285
286 expect(rule.constructCommand().args).toContain('-shell-restricted')
287
288 done()
289 })
290
291 it('add -output-format to command line when dvi format is requested.', async (done) => {
292 const { rule } = await initialize({
293 parameters: [{
294 filePath: 'LaTeX_article.tex'
295 }],
296 options: { outputFormat: 'dvi' }
297 })
298
299 expect(rule.constructCommand().args).toContain('-output-format=dvi')
300
301 done()
302 })
303
304 it('add -output-format to command line when ps format is requested.', async (done) => {
305 const { rule } = await initialize({
306 parameters: [{
307 filePath: 'LaTeX_article.tex'
308 }],
309 options: { outputFormat: 'ps' }
310 })
311
312 expect(rule.constructCommand().args).toContain('-output-format=dvi')
313
314 done()
315 })
316
317 it('add -no-pdf to command line when dvi format is requested for xelatex.', async (done) => {
318 const { rule } = await initialize({
319 parameters: [{
320 filePath: 'LaTeX_article.tex'
321 }],
322 options: { engine: 'xelatex', outputFormat: 'dvi' }
323 })
324
325 expect(rule.constructCommand().args).toContain('-no-pdf')
326
327 done()
328 })
329
330 it('adds kanji option when kanji encoding is set.', async (done) => {
331 const { rule } = await initialize({
332 parameters: [{
333 filePath: 'LaTeX_article.tex'
334 }],
335 options: { engine: 'uplatex', kanji: 'uptex' }
336 })
337
338 expect(rule.constructCommand().args).toContain('-kanji=uptex')
339
340 done()
341 })
342
343 it('does not add kanji option when kanji encoding is set but engine is not a Japanese variant.', async (done) => {
344 const { rule } = await initialize({
345 parameters: [{
346 filePath: 'LaTeX_article.tex'
347 }],
348 options: { kanji: 'uptex' }
349 })
350
351 expect(rule.constructCommand().args).not.toContain('-kanji=uptex')
352
353 done()
354 })
355
356 it('adds -kanji-internal option when kanji encoding is set.', async (done) => {
357 const { rule } = await initialize({
358 parameters: [{
359 filePath: 'LaTeX_article.tex'
360 }],
361 options: { engine: 'uplatex', kanjiInternal: 'uptex' }
362 })
363
364 expect(rule.constructCommand().args).toContain('-kanji-internal=uptex')
365
366 done()
367 })
368
369 it('does not add -kanji-internal option when kanji encoding is set but engine is not a Japanese variant.', async (done) => {
370 const { rule } = await initialize({
371 parameters: [{
372 filePath: 'LaTeX_article.tex'
373 }],
374 options: { kanjiInternal: 'uptex' }
375 })
376
377 expect(rule.constructCommand().args).not.toContain('-kanji-internal=uptex')
378
379 done()
380 })
381 })
382})