Skip to content

Commit 0c79827

Browse files
committed
add dynamic test cases for rendering
1 parent e27138c commit 0c79827

File tree

11 files changed

+50
-5
lines changed

11 files changed

+50
-5
lines changed

src/test/markupParser.test.ts

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,21 @@ import * as path from 'path';
66
import { parseMarkup, cssUri } from '../markupParser';
77
import * as fs from 'fs';
88

9+
const TEST_FILES_ROOT = path.join(__dirname, "../../src/test/testfiles");
10+
const FIXTURES_ROOT = path.join(__dirname, "../../src/test/resources/fixtures");
11+
12+
function walkdirSync(dir: string): string[] {
13+
return fs.readdirSync(dir).reduce(function (result: string[], file) {
14+
let name = path.join(dir, file);
15+
let isDir = fs.statSync(name).isDirectory();
16+
return result.concat(isDir ? walkdirSync(name) : [name]);
17+
}, []);
18+
}
19+
20+
function isConfluence(element: string, index: number, array: string[]): boolean {
21+
return (element.endsWith(".confluence"));
22+
}
23+
924
// Defines a Mocha test suite to group tests of similar kind together
1025
suite("markupParser Tests", function () {
1126

@@ -20,10 +35,26 @@ suite("markupParser Tests", function () {
2035
}
2136
});
2237

23-
test("Test render headers", function () {
24-
const testFile = vscode.Uri.file(path.join(__dirname, "../../src/test/testfiles/nix/scoped/headings.confluence"));
25-
const expected = '<p><h1>Heading 1</h1></p><p><h2>Heading 2</h2></p><p><h3>Heading 3</h3></p><p><h4>Heading 4</h4></p><p><h5>Heading 5</h5></p><p><h6>Heading 6</h6></p>'
26-
const content = fs.readFileSync(testFile.fsPath, 'utf8');
27-
assert.equal(parseMarkup(testFile, content), expected);
38+
walkdirSync(TEST_FILES_ROOT).filter(isConfluence).forEach(fullFilePath => {
39+
const fileName = path.basename(fullFilePath);
40+
const dirName = path.dirname(fullFilePath);
41+
42+
let typeDir = path.basename(dirName);
43+
let scopedDir = ''
44+
if (dirName.endsWith('scoped')) {
45+
scopedDir = path.basename(dirName);
46+
typeDir = path.basename(path.dirname(dirName));
47+
}
48+
49+
const testName = "Render testfile: " + path.join(typeDir, scopedDir, fileName)
50+
test(testName, function () {
51+
const fixtureFile = path.join(FIXTURES_ROOT, scopedDir, fileName.replace('confluence', 'html'));
52+
const fixtureContent = fs.readFileSync(fixtureFile, 'utf8');
53+
54+
const testFileUri = vscode.Uri.file(fullFilePath);
55+
const confluenceContent = fs.readFileSync(testFileUri.fsPath, 'utf8');
56+
57+
assert.equal(parseMarkup(testFileUri, confluenceContent), fixtureContent);
58+
});
2859
});
2960
});
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<p><h1>TITLE</h1></p><p><h2>Section One</h2></p><p>Section one.</p><p><h2>Section Two</h2></p><p>Section two.</p><p><ol class="initial"><li>Numbered List 1</li></p><p><li>Numbered List 2</li></p><p></ol></p><p><h2>Section Three</h2></p><p>Section three.</p><p><h2>Section Four</h2></p><p>Section four.</p>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<p><h1><strong>Issues</strong></h1></p><p><a href='https://github.com/denco/vscode-confluence-markup/issues/3'>#3</a>: Noformat macro</p><p><pre><code style='font-family: Menlo, Monaco, Consolas, monospace'></p><p>$ date -R -v+1d<br /></p><p>Sat, 10 Feb 2018 10:37:39 +0100<br /></p><p></pre></code></p><p><a href='https://github.com/denco/vscode-confluence-markup/issues/5'>#5</a>: Table without heading</p><p><h4>Table without heading</h4></p><p><tr><table><td>test</td><td>test</td></tr></p><p><tr><td>simple table</td><td>two</td></tr></p><p></table></p><p><a href='https://github.com/denco/vscode-confluence-markup/issues/6'>#6</a>: Intenting</p><p><h4>Header Four</h4></p><p><ul class="alternate"><li>list one</li></p><p><li>list two</li></p><p><li>list three</li></p><p></ul></p><p><h4>next header (should not be indented)</h4></p><p><ul><li>list</li></p><p><li>list two</li></p><p></ul></p><p><h3>third header</h3></p><p><ul class="alternate"><li>one</li></p><p><li>two</li></p><p></ul></p><p><a href='https://github.com/denco/vscode-confluence-markup/issues/7'>#7</a>: Nested lists</p><p><ul><li>el. 1</li></p><p><ul><li>el. 1.2.</li></p><p><li>el. 1.3.</li></p><p><ul><li>el. 1.3.1</li></p><p></ul></ul><li>el. 2</li></p><p></ul></p><p><ul class="alternate"><li>el. 1</li></p><p><ul class="alternate"><li>el. 1.2.</li></p><p><li>el. 1.3.</li></p><p><ul class="alternate"><li>el. 1.3.1</li></p><p></ul></ul><li>el. 2</li></p><p></ul></p><p><ol class="initial"><li>el. 1</li></p><p><ol><li>el. 1.2.</li></p><p><li>el. 1.3.</li></p><p><ol><li>el. 1.3.1</li></p><p></ol></ol><li>el. 2</li></p><p></ol></p><p><a href='https://github.com/denco/vscode-confluence-markup/issues/8'>#8</a>:</p><p>Dublicate of <a href='https://github.com/denco/vscode-confluence-markup/issues/5'>#5</a></p>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<p><span style='color:red;'>look ma, red text!</span></p><p><span style='color:blue;'>look ma, blue text!</span></p><p><span style='color:green;'>look ma, green text!</span></p>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<p><h1>Heading 1</h1></p><p><h2>Heading 2</h2></p><p><h3>Heading 3</h3></p><p><h4>Heading 4</h4></p><p><h5>Heading 5</h5></p><p><h6>Heading 6</h6></p>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<p><h1>cats</h1></p><p><ul class="alternate"><li><strong>coding cat</strong></li></p><p><img src="https://media.giphy.com/media/JIX9t2j0ZTN9S/giphy.gif"/></p><p></ul></p><p><ul class="alternate"><li><strong>compiling cat</strong></li></p><p><img src="https://media.giphy.com/media/mlvseq9yvZhba/giphy.gif"/></p><p></ul></p>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<p><h1>Lists</h1></p><p><h2>Ordered</h2></p><p><h3>Simple</h3></p><p><ol class="initial"><li>one</li></p><p><li>two</li></p><p><li>three</li></p><p><li>four</li></p><p></ol></p><p><h3>Nested</h3></p><p><ol class="initial"><li>one</li></p><p><li>two</li></p><p><ol><li>nested one</li></p><p><li>nested two</li></p><p><li>nested three</li></p><p><ol><li>sub sub</li></p><p><li>sub sub</li></p><p><ol class="initial"><li>sub s4</li></p><p><ol><li>sub s5</li></p><p><ol><li>sub s6</li></p><p><ol class="initial"><li>sub s7</li></p><p></ol></ol></ol></ol></ol></ol><li>three</li></p><p></ol></p><p><h2>Unordered</h2></p><p><h3>Simple</h3></p><p><h4>"squared"</h4></p><p><ul class="alternate"><li>one</li></p><p><li>two</li></p><p><li>three</li></p><p><li>four</li></p><p></ul></p><p><h4>"dotted"</h4></p><p><ul><li>one</li></p><p><li>two</li></p><p><li>three</li></p><p><li>four</li></p><p></ul></p><p><h3>Nested</h3></p><p><h4>"squared"</h4></p><p><ul class="alternate"><li>one</li></p><p><li>two</li></p><p><ul class="alternate"><li>nested one</li></p><p><li>nested two</li></p><p><li>nested three</li></p><p><ul class="alternate"><li>sub sub</li></p><p><li>sub sub</li></p><p><ul class="alternate"><li>sub s4</li></p><p><ul class="alternate"><li>sub s5</li></p><p><ul class="alternate"><li>sub s6</li></p><p><ul class="alternate"><li>sub s7</li></p><p></ul></ul></ul></ul></ul></ul><li>three</li></p><p></ul></p><p><h4>"dotted"</h4></p><p><ul><li>one</li></p><p><li>two</li></p><p><ul><li>nested one</li></p><p><li>nested two</li></p><p><li>nested three</li></p><p><ul><li>sub sub</li></p><p><li>sub sub</li></p><p><ul><li>sub s4</li></p><p><ul><li>sub s5</li></p><p><ul><li>sub s6</li></p><p><ul><li>sub s7</li></p><p></ul></ul></ul></ul></ul></ul><li>three</li></p><p></ul></p><p><h2>Mixed</h2></p><p><h3>Nested</h3></p><p><ol class="initial"><li>one</li></p><p><li>two</li></p><p><ul class="alternate"><li>nested one</li></p><p><li>nested two</li></p><p><li>nested three</li></p><p><ol class="initial"><li>sub sub</li></p><p><li>sub sub</li></p><p><ul class="alternate"><li>sub s4</li></p><p><ol><li>sub s5.1</li></p><p><li>sub s5.2</li></p><p><ul class="alternate"><li>sub s6</li></p><p><ol><li>sub s7.1</li></p><p><li>sub s7.2</li></p><p></ol></ul></ol></ul></ol></ul><li>three</li></p><p></ol></p>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<p><h1>Tables</h1></p><p><h2>Column heading</h2></p><p><tr><table><th>header c1</th><th>header c2</th></tr></p><p><tr><td>data 1.1</td><td>data 1.2</td></tr></p><p><tr><td>data 2.1</td><td>data 2.2</td></tr></p><p></table></p><p><h2>Row heading</h2></p><p><tr><table><th>header r1</td><td>data 1.1</td><td>data 1.2</tr></p><p><tr><th>header r2</td><td>data 2.1</td><td>data 2.2</tr></p><p><tr><th>header r3</td><td>data 3.1</td><td>data 3.2</tr></p><p></table></p><p><h2>Column and row heading</h2></p><p><tr><table><th> </th><th>header c1</th><th>header c2</tr></p><p><tr><th>header r1</td><td>data 1.1</td><td>data 1.2</td></tr></p><p><tr><th>header r2</td><td>data 2.1</td><td>data 2.2</td></tr></p><p></table></p><p><h2>Without heading</h2></p><p><tr><table><td>data 1.1</td><td>data 1.2</td></tr></p><p><tr><td>data 2.1</td><td>data 2.2</td></tr></p><p></table></p><p><h2>Table with nested macros (not supported yet)</h2></p><p><tr><table><th>Heading 1</th><th>Heading 2</th></tr></p><p><tr><td><strong> Item 1<br/></strong> Item 2<br/>* Item 3</td><td># Item 1 <br/># Item 2<br/># Item 3</td></tr></p>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<p><h1><strong>Examples</strong></h1></p><p><hr /></p><p><h2><strong>headers:</strong></h2></p><p><h1>Header 1</h1></p><p><h2>Header 2</h2></p><p><h3>Header 3</h3></p><p><h4>Header 4</h4></p><p><h5>Header 5</h5></p><p><h6>Header 6</h6></p><p><hr /></p><p><h2><strong>emoticons:</strong></h2></p><p><ul><li><img alt="(smile)" src="vscode-resource:/home/denco/projects/private/vscode/confluence-markup/media/emoticons/smile.png"/> smile</li></p><p><li><img alt="(sad)" src="vscode-resource:/home/denco/projects/private/vscode/confluence-markup/media/emoticons/sad.png"/> sad</li></p><p><li><img alt="(cheeky)" src="vscode-resource:/home/denco/projects/private/vscode/confluence-markup/media/emoticons/cheeky.png"/> cheeky</li></p><p><li><img alt="(laugh)" src="vscode-resource:/home/denco/projects/private/vscode/confluence-markup/media/emoticons/biggrin.png"/> laugh</li></p><p><li><img alt="(wink)" src="vscode-resource:/home/denco/projects/private/vscode/confluence-markup/media/emoticons/wink.png"/> wink</li></p><p><li><img alt="(thumbs-up)" src="vscode-resource:/home/denco/projects/private/vscode/confluence-markup/media/emoticons/thumbs-up.png"/> thumbs-up</li></p><p><li><img alt="(thumbs-down)" src="vscode-resource:/home/denco/projects/private/vscode/confluence-markup/media/emoticons/thumbs-down.png"/> thumbs-down</li></p><p><li><img alt="(information)" src="vscode-resource:/home/denco/projects/private/vscode/confluence-markup/media/emoticons/information.png"/> information</li></p><p><li><img alt="(tick)" src="vscode-resource:/home/denco/projects/private/vscode/confluence-markup/media/emoticons/tick.png"/> tick</li></p><p><li><img alt="(cross)" src="vscode-resource:/home/denco/projects/private/vscode/confluence-markup/media/emoticons/cross.png"/> cross</li></p><p><li><img alt="(warning)" src="vscode-resource:/home/denco/projects/private/vscode/confluence-markup/media/emoticons/warning.png"/> warning</li></p><p></ul></p><p><hr /></p><p><h2><strong>Links:</strong></h2></p><p><ul><li><a href='https://confluence.atlassian.com/doc/confluence-wiki-markup-251003035.html#ConfluenceWikiMarkup-Headings'>Mark Up</a></li></p><p><li><a href='https://confluence.atlassian.com/doc/confluence-storage-format-790796544.html'>Storage Format</a></li></p><p><li><a href='https://www.w3schools.com/html/html_formatting.asp'>html format</a></li></p><p><li><a href='https://ifl2014.github.io/submissions/ifl2014_submission_18.pdf'>test</a></li></p><p></ul></p><p><hr /></p><p><h2><strong>text effects:</strong></h2></p><p><strong>strong</strong></p><p><strong>bold text</strong></p><p><i>emphasis</i></p><p><i>italics</i> : Thing<i>x</i></p><p><i>italics with spaces</i></p><p><cite>citation</cite> <br/></p><p><span style='text-decoration: line-through;'>deleted</span> <br/></p><p><span style='text-decoration: line-through;'>deleted with spaces</span> <br/></p><p><u>inserted</u> <br/></p><p>Text with <sup>superscript</sup> : kg/m<sup>3</sup></p><p>Text with <sub>subscript</sub></p><p><code style='font-family: Menlo, Monaco, Consolas, monospace'>monospaced</code></p><p><blockquote><p>Here's how you make a paragraph appear as a block quotation.</p></blockquote></p><p><span style='color:red;'>look ma, red text!</span></p><p><hr /></p><p><h2><strong>lists:</strong></h2></p><p>Squared list</p><p><ul class="alternate"><li>one</li></p><p><li>two</li></p><p></ul></p><p>Dotted list</p><p><ul><li>one</li></p><p><li>tree</li></p><p><li>third</li></p><p></ul></p><p>Numbered list</p><p><ol class="initial"><li>one</li></p><p><ul><li>borderStyle</li></p><p><li>dasddasd</li></p><p></ul><li>two</li></p><p><li><img alt="(smile)" src="vscode-resource:/home/denco/projects/private/vscode/confluence-markup/media/emoticons/smile.png"/></li></p><p></ol></p><p><hr /></p><p><h2><strong>table:</strong></h2></p><p><tr><table><th>heading 1</th><th>heading 2</th><th>heading 3</th></tr></p><p><tr><td>cell A1</td><td>cell A2</td><td>cell A3</td></tr></p><p><tr><td>cell B1</td><td>cell B2</td><td>cell B3</td></tr></p><p></table></p><p><hr /></p><p><h2><strong>code:</strong></h2></p><p></table><pre><code style='font-family: Menlo, Monaco, Consolas, monospace'></p><p>&lt;test><br /></p><p> &lt;test1 /><br /></p><p>&lt;/test><br /></p><p></pre></code></p><p></table><pre><code style='font-family: Menlo, Monaco, Consolas, monospace'></p><p>bash<br /></p><p></pre></code></p><p><pre><code style='font-family: Menlo, Monaco, Consolas, monospace'>code oneline</code></pre></p><p><hr /></p><p><h2><strong>noformat:</strong></h2></p><p><pre><code style='font-family: Menlo, Monaco, Consolas, monospace'></p><p>&lt;xml><br /></p><p>&lt;/xml><br /></p><p></pre></code></p><p><pre><code style='font-family: Menlo, Monaco, Consolas, monospace'>noformat &lt;tag>&lt;/tag> oneline</code></pre></p>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{color:red}look ma, red text!{color}
2+
{color:blue}look ma, blue text!{color}
3+
{color:green}look ma, green text!{color}

0 commit comments

Comments
 (0)