From f486d11efe25105bf423d0f6e197bfa4d06e8545 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luiz=20Am=C3=A9rico?= Date: Sat, 4 May 2019 22:30:34 -0300 Subject: [PATCH] Add dash unit tests --- tests/unit/vector.spec.js | 115 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 115 insertions(+) create mode 100644 tests/unit/vector.spec.js diff --git a/tests/unit/vector.spec.js b/tests/unit/vector.spec.js new file mode 100644 index 0000000..8540bb8 --- /dev/null +++ b/tests/unit/vector.spec.js @@ -0,0 +1,115 @@ +import PDFDocument from '../../lib/document'; +import { logData } from './helpers'; + +describe('Vector Graphics', () => { + let document; + + beforeEach(() => { + document = new PDFDocument({ + info: { CreationDate: new Date(Date.UTC(2018, 1, 1)) }, + compress: false + }); + }); + + describe('dash', () => { + test('with numeric length argument', () => { + const docData = logData(document); + const vectorStream = new Buffer( + '1 0 0 -1 0 792 cm\n50 20 m\n[2 2] 0 d\nS\n', + 'binary' + ); + + document + .moveTo(50, 20) + .dash(2) + .stroke(); + document.end(); + + expect(docData).toContainChunk([ + `5 0 obj`, + `<< +/Length 38 +>>`, + `stream`, + vectorStream, + `\nendstream`, + `endobj` + ]); + }); + + test('with array length argument', () => { + const docData = logData(document); + const vectorStream = new Buffer( + '1 0 0 -1 0 792 cm\n50 20 m\n[1 2] 0 d\nS\n', + 'binary' + ); + + document + .moveTo(50, 20) + .dash([1, 2]) + .stroke(); + document.end(); + + expect(docData).toContainChunk([ + `5 0 obj`, + `<< +/Length 38 +>>`, + `stream`, + vectorStream, + `\nendstream`, + `endobj` + ]); + }); + + test('with space option', () => { + const docData = logData(document); + const vectorStream = new Buffer( + '1 0 0 -1 0 792 cm\n50 20 m\n[2 10] 0 d\nS\n', + 'binary' + ); + + document + .moveTo(50, 20) + .dash(2, { space: 10 }) + .stroke(); + document.end(); + + expect(docData).toContainChunk([ + `5 0 obj`, + `<< +/Length 39 +>>`, + `stream`, + vectorStream, + `\nendstream`, + `endobj` + ]); + }); + + test('with phase option', () => { + const docData = logData(document); + const vectorStream = new Buffer( + '1 0 0 -1 0 792 cm\n50 20 m\n[2 2] 8 d\nS\n', + 'binary' + ); + + document + .moveTo(50, 20) + .dash(2, { phase: 8 }) + .stroke(); + document.end(); + + expect(docData).toContainChunk([ + `5 0 obj`, + `<< +/Length 38 +>>`, + `stream`, + vectorStream, + `\nendstream`, + `endobj` + ]); + }); + }); +});