class SpreadsheetMarkdownIntegrationTests extends BaseTest {
parser;
setUp() {
this.parser = new Markdown([ ...Markdown.allReaders, new MDSpreadsheetReader() ]);
}
md(markdown) {
return normalizeWhitespace(this.parser.toHTML(markdown));
}
test_integration() {
const markdown = '| A | B | C |\n| --- | --- | --- |\n| 3 | 4 | =A*B |';
const expected = '
' +
'| A | B | C |
' +
'' +
'| 3 | ' +
'4 | ' +
'12 | ' +
'
';
const actual = this.md(markdown);
this.assertEqual(expected, actual);
}
test_bailOut() {
// If no formulas found table isn't modified
const markdown = '| A | B | C |\n| --- | --- | --- |\n| 3 | 4 | A*B |';
const expected = '' +
'| A | B | C |
' +
'' +
'| 3 | ' +
'4 | ' +
'A*B | ' +
'
';
const actual = this.md(markdown);
this.assertEqual(expected, actual);
}
test_observedError1() {
// Saw "Uncaught Error: columnIndex must be number, got string" from this
const markdown = '| Unit Price | Qty | Subtotal |\n| ---: | ---: | ---: |\n| $1.23 | 2 | =A*B FILL |\n| $4.99 | 6 | |\n| Total | | =SUM(C:C) |';
const expected = '' +
'| Unit Price | ' +
'Qty | ' +
'Subtotal | ' +
'
' +
'| $1.23 | ' +
'2 | ' +
'$2.46 | ' +
'
' +
'| $4.99 | ' +
'6 | ' +
'$29.94 | ' +
'
' +
'| Total | ' +
' | ' +
'$32.40 | ' +
'
';
const actual = this.md(markdown);
this.assertEqual(expected, actual);
}
test_observedError2() {
// A FILLed difference formula in row 2 of `=B2-B1` threw an exception
// due to a transposed address to the row above of `=B1-B0`.
const markdown = `| TB | Price | $/TB | Incr |
| --- | --- | --- | --- |
| 2 | $99.99 | =B/A FILL | |
| 4 | $186.41 | | =B2-B1 FILL |
| 6 | $209.99 | | |`;
const actual = this.md(markdown);
}
test_styledValue() {
const markdown = "| A | B | C |\n| --- | --- | --- |\n| **3** | _4_ | =A*B |";
const expected = '' +
'| A | B | C |
' +
'' +
'| 3 | ' +
'4 | ' +
'12 | ' +
'
';
const actual = this.md(markdown);
this.assertEqual(expected, actual);
}
test_styledFormula() {
const markdown = "| A | B | C |\n| --- | --- | --- |\n| 3 | 4 | **=A*B** |";
const expected = '' +
'| A | B | C |
' +
'' +
'| 3 | ' +
'4 | ' +
'12 | ' +
'
';
const actual = this.md(markdown);
this.assertEqual(expected, actual);
}
test_styledFormula_multiple() {
const markdown = "| A | B | C |\n| --- | --- | --- |\n| 3 | 4 | ~~**=A*B**~~ |";
const expected = '' +
'| A | B | C |
' +
'' +
'| 3 | ' +
'4 | ' +
'12 | ' +
'
';
const actual = this.md(markdown);
this.assertEqual(expected, actual);
}
test_preservedOperators() {
// Regular markdown will want to convert *B* into emphasized B
const markdown = "| A | B | C |\n| --- | --- | --- |\n| 3 | 4 | =A*B*4 |";
const expected = '' +
'| A | B | C |
' +
'' +
'| 3 | ' +
'4 | ' +
'48 | ' +
'
';
const actual = this.md(markdown);
this.assertEqual(expected, actual);
}
}