From 59bcdc78cf230212a46a5c5fcfefd7ff00421d3d Mon Sep 17 00:00:00 2001
From: tatsy <tatsy.mail@gmail.com>
Date: Sat, 7 Feb 2015 18:21:18 +0900
Subject: [PATCH] Add unit tests for improve code coverage.
---
helpers/parse_image_size.js | 2 +-
index.js | 16 ++++++++--------
test/fixtures/imsize.txt | 20 ++++++++++++++++++++
3 files changed, 29 insertions(+), 9 deletions(-)
diff --git a/helpers/parse_image_size.js b/helpers/parse_image_size.js
index 3b1fc2f..16e3f02 100644
--- a/helpers/parse_image_size.js
+++ b/helpers/parse_image_size.js
@@ -46,7 +46,7 @@ module.exports = function parseImageSize(str, pos, max) {
// (2) =300x
// (3) =x200
code = str.charCodeAt(pos);
- if (code !== 0x78 /* x */ && (code < 0x30 && code > 0x39) /* [0-9] */) {
+ if (code !== 0x78 /* x */ && (code < 0x30 || code > 0x39) /* [0-9] */) {
return result;
}
diff --git a/index.js b/index.js
index 5eb9a11..2254e70 100644
--- a/index.js
+++ b/index.js
@@ -41,7 +41,7 @@ function image_with_size(md) {
//
// [link]( <href> "title" )
- // ^^ skipping these spaces
+ // ^^ skipping these spaces
pos++;
for (; pos < max; pos++) {
code = state.src.charCodeAt(pos);
@@ -50,7 +50,7 @@ function image_with_size(md) {
if (pos >= max) { return false; }
// [link]( <href> "title" )
- // ^^^^^^ parsing link destination
+ // ^^^^^^ parsing link destination
start = pos;
res = md.helpers.parseLinkDestination(state.src, pos, state.posMax);
if (res.ok && state.md.inline.validateLink(res.str)) {
@@ -61,7 +61,7 @@ function image_with_size(md) {
}
// [link]( <href> "title" )
- // ^^ skipping these spaces
+ // ^^ skipping these spaces
start = pos;
for (; pos < max; pos++) {
code = state.src.charCodeAt(pos);
@@ -69,14 +69,14 @@ function image_with_size(md) {
}
// [link]( <href> "title" )
- // ^^^^^^^ parsing link title
+ // ^^^^^^^ parsing link title
res = md.helpers.parseLinkTitle(state.src, pos, state.posMax);
if (pos < max && start !== pos && res.ok) {
title = res.str;
pos = res.pos;
// [link]( <href> "title" )
- // ^^ skipping these spaces
+ // ^^ skipping these spaces
for (; pos < max; pos++) {
code = state.src.charCodeAt(pos);
if (code !== 0x20 && code !== 0x0A) { break; }
@@ -86,7 +86,7 @@ function image_with_size(md) {
}
// [link]( <href> "title" =WxH )
- // ^^^^ parsing image size
+ // ^^^^ parsing image size
if (pos - 1 >= 0) {
code = state.src.charCodeAt(pos - 1);
@@ -100,7 +100,7 @@ function image_with_size(md) {
pos = res.pos;
// [link]( <href> "title" =WxH )
- // ^^ skipping these spaces
+ // ^^ skipping these spaces
for (; pos < max; pos++) {
code = state.src.charCodeAt(pos);
if (code !== 0x20 && code !== 0x0A) { break; }
@@ -122,7 +122,7 @@ function image_with_size(md) {
if (typeof state.env.references === 'undefined') { return false; }
// [foo] [bar]
- // ^^ optional whitespace (can include newlines)
+ // ^^ optional whitespace (can include newlines)
for (; pos < max; pos++) {
code = state.src.charCodeAt(pos);
if (code !== 0x20 && code !== 0x0A) { break; }
diff --git a/test/fixtures/imsize.txt b/test/fixtures/imsize.txt
index 06c9b99..ff83718 100644
--- a/test/fixtures/imsize.txt
+++ b/test/fixtures/imsize.txt
@@ -258,6 +258,26 @@ Coverage. Image
.
<p></p>
.
+.
+
+.
+<p></p>
+.
+.
+
+.
+<p><img src="http://this.is.test.jpg" alt="test" width="100" height="200"></p>
+.
+.
+
+.
+<p></p>
+.
+.
+
+.
+<p><img src="x" alt="test" width="100" height="200"></p>
+.
Coverage. Link
.
--
GitLab