Skip to content

Commit

Permalink
[unknown] Add docx tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Toliak committed Jul 18, 2023
1 parent 4b3084e commit 3d61adc
Show file tree
Hide file tree
Showing 10 changed files with 972 additions and 0 deletions.
1 change: 1 addition & 0 deletions printers/docx/test/full/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
out
9 changes: 9 additions & 0 deletions printers/docx/test/full/files/additional.mxd
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
## Additional file

Formula:

$$$math
y = bx + c
$$$

Image from main.mxd !PK[img].
5 changes: 5 additions & 0 deletions printers/docx/test/full/files/main.mxd
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Main file with content

Image here

![image-label](./nothing)(@h 4cm)(@n Image)
3 changes: 3 additions & 0 deletions printers/docx/test/full/files/unused.mxd
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## Hidden content

This content should not appear in the result file
104 changes: 104 additions & 0 deletions printers/docx/test/full/index.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
import { convertYaxmFiles, diagnostic } from '@md-to-latex/converter';
import * as fs from 'fs';
import * as path from 'path';
import yaml from 'js-yaml';
import { buildConfig, createPrinterDocx } from '../../src';

describe('convertMarkdownFiles', function () {
const fullDiagnosticList: diagnostic.DiagnoseList = [];

beforeAll(() => {
const convertResult = convertYaxmFiles({
rootDir: __dirname,
buildConfig: yaml.load(
fs.readFileSync(
path.join(__dirname, 'yaxm-build.yml'),
'utf-8',
),
) as any,
});
fullDiagnosticList.push(...convertResult.diagnostic);

const printer = createPrinterDocx(buildConfig());
convertResult.result.forEach(data => {
const result = printer.processNode(printer, data.fileNode);

const fullOutPath = path.join(__dirname, data.fileInfo.out);

fs.mkdirSync(path.dirname(fullOutPath), { recursive: true });
fs.writeFileSync(fullOutPath, result.result, 'utf-8');

fullDiagnosticList.push(...result.diagnostic);
});
});

const fileParameters = {
main: {
pathTex: path.join(__dirname, 'out', 'main.tex'),
pathMd: path.join(__dirname, 'files', 'main.tex'),
emitted: true,
},
another: {
pathTex: path.join(__dirname, 'out', 'another.tex'),
pathMd: path.join(__dirname, 'files', 'another.tex'),
emitted: true,
},
unused: {
pathTex: path.join(__dirname, 'out', 'unused.tex'),
pathMd: path.join(__dirname, 'files', 'unused.tex'),
emitted: false,
},
} as {
[Key: string]: {
pathTex: string;
pathMd: string;
emitted: boolean;
};
};

Object.entries(fileParameters).forEach(entry => {
const emitted = entry[1].emitted;
test(`File ${entry[0]} should${
emitted ? '' : ' not'
} be emitted`, () => {
if (emitted) {
expect(fs.existsSync(entry[1].pathTex)).toBeTruthy();
} else {
expect(fs.existsSync(entry[1].pathTex)).not.toBeTruthy();
}
});
});

test('main.tex correct content', () => {
const content = fs.readFileSync(fileParameters.main.pathTex, 'utf8');

expect(content).toContain(
'\\section{\\uppercase{Main file with content}}',
);
expect(content).toContain('\\setlength{\\belowcaptionskip}{-4ex}');
expect(content).not.toContain(
'\\addtolength{\\belowcaptionskip}{-1em}',
);
expect(content).toContain('\\begin{figure}[H]');
expect(content).toContain('\\includegraphics[height=4cm]{./nothing}');
expect(content).toContain('\\caption{Рисунок 1 -- Image}');
expect(content).toContain('\\begin{figure}[H]');
});

test('another.tex correct content', () => {
const content = fs.readFileSync(fileParameters.another.pathTex, 'utf8');

expect(content).toContain('\\subsection{Additional file}');
expect(content).toContain('Formula:');
expect(content).toContain('\\setlength{\\abovedisplayskip}{-0.9em}');
expect(content).toContain('\\setlength{\\belowdisplayskip}{0pt}');
expect(content).toContain('\\setlength{\\abovedisplayshortskip}{0pt}');
expect(content).toContain('\\setlength{\\belowdisplayshortskip}{0pt}');
});

test('another.tex correct link to image, defined in main.mxd', () => {
const content = fs.readFileSync(fileParameters.another.pathTex, 'utf8');

expect(content).toContain('Image from main.mxd 2');
});
});
5 changes: 5 additions & 0 deletions printers/docx/test/full/yaxm-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
files:
- path: files/main.mxd
out: out/main.tex
- path: files/additional.mxd
out: out/another.tex
249 changes: 249 additions & 0 deletions printers/docx/test/printer/__snapshots__/printer.spec.ts.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,249 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`simple md to latex docs printer Header + Image + Code + Image 1`] = `
Array [
Object {
"errorType": 2,
"filePath": "[PATH]",
"message": "Unused picture label img-1",
"pos": Object {
"end": Object {
"absolute": 65,
"column": 55,
"line": 4,
},
"start": Object {
"absolute": 11,
"column": 1,
"line": 4,
},
},
"severity": "WARNING",
},
Object {
"errorType": 2,
"filePath": "[PATH]",
"message": "Unused picture label code-1",
"pos": Object {
"end": Object {
"absolute": 144,
"column": 4,
"line": 9,
},
"start": Object {
"absolute": 67,
"column": 1,
"line": 6,
},
},
"severity": "WARNING",
},
Object {
"errorType": 2,
"filePath": "[PATH]",
"message": "Unused picture label img-2",
"pos": Object {
"end": Object {
"absolute": 202,
"column": 57,
"line": 11,
},
"start": Object {
"absolute": 146,
"column": 1,
"line": 11,
},
},
"severity": "WARNING",
},
Object {
"errorType": 4,
"filePath": "[PATH]",
"message": "Unable to print node with type 'Heading' (TODO)",
"pos": Object {
"end": Object {
"absolute": 9,
"column": 9,
"line": 2,
},
"start": Object {
"absolute": 1,
"column": 1,
"line": 2,
},
},
"severity": "WARNING",
},
Object {
"errorType": 4,
"filePath": "[PATH]",
"message": "Unable to print node with type 'PictureProcessed' (TODO)",
"pos": Object {
"end": Object {
"absolute": 65,
"column": 55,
"line": 4,
},
"start": Object {
"absolute": 11,
"column": 1,
"line": 4,
},
},
"severity": "WARNING",
},
Object {
"errorType": 4,
"filePath": "[PATH]",
"message": "Unable to print node with type 'CodeProcessed' (TODO)",
"pos": Object {
"end": Object {
"absolute": 144,
"column": 4,
"line": 9,
},
"start": Object {
"absolute": 67,
"column": 1,
"line": 6,
},
},
"severity": "WARNING",
},
Object {
"errorType": 4,
"filePath": "[PATH]",
"message": "Unable to print node with type 'PictureProcessed' (TODO)",
"pos": Object {
"end": Object {
"absolute": 202,
"column": 57,
"line": 11,
},
"start": Object {
"absolute": 146,
"column": 1,
"line": 11,
},
},
"severity": "WARNING",
},
]
`;

exports[`simple md to latex docs printer Header + Image + Code + Image 2`] = `
Array [
we {
"properties": pe {
"root": Array [],
"rootKey": "w:rPr",
},
"root": Array [
pe {
"root": Array [],
"rootKey": "w:rPr",
},
fe {
"root": Array [
V {
"root": Object {
"space": "preserve",
},
"rootKey": "_attr",
"xmlKeys": Object {
"space": "xml:space",
},
},
"[TODO 'Heading']",
],
"rootKey": "w:t",
},
],
"rootKey": "w:r",
},
we {
"properties": pe {
"root": Array [],
"rootKey": "w:rPr",
},
"root": Array [
pe {
"root": Array [],
"rootKey": "w:rPr",
},
fe {
"root": Array [
V {
"root": Object {
"space": "preserve",
},
"rootKey": "_attr",
"xmlKeys": Object {
"space": "xml:space",
},
},
"[TODO 'PictureProcessed']",
],
"rootKey": "w:t",
},
],
"rootKey": "w:r",
},
we {
"properties": pe {
"root": Array [],
"rootKey": "w:rPr",
},
"root": Array [
pe {
"root": Array [],
"rootKey": "w:rPr",
},
fe {
"root": Array [
V {
"root": Object {
"space": "preserve",
},
"rootKey": "_attr",
"xmlKeys": Object {
"space": "xml:space",
},
},
"[TODO 'CodeProcessed']",
],
"rootKey": "w:t",
},
],
"rootKey": "w:r",
},
we {
"properties": pe {
"root": Array [],
"rootKey": "w:rPr",
},
"root": Array [
pe {
"root": Array [],
"rootKey": "w:rPr",
},
fe {
"root": Array [
V {
"root": Object {
"space": "preserve",
},
"rootKey": "_attr",
"xmlKeys": Object {
"space": "xml:space",
},
},
"[TODO 'PictureProcessed']",
],
"rootKey": "w:t",
},
],
"rootKey": "w:r",
},
]
`;
Loading

0 comments on commit 3d61adc

Please sign in to comment.