Skip to content

Commit

Permalink
Delint tests
Browse files Browse the repository at this point in the history
  • Loading branch information
chbrown committed Jul 10, 2018
1 parent 2f90296 commit 986bc63
Show file tree
Hide file tree
Showing 7 changed files with 181 additions and 182 deletions.
100 changes: 50 additions & 50 deletions test/cmap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ import test, {ExecutionContext} from 'ava';
import {parseCMap} from '../parsers/index';

function check(input: string, expected: any, t: ExecutionContext) {
var output = parseCMap(Buffer.from(input));
var message = `parse result does not match expected output.
const output = parseCMap(Buffer.from(input));
const message = `parse result does not match expected output.
parse("${input}") => ${JSON.stringify(output)}
but should == ${JSON.stringify(expected)}`;
t.deepEqual(output, expected, message);
}

test('CMap parser should parse simple byteLength=1 bfrange', t => {
var input = `/CIDInit /ProcSet findresource begin
const input = `/CIDInit /ProcSet findresource begin
12 dict begin
begincmap
/CMapType 2 def
Expand All @@ -28,22 +28,22 @@ endbfrange
endcmap
CMapName currentdict /CMap defineresource pop
end end`;
var expected = {
"codeSpaceRanges": [{"low":0, "high":255}],
"mappings": [
{"src":0, "dst":"−", "byteLength":1},
{"src":1, "dst":"·", "byteLength":1},
{"src":2, "dst":"×", "byteLength":1},
{"src":20, "dst":"≤", "byteLength":1},
{"src":21, "dst":"≥", "byteLength":1},
const expected = {
codeSpaceRanges: [{low: 0, high: 255}],
mappings: [
{src: 0, dst: '−', byteLength: 1},
{src: 1, dst: '·', byteLength: 1},
{src: 2, dst: '×', byteLength: 1},
{src: 20, dst: '≤', byteLength: 1},
{src: 21, dst: '≥', byteLength: 1},
],
"byteLength": 1,
byteLength: 1,
};
check(input, expected, t);
});

test('CMap parser should parse simple byteLength=2 bfchar', t => {
var input = `/CIDInit /ProcSet findresource begin
const input = `/CIDInit /ProcSet findresource begin
12 dict begin
begincmap
/CIDSystemInfo
Expand All @@ -63,21 +63,21 @@ endcmap
CMapName currentdict /CMap defineresource pop
end
end`;
var expected = {
"codeSpaceRanges": [{"low":0, "high":65535}],
"mappings": [
{"src":271, "dst":"b", "byteLength":2},
{"src":1004, "dst":"0", "byteLength":2},
{"src":1005, "dst":"1", "byteLength":2},
{"src":1006, "dst":"2", "byteLength":2},
const expected = {
codeSpaceRanges: [{low: 0, high: 65535}],
mappings: [
{src: 271, dst: 'b', byteLength: 2},
{src: 1004, dst: '0', byteLength: 2},
{src: 1005, dst: '1', byteLength: 2},
{src: 1006, dst: '2', byteLength: 2},
],
"byteLength": 2,
byteLength: 2,
};
check(input, expected, t);
});

test('CMap parser should parse single bfchar', t => {
var input = `/CIDInit /ProcSet findresource begin
const input = `/CIDInit /ProcSet findresource begin
12 dict begin
begincmap
/CIDSystemInfo
Expand All @@ -92,18 +92,18 @@ endcodespacerange
<0078> <2022>
endbfchar
endcmap CMapName currentdict /CMap defineresource pop end end`;
var expected = {
"codeSpaceRanges": [{"low":0, "high":65535}],
"mappings": [
{"src":120, "dst":"•", "byteLength":2},
const expected = {
codeSpaceRanges: [{low: 0, high: 65535}],
mappings: [
{src: 120, dst: '•', byteLength: 2},
],
"byteLength": 2,
byteLength: 2,
};
check(input, expected, t);
});

test('CMap parser should parse multiple bfchars and bfrange', t => {
var input = `/CIDInit /ProcSet findresource begin
const input = `/CIDInit /ProcSet findresource begin
12 dict begin
begincmap
/CIDSystemInfo <<
Expand Down Expand Up @@ -134,27 +134,27 @@ endcmap
CMapName currentdict /CMap defineresource pop
end
end`;
var expected = {
"codeSpaceRanges": [
{"low": 0, "high": 255},
const expected = {
codeSpaceRanges: [
{low: 0, high: 255},
],
"mappings": [
{"src": 44, "dst": "\t\r  ", "byteLength": 1},
{"src": 67, "dst": "-­‐", "byteLength": 1},
{"src": 33, "dst": "1", "byteLength": 1},
{"src": 34, "dst": ".", "byteLength": 1},
{"src": 35, "dst": "I", "byteLength": 1},
{"src": 36, "dst": "n", "byteLength": 1},
{"src": 37, "dst": "t", "byteLength": 1},
{"src": 38, "dst": "r", "byteLength": 1},
mappings: [
{src: 44, dst: '\t\r \xa0', byteLength: 1},
{src: 67, dst: '-­‐', byteLength: 1},
{src: 33, dst: '1', byteLength: 1},
{src: 34, dst: '.', byteLength: 1},
{src: 35, dst: 'I', byteLength: 1},
{src: 36, dst: 'n', byteLength: 1},
{src: 37, dst: 't', byteLength: 1},
{src: 38, dst: 'r', byteLength: 1},
],
"byteLength": 1,
byteLength: 1,
};
check(input, expected, t);
});

test('CMap parser should parse multiple code space ranges', t => {
var input = `%!PS-Adobe-3.0 Resource-CMap
const input = `%!PS-Adobe-3.0 Resource-CMap
%%DocumentNeededResources: ProcSet (CIDInit)
%%IncludeResource: ProcSet (CIDInit)
%%BeginResource: CMap (90ms-RKSJ-H)
Expand Down Expand Up @@ -196,15 +196,15 @@ CMapName currentdict /CMap defineresource pop end
end
%%EndResource
%%EOF`;
var expected = {
"codeSpaceRanges": [
{"low": 0, "high": 128},
{"low": 33088, "high": 40956},
{"low": 160, "high": 223},
{"low": 57408, "high": 64764},
const expected = {
codeSpaceRanges: [
{low: 0, high: 128},
{low: 33088, high: 40956},
{low: 160, high: 223},
{low: 57408, high: 64764},
],
"mappings": [],
"byteLength": 1,
mappings: [],
byteLength: 1,
};
check(input, expected, t);
});
Expand Down
38 changes: 19 additions & 19 deletions test/filters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,41 +3,41 @@ import test from 'ava';
import * as decoders from '../filters/decoders';

test('pdf filters/decoders: ASCII85Decode should decode an ascii string', t => {
var output = decoders.ASCII85Decode(Buffer.from('87cURD]j7BEbo80'));
const output = decoders.ASCII85Decode(Buffer.from('87cURD]j7BEbo80'));
t.deepEqual(output, Buffer.from('Hello world!'));
});

test('pdf filters/decoders: ASCII85Decode should decode an ascii string with an EOF marker', t => {
var output = decoders.ASCII85Decode(Buffer.from('87cURD]j7BEbo80~>'));
const output = decoders.ASCII85Decode(Buffer.from('87cURD]j7BEbo80~>'));
t.deepEqual(output, Buffer.from('Hello world!'));
});

test('pdf filters/decoders: ASCII85Decode should decode a buffer of 0xFF bytes', t => {
var output = decoders.ASCII85Decode(Buffer.from('s8W-!'));
const output = decoders.ASCII85Decode(Buffer.from('s8W-!'));
t.deepEqual(output, Buffer.from([255, 255, 255, 255]));
});

test('pdf filters/decoders: ASCII85Decode should decode a random buffer of length 12', t => {
var output = decoders.ASCII85Decode(Buffer.from("%V'A!!<ZDmrr"));
const output = decoders.ASCII85Decode(Buffer.from("%V'A!!<ZDmrr"));
t.deepEqual(output, Buffer.from([14, 99, 109, 203, 1, 3, 87, 155, 255]));
});

test('pdf filters/decoders: ASCII85Decode should decode a random buffer of length 5', t => {
// e.g., comparison point: python3.4 >>> import base64; base64.a85encode(bytes([200, 8, 104, 63]))
var output = decoders.ASCII85Decode(Buffer.from('a9ZHD'));
const output = decoders.ASCII85Decode(Buffer.from('a9ZHD'));
t.deepEqual(output, Buffer.from([200, 8, 104, 63]));
});

test('pdf filters/decoders: ASCII85Decode should decode the leviathan example from wikipedia', t => {
var input = [
const input = [
'9jqo^BlbD-BleB1DJ+*+F(f,q/0JhKF<GL>Cj@.4Gp$d7F!,L7@<6@)/0JDEF<G%<+EV:2F!,',
'O<DJ+*.@<*K0@<6L(Df-\\0Ec5e;DffZ(EZee.Bl.9pF"AGXBPCsi+DGm>@3BB/F*&OCAfu2/AKY',
'i(DIb:@FD,*)+C]U=@3BN#EcYf8ATD3s@q?d$AftVqCh[NqF<G:8+EV:.+Cf>-FD5W8ARlolDIa',
"l(DId<j@<?3r@:F%a+D58'ATD4$Bl@l3De:,-DJs`8ARoFb/0JMK@qB4^F!,R<AKZ&-DfTqBG%G",
">uD.RTpAKYo'+CT/5+Cei#DII?(E,9)oF*2M7/c",
].join('\n');
var output = decoders.ASCII85Decode(Buffer.from(input));
t.deepEqual(output, Buffer.from(`Man is distinguished, not only by his reason, but by this singular passion from other animals, which is a lust of the mind, that by a perseverance of delight in the continued and indefatigable generation of knowledge, exceeds the short vehemence of any carnal pleasure.`));
const output = decoders.ASCII85Decode(Buffer.from(input));
t.deepEqual(output, Buffer.from('Man is distinguished, not only by his reason, but by this singular passion from other animals, which is a lust of the mind, that by a perseverance of delight in the continued and indefatigable generation of knowledge, exceeds the short vehemence of any carnal pleasure.'));
});

/*
Expand All @@ -51,29 +51,29 @@ test('pdf filters/decoders: ASCII85Decode should decode the leviathan example fr
*/

test('pdf filters/decoders: LZWDecode should iterate through a bit string correctly', t => {
var buffer = Buffer.from([0x8F, 0x67]);
var bits = new decoders.BitIterator(buffer);
const buffer = Buffer.from([0x8F, 0x67]);
const bits = new decoders.BitIterator(buffer);
//
var actual: number[] = [bits.next(9), bits.next(2), bits.next(5)];
const actual: number[] = [bits.next(9), bits.next(2), bits.next(5)];
t.deepEqual(actual, [286, 3, 7]);
});

test('pdf filters/decoders: LZWDecode should iterate through another bit string correctly', t => {
var buffer = Buffer.from([0x80, 0x0B, 0x60, 0x50, 0x22, 0x0C, 0x0C, 0x85, 0x01]);
var bit_iterator = new decoders.BitIterator(buffer);
const buffer = Buffer.from([0x80, 0x0B, 0x60, 0x50, 0x22, 0x0C, 0x0C, 0x85, 0x01]);
const bit_iterator = new decoders.BitIterator(buffer);
//
var actual: number[] = [];
const actual: number[] = [];
while (bit_iterator.length > bit_iterator.offset) {
var code = bit_iterator.next(9);
const code = bit_iterator.next(9);
actual.push(code);
}
var expected = [256, 45, 258, 258, 65, 259, 66, 257];
const expected = [256, 45, 258, 258, 65, 259, 66, 257];
t.deepEqual(actual, expected);
});

test('pdf filters/decoders: LZWDecode should LZW decode the example from the PDF spec (7.4.4.2, Example 2)', t => {
var encoded = Buffer.from([0x80, 0x0B, 0x60, 0x50, 0x22, 0x0C, 0x0C, 0x85, 0x01]);
var actual = decoders.LZWDecode(encoded);
var expected = Buffer.from([45, 45, 45, 45, 45, 65, 45, 45, 45, 66]);
const encoded = Buffer.from([0x80, 0x0B, 0x60, 0x50, 0x22, 0x0C, 0x0C, 0x85, 0x01]);
const actual = decoders.LZWDecode(encoded);
const expected = Buffer.from([45, 45, 45, 45, 45, 65, 45, 45, 45, 66]);
t.deepEqual(actual, expected);
});
5 changes: 2 additions & 3 deletions test/graphics.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import test from 'ava';

import {Rectangle, makeRectangle, distanceToRectangle, formatRectangle, containsRectangle} from '../graphics/geometry';
import {Container, mergeContainer} from '../graphics/geometry';
import {makeRectangle, distanceToRectangle, formatRectangle, containsRectangle} from '../graphics/geometry';

test('graphics should measure distances between rectangles', t => {
const unitRect = makeRectangle(0, 0, 1, 1);
Expand All @@ -12,7 +11,7 @@ test('graphics should measure distances between rectangles', t => {

test('graphics should format rectangle string', t => {
const unitRect = makeRectangle(0, 0, 1, 1);
t.deepEqual("[0, 0, 1, 1]", formatRectangle(unitRect));
t.deepEqual('[0, 0, 1, 1]', formatRectangle(unitRect));
});

test('graphics should detect rectangle containment', t => {
Expand Down
18 changes: 9 additions & 9 deletions test/numbers.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
import test from 'ava';

test('Numbers that should look numeric', t => {
t.true(!isNaN(<any>'3'));
t.true(!isNaN(<any>'34'));
t.true(!isNaN(<any>'-1'));
t.true(!isNaN(<any>'100.0'));
t.true(!isNaN('3' as any));
t.true(!isNaN('34' as any));
t.true(!isNaN('-1' as any));
t.true(!isNaN('100.0' as any));
t.true(!isNaN(3));
t.true(!isNaN(34));
t.true(!isNaN(-1));
t.true(!isNaN(100.0));
});
test('Numbers that should not look numeric', t => {
t.true(isNaN(<any>'3g'));
t.true(isNaN(<any>'10K'));
t.true(isNaN(<any>'four'));
t.true(isNaN('3g' as any));
t.true(isNaN('10K' as any));
t.true(isNaN('four' as any));
t.true(isNaN(undefined));
t.true(isNaN(<any>'-5-6-8'));
t.true(isNaN('-5-6-8' as any));
});
test('Numbers that should not look numeric but do', t => {
t.true(!isNaN(null));
t.true(!isNaN(<any>false));
t.true(!isNaN(false as any));
});

0 comments on commit 986bc63

Please sign in to comment.