-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migrate mocha -> ava (and use nyc instead of istanbul)
- Loading branch information
Showing
10 changed files
with
522 additions
and
552 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,32 @@ | ||
import {strictEqual} from 'assert'; | ||
import test from 'ava'; | ||
|
||
import {BufferIterator} from 'lexing'; | ||
import {consumeString} from '../parsers/consumers'; | ||
|
||
function assertBuffersEqual(actual, expected, message?: string) { | ||
return strictEqual(actual.toString('hex'), expected.toString('hex'), message); | ||
} | ||
|
||
describe('consumers', () => { | ||
it('should consume a typical PDF string', () => { | ||
const iterable = BufferIterator.fromString('Hello world) >>\n2 0 obj'); | ||
const expected = Buffer.from('Hello world', 'ascii'); | ||
const actual = consumeString(iterable); | ||
assertBuffersEqual(actual, expected); | ||
}); | ||
test('should consume a typical PDF string', t => { | ||
const iterable = BufferIterator.fromString('Hello world) >>\n2 0 obj'); | ||
const expected = Buffer.from('Hello world', 'ascii'); | ||
const actual = consumeString(iterable); | ||
t.deepEqual(actual, expected); | ||
}); | ||
|
||
it('should consume a nested PDF string', () => { | ||
const iterable = BufferIterator.fromString('Hello (world)!) >>'); | ||
const expected = Buffer.from('Hello (world)!', 'ascii'); | ||
const actual = consumeString(iterable); | ||
assertBuffersEqual(actual, expected); | ||
}); | ||
test('should consume a nested PDF string', t => { | ||
const iterable = BufferIterator.fromString('Hello (world)!) >>'); | ||
const expected = Buffer.from('Hello (world)!', 'ascii'); | ||
const actual = consumeString(iterable); | ||
t.deepEqual(actual, expected); | ||
}); | ||
|
||
it('should consume a double-nested PDF string', () => { | ||
const iterable = BufferIterator.fromString('Hello (world (hi))!) >>'); | ||
const expected = Buffer.from('Hello (world (hi))!', 'ascii'); | ||
const actual = consumeString(iterable); | ||
assertBuffersEqual(actual, expected); | ||
}); | ||
test('should consume a double-nested PDF string', t => { | ||
const iterable = BufferIterator.fromString('Hello (world (hi))!) >>'); | ||
const expected = Buffer.from('Hello (world (hi))!', 'ascii'); | ||
const actual = consumeString(iterable); | ||
t.deepEqual(actual, expected); | ||
}); | ||
|
||
it('should consume a PDF string with unusual characters', () => { | ||
const iterable = BufferIterator.fromString('Hello \(world\)!) >>'); | ||
const expected = Buffer.from('Hello (world)!', 'ascii'); | ||
const actual = consumeString(iterable); | ||
assertBuffersEqual(actual, expected); | ||
}); | ||
test('should consume a PDF string with unusual characters', t => { | ||
const iterable = BufferIterator.fromString('Hello \(world\)!) >>'); | ||
const expected = Buffer.from('Hello (world)!', 'ascii'); | ||
const actual = consumeString(iterable); | ||
t.deepEqual(actual, expected); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,15 @@ | ||
import {strictEqual} from 'assert'; | ||
import test from 'ava'; | ||
|
||
import {swapEndian} from '../util'; | ||
|
||
describe('util', () => { | ||
it('should swap every two bytes in a Buffer', () => { | ||
const littleEndianWithBOM = Buffer.from('fffe680065006c006c006f00', 'hex'); | ||
const swapped = swapEndian(littleEndianWithBOM); | ||
strictEqual(swapped.toString('hex'), 'feff00680065006c006c006f'); | ||
}); | ||
test('util should swap every two bytes in a Buffer', t => { | ||
const littleEndianWithBOM = Buffer.from('fffe680065006c006c006f00', 'hex'); | ||
const swapped = swapEndian(littleEndianWithBOM); | ||
t.deepEqual(swapped.toString('hex'), 'feff00680065006c006c006f'); | ||
}); | ||
|
||
it('should swap every two bytes in a Buffer except the last if there are an odd number of bytes', () => { | ||
const brokenLittleEndianWithBOM = Buffer.from('fffe680065006c006c006f', 'hex'); | ||
const swapped = swapEndian(brokenLittleEndianWithBOM); | ||
strictEqual(swapped.toString('hex'), 'feff00680065006c006c6f'); | ||
}); | ||
test('util should swap every two bytes in a Buffer except the last if there are an odd number of bytes', t => { | ||
const brokenLittleEndianWithBOM = Buffer.from('fffe680065006c006c006f', 'hex'); | ||
const swapped = swapEndian(brokenLittleEndianWithBOM); | ||
t.deepEqual(swapped.toString('hex'), 'feff00680065006c006c6f'); | ||
}); |
Oops, something went wrong.