Skip to content

Commit

Permalink
test: fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tivie committed Dec 23, 2017
1 parent 13ba267 commit 173ad51
Show file tree
Hide file tree
Showing 28 changed files with 129 additions and 43 deletions.
8 changes: 8 additions & 0 deletions src/converter.js
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,9 @@ showdown.Converter = function (converterOptions) {
txt = node.outerHTML + '\n\n';
}

// common normalization


return txt;
}

Expand All @@ -500,6 +503,7 @@ showdown.Converter = function (converterOptions) {
// multiple spaces are collapsed
txt = txt.replace(/ +/g, ' ');

// replace the custom ¨NBSP; with a space
txt = txt.replace(/¨NBSP;/g, ' ');

// ", <, > and & should replace escaped html entities
Expand Down Expand Up @@ -723,6 +727,10 @@ showdown.Converter = function (converterOptions) {
txt += parseNode(children[i]);
}
}

// some text normalization
txt = txt.trim();

return txt;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
> ## This is a header.
>
>
> 1. This is the first list item.
> 2. This is the second list item.
>
>
> Here's some example code:
>
>
> ```
> return shell_exec("echo $input | $markdown_script");
> ```
2 changes: 1 addition & 1 deletion test/functional/makemarkdown/cases/standard/blockquote.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
> This is a multi line blockquote test
>
>
> With more than one line.
2 changes: 1 addition & 1 deletion test/functional/makemarkdown/cases/standard/escaping.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@
<p>but. this should not</p>
<p>. nor this</p>
<p>or this.</p>
<p> four ate the beginning of line are removed</p>
<p> 4 spaces at the beginning of line are removed</p>
<p>multiple spaces are colapsed to 1</p>
4 changes: 2 additions & 2 deletions test/functional/makemarkdown/cases/standard/escaping.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
\[a false reference]: must be escaped

\- a list item
\- a list item

\*

Expand Down Expand Up @@ -28,6 +28,6 @@ but. this should not

or this.

four ate the beginning of line are removed
4 spaces at the beginning of line are removed

multiple spaces are colapsed to 1
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<pre><code>function MyFunc(a) {
<pre><code>
function MyFunc(a) {
// ...
}
}
</code></pre>
<p>That is some code!</p>
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
```
function MyFunc(a) {
// ...
// ...
}
```

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
> Define a function in javascript:
>
>
> ```
> function MyFunc(a) {
> var s = '`';
> }
> ```
>
>
> > And some nested quote
> >
> >
> > ```html
> > <div>HTML!</div>
> > ```
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<p>Define a function in javascript:</p>
<pre><code>function MyFunc(a) {
var s = '`';
}
var s = '`';
}
</code></pre>
<p>And some HTML</p>
<pre><code class="html language-html">&lt;div&gt;HTML!&lt;/div&gt;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ And some HTML

```javascript
function foo() {
return 'bar';
return 'bar';
}
```
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<pre><code>code can go here
this is rendered on a second line
this is rendered on a second line
</code></pre>
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<hr />
<hr>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---

---
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<ul>
<li><p>Bird</p></li>
<li><p>Magic</p></li>
</ul>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
- Bird

- Magic
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<h1 id="sometitle">some title</h1>
<ol>
<li>list item 1</li>
<li>list item 2</li>
</ol>
<blockquote>
<p>some text in a blockquote</p>
</blockquote>
<ul>
<li>another list item 1</li>
<li>another list item 2</li>
</ul>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# some title

1. list item 1
2. list item 2

> some text in a blockquote
- another list item 1
- another list item 2
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<h1 id="sometitle">some title</h1>
<ol>
<li>list item 1</li>
<li>list item 2</li>
</ol>
<pre><code>some code

and some other line of code
</code></pre>
<ul>
<li>another list item 1</li>
<li>another list item 2</li>
</ul>
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# some title

1. list item 1
2. list item 2

```
some code
and some other line of code
```

- another list item 1
- another list item 2
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<ul>
<li><p>A list item with a blockquote:</p>
<blockquote>
<p>This is a blockquote
inside a list item.</p>
</blockquote></li>
</ul>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
- A list item with a blockquote:

> This is a blockquote inside a list item.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<ul>
<li><p>A list item with code:</p>
<pre><code>alert('Hello world!');
</code></pre></li>
</ul>
5 changes: 5 additions & 0 deletions test/functional/makemarkdown/cases/standard/list-with-code.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
- A list item with code:

```
alert('Hello world!');
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<ol>
<li><p>This is a major bullet point.</p>
<p>That contains multiple paragraphs.</p></li>
<li><p>And another line</p></li>
</ol>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
1. This is a major bullet point.

That contains multiple paragraphs.

2. And another line
6 changes: 3 additions & 3 deletions test/functional/makemarkdown/cases/standard/ordered-list.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
1. Red
2. Green
3. Blue
1. Red
2. Green
3. Blue
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
- foo
- foo

- bazinga

- yeah
- bar

- bar

1. damn

2. so many paragraphs
- baz

- baz
16 changes: 2 additions & 14 deletions test/functional/makemarkdown/makemarkdown.bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,21 +56,9 @@
testCase.expected = testCase.expected.replace(/(\r\n)|\n|\r/g, '\n');
testCase.actual = testCase.actual.replace(/(\r\n)|\n|\r/g, '\n');

// Ignore all leading/trailing whitespace
testCase.expected = testCase.expected.split('\n').map(function (x) {
return x.trim();
}).join('\n');
testCase.actual = testCase.actual.split('\n').map(function (x) {
return x.trim();
}).join('\n');

// Remove extra lines
testCase.expected = testCase.expected.trim();
testCase.actual = testCase.actual.trim();

// Normalize line returns
testCase.expected = testCase.expected.replace(/(\r\n)|\n|\r/g, '\n');
testCase.actual = testCase.actual.replace(/(\r\n)|\n|\r/g, '\n');
testCase.expected = testCase.expected.replace(/^\n+/, '').replace(/\n+$/, '');
testCase.actual = testCase.actual.replace(/^\n+/, '').replace(/\n+$/, '');

return testCase;
}
Expand Down

0 comments on commit 173ad51

Please sign in to comment.