0
0
mirror of https://github.com/naturalcrit/homebrewery.git synced 2025-12-24 18:32:41 +00:00

Update tests.

Prune no lionger valid cases.
This commit is contained in:
David Bolack
2024-02-06 22:13:44 -06:00
parent 703e207970
commit 3ee9fe1c3f
3 changed files with 36 additions and 49 deletions

View File

@@ -151,21 +151,21 @@ const Editor = createClass({
// definition lists
if(line.includes('::')){
// const regex = /^([^\n]*?)::([^\n]*)(?:\n|$)/ym;
const regex = /^([^\n:]*?)::(.*)(?:\n|$)/ym;
if(/^:*$/.test(line) == true){ return };
const regex = /^([^\n:]*?)(::[^\n]*)(?:\n|$)/ymd; // the `d` flag, for match indices, throws an ESLint error.
let match;
while ((match = regex.exec(line)) != null){
codeMirror.markText({ line: lineNumber, ch: line.indexOf(match[0]) }, { line: lineNumber, ch: line.indexOf(match[0]) + match[0].length }, { className: 'define' });
codeMirror.markText({ line: lineNumber, ch: line.indexOf(match[1]) }, { line: lineNumber, ch: line.indexOf(match[1]) + match[1].length }, { className: 'term' });
const matches = match[2].split('::').map((s)=>(s.trim()));
matches.forEach((m)=>{
codeMirror.markText({ line: lineNumber, ch: line.indexOf(m) }, { line: lineNumber, ch: line.indexOf(m) + m.length }, { className: 'definition' });
});
// codeMirror.markText({ line: lineNumber, ch: line.indexOf(match[2]) }, { line: lineNumber, ch: line.indexOf(match[2]) + match[2].length }, { className: 'definition' });
codeMirror.markText({ line: lineNumber, ch: match.indices[0][0] }, { line: lineNumber, ch: match.indices[0][1] }, { className: 'dl-highlight' });
codeMirror.markText({ line: lineNumber, ch: match.indices[1][0] }, { line: lineNumber, ch: match.indices[1][1] }, { className: 'dt-highlight' });
codeMirror.markText({ line: lineNumber, ch: match.indices[2][0] }, { line: lineNumber, ch: match.indices[2][1] }, { className: 'dd-highlight' });
const ddIndex = match.indices[2][0];
let colons = /::/g;
let colonMatches;
while((colonMatches = colons.exec(match[2])) !== null){
codeMirror.markText({ line: lineNumber, ch: colonMatches.index + ddIndex }, { line: lineNumber, ch: colonMatches.index + colonMatches[0].length + ddIndex }, { className: 'dl-colon-highlight'} )
}
}
}
// Superscript
if(line.includes('\^')) {
const regex = /\^(?!\s)(?=([^\n\^]*[^\s\^]))\1\^/g;

View File

@@ -55,6 +55,16 @@
vertical-align : sub;
font-size : 0.9em;
}
.dl-highlight {
&.dl-colon-highlight {
font-weight : bold;
color : #949494;
background : #E5E5E5;
border-radius : 3px;
}
&.dt-highlight { color : rgb(96, 117, 143); }
&.dd-highlight { color : rgb(97, 57, 178); }
}
}
.brewJump {

View File

@@ -6,49 +6,13 @@ describe('Dictionary Terms', ()=>{
test('Single Definition', function() {
const source = 'My term :: My First Definition\n\n';
const rendered = Markdown.render(source);
expect(rendered, `Input:\n${source}`, { showPrefix: false }).toBe('<dl><dt>My term</dt><dd>My First Definition</dd></dl>');
});
test('Two Definitions', function() {
const source = 'My term :: My First Definition :: My Second Definition\n\n';
const rendered = Markdown.render(source);
expect(rendered, `Input:\n${source}`, { showPrefix: false }).toBe('<dl><dt>My term</dt><dd>My First Definition</dd><dd>My Second Definition</dd></dl>');
});
test('Three Definitions', function() {
const source = 'My term :: My First Definition :: My Second Definition :: My Third Definition\n\n';
const rendered = Markdown.render(source);
expect(rendered, `Input:\n${source}`, { showPrefix: false }).toBe('<dl><dt>My term</dt><dd>My First Definition</dd><dd>My Second Definition</dd><dd>My Third Definition</dd></dl>');
});
test('Multiline Definitions', function() {
const source = '**Example** :: V3 uses HTML *definition lists* to create "lists" with hanging indents.\n::Two\n::Three\n::Four\n\n';
const rendered = Markdown.render(source);
expect(rendered, `Input:\n${source}`, { showPrefix: false }).toBe('<dl><dt><strong>Example</strong></dt>\n<dd>V3 uses HTML <em>definition lists</em> to create “lists” with hanging indents.</dd>\n<dd>Two</dd>\n<dd>Three</dd>\n<dd>Four</dd></dl>');
expect(rendered, `Input:\n${source}`, { showPrefix: false }).toBe('<dl class="inlineDL"><dt>My term</dt><dd>My First Definition</dd></dl>');
});
test('Multiple Definition Terms, single line, single definition', function() {
const source = 'Term 1::Definition of Term 1\nTerm 2::Definition of Term 2\n\n';
const rendered = Markdown.render(source);
expect(rendered, `Input:\n${source}`, { showPrefix: false }).toBe('<dl><dt>Term 1</dt><dd>Definition of Term 1</dd>\n<dt>Term 2</dt><dd>Definition of Term 2</dd></dl>');
});
test('Multiple Definition Terms, single line, multiple definitions', function() {
const source = 'Term 1::Definition 1 of Term 1::Definition 2 of Term 1\nTerm 2::Definition 1 of Term 2::Definition 2 of Term 2\n\n';
const rendered = Markdown.render(source);
expect(rendered, `Input:\n${source}`, { showPrefix: false }).toBe('<dl><dt>Term 1</dt><dd>Definition 1 of Term 1</dd><dd>Definition 2 of Term 1</dd>\n<dt>Term 2</dt><dd>Definition 1 of Term 2</dd><dd>Definition 2 of Term 2</dd></dl>');
});
test('Multiple Definition Terms, single definitions, multiple lines', function() {
const source = 'Term 1::Definition 1 of Term 1\n::Definition 2 of Term 1\nTerm 2::Definition of Term 2\n\n';
const rendered = Markdown.render(source);
expect(rendered, `Input:\n${source}`, { showPrefix: false }).toBe('<dl><dt>Term 1</dt>\n<dd>Definition 1 of Term 1</dd>\n<dd>Definition 2 of Term 1</dd>\n<dt>Term 2</dt><dd>Definition of Term 2</dd></dl>');
});
test('Multiple Definition Terms, multiple mixed-line definitions', function() {
const source = 'Term 1::Definition 1 of Term 1\n::Definition 2 of Term 1::Definition 3 of Term 1\nTerm 2::Definition of Term 2\n\n';
const rendered = Markdown.render(source);
expect(rendered, `Input:\n${source}`, { showPrefix: false }).toBe('<dl><dt>Term 1</dt>\n<dd>Definition 1 of Term 1</dd>\n<dd>Definition 2 of Term 1</dd><dd>Definition 3 of Term 1</dd>\n<dt>Term 2</dt><dd>Definition of Term 2</dd></dl>');
expect(rendered, `Input:\n${source}`, { showPrefix: false }).toBe('<dl class="inlineDL"><dt>Term 1</dt><dd>Definition of Term 1</dd>\n<dt>Term 2</dt><dd>Definition of Term 2</dd></dl>');
});
test('PANdoc style list - Single Term, Single Definition', function() {
@@ -75,5 +39,18 @@ describe('Dictionary Terms', ()=>{
expect(rendered, `Input:\n${source}`, { showPrefix: false }).toBe('<dl><dt>Term 1</dt>\n<dd>Definition 1</dd>\n<dd>Definition 2</dd>\n<dt>Term 2</dt>\n<dd>Definition 1</dd>\n<dd>Definition 2</dd></dl>');
});
test('PANdoc style list - Single Term, Single multiple line definition', function() {
const source = 'Term 1\n::Definition 1\nand more and\nmore and more\n\n';
const rendered = Markdown.render(source);
expect(rendered, `Input:\n${source}`, { showPrefix: false }).toBe('<dl><dt>Term 1</dt><dd>Definition 1 and more and more and more</dd></dl>');
});
test('PANdoc style list - Multiple Term, Single multiple line definition', function() {
const source = 'Term 1\n::Definition 1\nand more and\nmore and more\n\n::Definition 2\n\n::Definition 3\n\n';
const rendered = Markdown.render(source);
expect(rendered, `Input:\n${source}`, { showPrefix: false }).toBe('<dl><dt>Term 1</dt>\n<dd>Definition 1 and more and more and more</dd>\n<dd>Definition 2</dd>\n<dd>Definition 3</dd></dl>');
});
});