UNPKG

3.87 kBJavaScriptView Raw
1/* @flow */
2
3import 'babel-polyfill'
4
5import LhsToTeX from '../../src/Rules/LhsToTeX'
6import { initializeRule } from '../helpers'
7
8import type { RuleDefinition } from '../helpers'
9
10async function initialize ({
11 RuleClass = LhsToTeX,
12 parameters = [{
13 filePath: 'LiterateHaskell.lhs'
14 }],
15 ...rest }: RuleDefinition = {}) {
16 return initializeRule({ RuleClass, parameters, ...rest })
17}
18
19describe('LhsToTeX', () => {
20 describe('appliesToParameters', () => {
21 it('returns true if file type is \'LiterateHaskell\'', async (done) => {
22 const { rule, options } = await initialize()
23
24 expect(await LhsToTeX.appliesToParameters(rule.state, 'build', 'execute', options, ...rule.parameters)).toBe(true)
25
26 done()
27 })
28
29 it('returns true if literateAgdaEngine is \'lhs2TeX\' and file type is \'LiterateAgda\'', async (done) => {
30 const { rule, options } = await initialize({
31 parameters: [{ filePath: 'LiterateAgda.lagda' }],
32 options: { literateAgdaEngine: 'lhs2TeX' }
33 })
34
35 expect(await LhsToTeX.appliesToParameters(rule.state, 'build', 'execute', options, ...rule.parameters)).toBe(true)
36
37 done()
38 })
39
40 it('returns false if literateAgdaEngine is not \'lhs2TeX\' and file type is \'LiterateAgda\'', async (done) => {
41 const { rule, options } = await initialize({
42 parameters: [{ filePath: 'LiterateAgda.lagda' }]
43 })
44
45 expect(await LhsToTeX.appliesToParameters(rule.state, 'build', 'execute', options, ...rule.parameters)).toBe(false)
46
47 done()
48 })
49 })
50
51 describe('constructCommand', () => {
52 it('returns correct arguments and command options for lhs file.', async (done) => {
53 const { rule } = await initialize()
54
55 expect(rule.constructCommand()).toEqual({
56 args: ['lhs2TeX', '-o', '{{$DIR_0/$NAME_0.tex}}', '{{$FILEPATH_0}}'],
57 cd: '$ROOTDIR',
58 severity: 'error',
59 outputs: ['$DIR_0/$NAME_0.tex']
60 })
61
62 done()
63 })
64
65 it('returns correct arguments and command options for lagda file.', async (done) => {
66 const { rule } = await initialize({
67 parameters: [{ filePath: 'LiterateAgda.lagda' }],
68 options: { literateAgdaEngine: 'lhs2TeX' }
69 })
70
71 expect(rule.constructCommand()).toEqual({
72 args: ['lhs2TeX', '--agda', '-o', '{{$DIR_0/$NAME_0.tex}}', '{{$FILEPATH_0}}'],
73 cd: '$ROOTDIR',
74 severity: 'error',
75 outputs: ['$DIR_0/$NAME_0.tex']
76 })
77
78 done()
79 })
80
81 it('add --math to command line when lhs2texStyle is set to \'math\'.', async (done) => {
82 const { rule } = await initialize({
83 options: { lhs2texStyle: 'math' }
84 })
85
86 expect(rule.constructCommand().args).toContain('--math')
87
88 done()
89 })
90
91 it('add --newcode to command line when lhs2texStyle is set to \'newCode\'.', async (done) => {
92 const { rule } = await initialize({
93 options: { lhs2texStyle: 'newCode' }
94 })
95
96 expect(rule.constructCommand().args).toContain('--newcode')
97
98 done()
99 })
100
101 it('add --code to command line when lhs2texStyle is set to \'code\'.', async (done) => {
102 const { rule } = await initialize({
103 options: { lhs2texStyle: 'code' }
104 })
105
106 expect(rule.constructCommand().args).toContain('--code')
107
108 done()
109 })
110
111 it('add --tt to command line when lhs2texStyle is set to \'typewriter\'.', async (done) => {
112 const { rule } = await initialize({
113 options: { lhs2texStyle: 'typewriter' }
114 })
115
116 expect(rule.constructCommand().args).toContain('--tt')
117
118 done()
119 })
120
121 it('add --verb to command line when lhs2texStyle is set to \'verbatim\'.', async (done) => {
122 const { rule } = await initialize({
123 options: { lhs2texStyle: 'verbatim' }
124 })
125
126 expect(rule.constructCommand().args).toContain('--verb')
127
128 done()
129 })
130 })
131})