Commit 64cf4ed9 authored by Roy Revelt's avatar Roy Revelt

test: split tests into separate files

parent 1b9640f5
......@@ -40,6 +40,7 @@
"1.4.42": 23710.915203650064,
"1.4.43": 3841.7298656887588,
"1.4.44": 2553.207433569914,
"lastPublished": 2553.207433569914,
"lastRan": 2553.207433569914
"1.4.50": 10019.98430133594,
"lastPublished": 10019.98430133594,
"lastRan": 10019.98430133594
}
\ No newline at end of file
import tap from "tap";
import alt from "../dist/html-img-alt.esm";
// adds ALT
// -----------------------------------------------------------------------------
tap.test("01 - normalising all attributes on IMG, adding ALT", (t) => {
t.same(
alt('z<img a="zz" >z'),
'z<img a="zz" alt="" >z',
"01 - html simples"
);
t.end();
});
tap.test("02 - normalising all attributes on IMG, adding ALT", (t) => {
t.same(
alt('z<img a="zz" />z'),
'z<img a="zz" alt="" />z',
"02 - xhtml simples"
);
t.end();
});
tap.test("03 - normalising all attributes on IMG, adding ALT", (t) => {
t.same(
alt('z<img a="zz" / >z'),
'z<img a="zz" alt="" />z',
"03 - xhtml simples"
);
t.end();
});
tap.test("04 - normalising all attributes on IMG, adding ALT", (t) => {
t.same(
alt('z<img a="zz"/ >z'),
'z<img a="zz" alt="" />z',
"04 - xhtml simples"
);
t.end();
});
tap.test("05 - normalising all attributes on IMG, adding ALT", (t) => {
t.same(
alt(
'zzz<img whatever="sjldldljg; slhljdfg" also="sdfkdh:232423 ; kgkd: 1223678638" >zzz'
),
'zzz<img whatever="sjldldljg; slhljdfg" also="sdfkdh:232423 ; kgkd: 1223678638" alt="" >zzz',
"05 - html advanced"
);
t.end();
});
tap.test("06 - normalising all attributes on IMG, adding ALT", (t) => {
t.same(
alt(
'zzz<img whatever="sjldldljg; slhljdfg" also="sdfkdh:232423 ; kgkd: 1223678638" />zzz'
),
'zzz<img whatever="sjldldljg; slhljdfg" also="sdfkdh:232423 ; kgkd: 1223678638" alt="" />zzz',
"06 - xhtml advanced"
);
t.end();
});
import tap from "tap";
import alt from "../dist/html-img-alt.esm";
// alt attr is missing
// -----------------------------------------------------------------------------
tap.test("01 - missing alt", (t) => {
t.same(alt("zzz<img>zzz"), 'zzz<img alt="" >zzz', "01 - html - tight");
t.end();
});
tap.test("02 - missing alt", (t) => {
t.same(
alt("zzz<img >zzz"),
'zzz<img alt="" >zzz',
"02 - html - trailing space"
);
t.end();
});
tap.test("03 - missing alt", (t) => {
t.same(
alt("zzz<img >zzz"),
'zzz<img alt="" >zzz',
"03 - html - excessive trailing space"
);
t.end();
});
tap.test("04 - missing alt", (t) => {
t.same(alt("zzz<img/>zzz"), 'zzz<img alt="" />zzz', "04 - xhtml - tight");
t.end();
});
tap.test("05 - missing alt", (t) => {
t.same(
alt("zzz<img />zzz"),
'zzz<img alt="" />zzz',
"05 - xhtml - one space before slash"
);
t.end();
});
tap.test("06 - missing alt", (t) => {
t.same(
alt("zzz<img />zzz"),
'zzz<img alt="" />zzz',
"06 - xhtml - many spaces before slash"
);
t.end();
});
tap.test("07 - missing alt", (t) => {
t.same(
alt("zzz<img / >zzz"),
'zzz<img alt="" />zzz',
"07 - xhtml - many spaces on both sides"
);
t.end();
});
import tap from "tap";
import alt from "../dist/html-img-alt.esm";
// alt attr is present, but without equal and double quotes.
// -----------------------------------------------------------------------------
tap.test("01 - alt without equal", (t) => {
t.same(alt("zzz<img alt>zzz"), 'zzz<img alt="" >zzz', "01 - html - tight");
t.end();
});
tap.test("02 - alt without equal", (t) => {
t.same(
alt("zzz<img alt>zzz"),
'zzz<img alt="" >zzz',
"02 - html - excessive white space"
);
t.end();
});
tap.test("03 - alt without equal", (t) => {
t.same(
alt("zzz<img alt >zzz"),
'zzz<img alt="" >zzz',
"03 - html - one trailing space"
);
t.end();
});
tap.test("04 - alt without equal", (t) => {
t.same(
alt("zzz<img alt >zzz"),
'zzz<img alt="" >zzz',
"04 - html - excessive white space on both sides"
);
t.end();
});
tap.test("05 - alt without equal", (t) => {
t.same(alt("zzz<img alt/>zzz"), 'zzz<img alt="" />zzz', "05 - xhtml - tight");
t.end();
});
tap.test("06 - alt without equal", (t) => {
t.same(
alt("zzz<img alt />zzz"),
'zzz<img alt="" />zzz',
"06 - xhtml - single space on both sides"
);
t.end();
});
tap.test("07 - alt without equal", (t) => {
t.same(
alt("zzz<img alt />zzz"),
'zzz<img alt="" />zzz',
"07 - xhtml - excessive white space on both sides"
);
t.end();
});
tap.test("08 - alt without equal", (t) => {
t.same(
alt("zzz<img alt / >zzz"),
'zzz<img alt="" />zzz',
"08 - xhtml - excessive white space everywhere"
);
t.end();
});
import tap from "tap";
import alt from "../dist/html-img-alt.esm";
// alt attr is present, but with only equal character
// -----------------------------------------------------------------------------
tap.test("01 - alt with just equal", (t) => {
t.same(
alt("zzz<img alt=>zzz"),
'zzz<img alt="" >zzz',
"01 - html, no space after"
);
t.end();
});
tap.test("02 - alt with just equal", (t) => {
t.same(
alt("zzz<img alt=>zzz<img alt=>zzz"),
'zzz<img alt="" >zzz<img alt="" >zzz',
"02 - html, two imag tags, no space after each"
);
t.end();
});
tap.test("03 - alt with just equal", (t) => {
t.same(
alt("zzz<img alt= >zzz"),
'zzz<img alt="" >zzz',
"03 - html, space after"
);
t.end();
});
tap.test("04 - alt with just equal", (t) => {
t.same(
alt("zzz<img alt=>zzz"),
'zzz<img alt="" >zzz',
"04 - html, excessive space in front"
);
t.end();
});
tap.test("05 - alt with just equal", (t) => {
t.same(
alt("zzz<img alt= >zzz"),
'zzz<img alt="" >zzz',
"05 - html, excessive space after"
);
t.end();
});
tap.test("06 - alt with just equal", (t) => {
t.same(
alt("zzz<img alt=/>zzz"),
'zzz<img alt="" />zzz',
"06 - xhtml, no space after"
);
t.end();
});
tap.test("07 - alt with just equal", (t) => {
t.same(
alt("zzz<img alt=/ >zzz"),
'zzz<img alt="" />zzz',
"07 - xhtml, no space after"
);
t.end();
});
tap.test("08 - alt with just equal", (t) => {
t.same(
alt("zzz<img alt= />zzz"),
'zzz<img alt="" />zzz',
"08 - xhtml, space after"
);
t.end();
});
tap.test("09 - alt with just equal", (t) => {
t.same(
alt("zzz<img alt=/>zzz"),
'zzz<img alt="" />zzz',
"09 - xhtml, excessive space before"
);
t.end();
});
tap.test("10 - alt with just equal", (t) => {
t.same(
alt("zzz<img alt= />zzz"),
'zzz<img alt="" />zzz',
"10 - xhtml, excessive space after"
);
t.end();
});
tap.test("11 - alt with just equal", (t) => {
t.same(
alt("zzz<img alt= />zzz"),
'zzz<img alt="" />zzz',
"11 - xhtml, excessive space on both sides of alt="
);
t.end();
});
tap.test("12 - alt with just equal", (t) => {
t.same(
alt("zzz<img alt = />zzz"),
'zzz<img alt="" />zzz',
"12 - xhtml, excessive space on both sides of equal, no quotes"
);
t.end();
});
tap.test("13 - alt with just equal", (t) => {
t.same(
alt("zzz<img alt =>zzz"),
'zzz<img alt="" >zzz',
"13 - html, no space after"
);
t.end();
});
tap.test("14 - alt with just equal", (t) => {
t.same(
alt('zzz<img alt = "">zzz'),
'zzz<img alt="" >zzz',
"14 - html, no space after"
);
t.end();
});
import tap from "tap";
import alt from "../dist/html-img-alt.esm";
// gap between slash and closing bracket
// -----------------------------------------------------------------------------
tap.test(
"01 - alt with two double quotes, many spaces between slash & bracket, XHTML",
(t) => {
t.same(
alt('zzz<img alt="" / >zzz'),
'zzz<img alt="" />zzz',
"01"
);
t.end();
}
);
tap.test(
"02 - alt with two double quotes, many spaces between slash & bracket, XHTML",
(t) => {
t.same(
alt('zzz<img alt ="" / >zzz'),
'zzz<img alt="" />zzz',
"02"
);
t.end();
}
);
tap.test(
"03 - alt with two double quotes, many spaces between slash & bracket, XHTML",
(t) => {
t.same(
alt('zzz<img alt = "" / >zzz'),
'zzz<img alt="" />zzz',
"03"
);
t.end();
}
);
tap.test(
"04 - alt with two double quotes, many spaces between slash & bracket, XHTML",
(t) => {
t.same(
alt('zzz<img alt = ""/ >zzz'),
'zzz<img alt="" />zzz',
"04"
);
t.end();
}
);
tap.test(
"05 - alt with two double quotes, many spaces between slash & bracket, XHTML",
(t) => {
t.same(
alt('zzz<img alt=" " / >zzz'),
'zzz<img alt="" />zzz',
"05"
);
t.end();
}
);
tap.test(
"06 - alt with two double quotes, many spaces between slash & bracket, XHTML",
(t) => {
t.same(
alt('zzz<img alt =" " / >zzz'),
'zzz<img alt="" />zzz',
"06"
);
t.end();
}
);
tap.test(
"07 - alt with two double quotes, many spaces between slash & bracket, XHTML",
(t) => {
t.same(
alt('zzz<img alt = " " / >zzz'),
'zzz<img alt="" />zzz',
"07"
);
t.end();
}
);
tap.test(
"08 - alt with two double quotes, many spaces between slash & bracket, XHTML",
(t) => {
t.same(
alt('zzz<img alt = " "/ >zzz'),
'zzz<img alt="" />zzz',
"08"
);
t.end();
}
);
tap.test(
"09 - alt with two double quotes, many spaces between slash & bracket, XHTML",
(t) => {
t.same(
alt('zzz<img alt = " "/ >zzz'),
'zzz<img alt="" />zzz',
"09"
);
t.end();
}
);
import tap from "tap";
import alt from "../dist/html-img-alt.esm";
// no alt attr is missing, only whitespace control
// -----------------------------------------------------------------------------
tap.test("01 - nothing is missing", (t) => {
t.same(
alt('zzz<img alt="123" >zzz'),
'zzz<img alt="123" >zzz',
"01 - one HTML tag, only excessive whitespace"
);
t.end();
});
tap.test("02 - nothing is missing", (t) => {
t.same(
alt('<img alt="123" >'),
'<img alt="123" >',
"02 - whitespace on both sides, one tag"
);
t.end();
});
tap.test("03 - nothing is missing", (t) => {
t.same(
alt('xxx<img alt="123" >yyy<img alt="123" >zzz'),
'xxx<img alt="123" >yyy<img alt="123" >zzz',
"03 - multiple HTML tags, only excessive whitespace"
);
t.end();
});
tap.test("04 - nothing is missing", (t) => {
t.same(
alt('zzz<img alt="123" />zzz'),
'zzz<img alt="123" />zzz',
"04 - one XHTML tag, only excessive whitespace"
);
t.end();
});
tap.test("05 - nothing is missing", (t) => {
t.same(
alt('xxx<img alt="123" />yyy<img alt="123" />zzz'),
'xxx<img alt="123" />yyy<img alt="123" />zzz',
"05 - multiple XHTML tags, only excessive whitespace"
);
t.end();
});
tap.test("06 - nothing is missing", (t) => {
t.same(
alt("aaaa bbbbb"),
"aaaa bbbbb",
"06 - excessive whitespace, no tags at all"
);
t.end();
});
tap.test("07 - nothing is missing", (t) => {
t.same(
alt("aaaa alt bbbbb"),
"aaaa alt bbbbb",
"07 - suspicious alt within copy but not IMG tag"
);
t.end();
});
tap.test("08 - nothing is missing", (t) => {
t.same(
alt("aaaa alt= bbbbb"),
"aaaa alt= bbbbb",
"08 - suspicious alt= within copy but not IMG tag"
);
t.end();
});
tap.test("09 - nothing is missing", (t) => {
t.same(
alt("aaaa alt = bbbbb"),
"aaaa alt = bbbbb",
"09 - suspicious alt= within copy but not IMG tag"
);
t.end();
});
tap.test("10 - nothing is missing", (t) => {
t.same(
alt('<img alt="1 23" >'),
'<img alt="1 23" >',
"10 - does nothing"
);
t.end();
});
tap.test("11 - nothing is missing", (t) => {
t.same(
alt('<img class="zzz" alt="123" >'),
'<img class="zzz" alt="123" >',
"11 - whitespace on both sides, one tag"
);
t.end();
});
tap.test("12 - nothing is missing", (t) => {
t.same(
alt('zzz<img alt="123" / >yyy'),
'zzz<img alt="123" />yyy',
"12"
);
t.end();
});
tap.test("13 - nothing is missing", (t) => {
t.same(
alt('z/zz<img alt="/123/" / >y/yy'),
'z/zz<img alt="/123/" />y/yy',
"13"
);
t.end();
});
tap.test("14 - nothing is missing", (t) => {
t.same(
alt('zzz<img alt = "" / >zzz'),
'zzz<img alt="" />zzz',
"14"
);
t.end();
});
tap.test("15 - nothing is missing", (t) => {
t.same(
alt('zzz<img alt="123" class="test" >zzz'),
'zzz<img alt="123" class="test" >zzz',
"15"
);
t.end();
});
import tap from "tap";
import alt from "../dist/html-img-alt.esm";
// alt with only one single quote
// -----------------------------------------------------------------------------
tap.test("01 - alt with only one single quote", (t) => {
t.same(
alt("zzz<img alt='>zzz"),
'zzz<img alt="" >zzz',
"01 - html, one single quote"
);
t.end();
});
tap.test("02 - alt with only one single quote", (t) => {
t.same(
alt("zzz<img alt= ' >zzz"),
'zzz<img alt="" >zzz',
"02 - html, one single quote"
);
t.end();
});
tap.test("03 - alt with only one single quote", (t) => {
t.same(
alt("zzz<img alt = ' >zzz"),
'zzz<img alt="" >zzz',
"03 - html, one single quote"
);
t.end();
});
tap.test("04 - alt with only one single quote", (t) => {
t.same(
alt("zz'z<img alt='>zzz<img alt=\"legit quote: '\" >zz"),
'zz\'z<img alt="" >zzz<img alt="legit quote: \'" >zz',
"04 - html, one single quote"
);
t.end();
});
tap.test("05 - alt with only one single quote", (t) => {
t.same(
alt("zzz<img alt= '' >zzz"),
'zzz<img alt="" >zzz',
"05 - html, two single quotes"
);
t.end();
});
tap.test("06 - alt with only one single quote", (t) => {
t.same(
alt("zzz<img alt= ''>zzz"),
'zzz<img alt="" >zzz',
"06 - html, two single quotes"
);
t.end();
});
tap.test("07 - alt with only one single quote", (t) => {
t.same(
alt("zzz<img alt ='>zzz"),
'zzz<img alt="" >zzz',
"07 - html, one single quote"
);
t.end();
});
import tap from "tap";
import alt from "../dist/html-img-alt.esm";
// alt attr is present, but with only one quote (double or single), one tag
// -----------------------------------------------------------------------------
tap.test("01 - alt with only one double quote, one HTML tag", (t) => {
t.same(alt('zzz<img alt=">zzz'), 'zzz<img alt="" >zzz', "01");
t.end();
});
tap.test("02 - alt with only one double quote, one HTML tag", (t) => {
t.same(alt('zzz<img alt =">zzz'), 'zzz<img alt="" >zzz', "02");
t.end();
});
tap.test("03 - alt with only one double quote, one HTML tag", (t) => {
t.same(alt('zzz<img alt= ">zzz'), 'zzz<img alt="" >zzz', "03");
t.end();
});
tap.test("04 - alt with only one double quote, one HTML tag", (t) => {
t.same(alt('zzz<img alt=" >zzz'), 'zzz<img alt="" >zzz', "04");
t.end();
});
tap.test("05 - alt with only one double quote, one HTML tag", (t) => {
t.same(alt('zzz<img alt =">zzz'), 'zzz<img alt="" >zzz', "05");
t.end();
});
tap.test("06 - alt with only one double quote, one HTML tag", (t) => {
t.same(alt('zzz