function assertCLIResult(result:xm.RunCLIResult, test, info:helper.TestInfo, args):void { assert.isObject(result, 'result'); assert.strictEqual(result.code, 0, 'result.code'); assert.operator(result.stdout.length, '>=', 0, 'result.stdout.length'); var stdout = trimHeader(result.stdout.toString('utf8')); var stderr = trimHeader(result.stderr.toString('utf8')); fs.writeFileSync(info.stdoutFile, stdout, 'utf8'); if (result.stderr.length > 0) { fs.writeFileSync(info.stderrFile, stderr, 'utf8'); } if (result.error) { xm.file.writeJSONSync(info.errorFile, result.error); } var stdoutExpect = fs.readFileSync(info.stdoutExpect, 'utf8'); assert.operator(stdoutExpect.length, '>=', 0, 'stdoutExpect.length'); helper.longAssert(stdout, stdoutExpect, 'result.stdout'); if (fs.existsSync(info.stderrExpect)) { var stderrExpect = fs.readFileSync(info.stderrExpect, 'utf8'); helper.longAssert(stderr, stderrExpect, 'result.stderr'); } if (fs.existsSync(info.errorExpect)) { var errorExpect = xm.file.readJSONSync(info.errorExpect); assert.jsonOf(result.error, errorExpect, 'result.error'); } }
export function assertBBoxInclusion(outerEl: d3Selection<Element>, innerEl: d3Selection<any>) { const outerBox = outerEl.node().getBoundingClientRect(); const innerBox = innerEl.node().getBoundingClientRect(); assert.operator(Math.floor(outerBox.left), "<=", Math.ceil(innerBox.left) + PIXEL_CLOSETO_REQUIREMENT, "bounding rect left included"); assert.operator(Math.floor(outerBox.top), "<=", Math.ceil(innerBox.top) + PIXEL_CLOSETO_REQUIREMENT, "bounding rect top included"); assert.operator(Math.ceil(outerBox.right) + PIXEL_CLOSETO_REQUIREMENT, ">=", Math.floor(innerBox.right), "bounding rect right included"); assert.operator(Math.ceil(outerBox.bottom) + PIXEL_CLOSETO_REQUIREMENT, ">=", Math.floor(innerBox.bottom), "bounding rect bottom included"); }
it("two lines", () => { const text = "hello world!."; const availableWidth = measurer.measure(text).width - 2; const baseWrapper = new Wrapper().maxLines(2); const result = wrapper.wrap(text, measurer, availableWidth); const baseResult = baseWrapper.wrap(text, measurer, availableWidth); const baseDimensions = measurer.measure(baseResult.wrappedText); const dimensions = measurer.measure(result.wrappedText); assert.deepEqual(result.originalText, text, "original text has been set"); assert.notEqual(result.wrappedText, text, "wrapped text is not the whole line"); assert.notEqual(result.wrappedText, baseResult.wrappedText, "wrapped text looks better"); assert.operator(dimensions.width, "<", baseDimensions.width, "occupies less width"); assert.equal(dimensions.height, baseDimensions.height, "occupies same height"); assert.operator(dimensions.width, "<=", availableWidth, "wrapped text fits in"); });
return core.index.getIndex().then((index:tsd.DefIndex) => { assert.isTrue(index.hasIndex(), 'index.hasIndex'); assert.operator(index.list.length, '>', 200, 'index.list'); // xm.log(index.toDump()); // TODO validate index data return null; });
}).then((firstData:NodeBuffer) => { assert.instanceOf(firstData, Buffer, 'first callback data'); assert.operator(firstData.length, '>', 0, 'first callback data'); // get again, should be cached return repo.raw.getBinary(ref, filePath).progress((note:any) => { notes.push(note); }).then((secondData:NodeBuffer) => { assert.instanceOf(secondData, Buffer, 'second callback data'); assert.strictEqual(firstData.toString('utf8'), secondData.toString('utf8'), 'first vs second data'); repo.raw.track.complete('second'); helper.assertNotes(notes, [ { message: /^remote: /, code: 'http 200' }, { message: /^local: /, code: null } ], 'second'); }); });
it("does not break words, except as last resort", () => { const availableWidth = measurer.measure(token).width * 3 / 4; const result = wrapper.wrap(token, measurer, availableWidth); assert.lengthOf(result.wrappedText.split("\n"), 2, "wrapping occured"); assert.deepEqual(result.truncatedText, "", "non of the text has been truncated"); assert.deepEqual(result.noBrokeWords, 1, "wrapping with breaking one word"); assert.deepEqual(result.noLines, 2, "wrapping was needed"); assert.operator(measurer.measure(result.wrappedText).width, "<=", availableWidth, "wrapped text fits in"); });
it("multi time wrapping", () => { const availableWidth = measurer.measure("hell").width; const result = wrapper.wrap(line, measurer, availableWidth); assert.deepEqual(result.originalText, line, "original text has been set"); assert.lengthOf(result.wrappedText.split("\n"), 5, "wrapping occured"); assert.deepEqual(result.truncatedText, "", "non of the text has been truncated"); assert.closeTo(result.noBrokeWords, 3, 1, "wrapping with breaking two words about three times"); assert.equal(result.noLines, 5, "wrapping was needed"); assert.operator(measurer.measure(result.wrappedText).width, "<=", availableWidth, "wrapped text fits in"); });
it("whitespaces at the end", () => { line = "hello wor"; const availableWidth = measurer.measure("hello").width; const result = wrapper.wrap(line, measurer, availableWidth); assert.deepEqual(result.originalText, line, "original text has been set"); assert.deepEqual(result.wrappedText, "hello\nwor", "only first word fits"); assert.deepEqual(result.truncatedText, "", "whole line fits"); assert.equal(result.noLines, 2, "wrapping was needed"); assert.operator(measurer.measure(result.wrappedText).width, "<=", availableWidth, "wrapped text fits in"); });
it("does not break words", () => { const availableWidth = measurer.measure(line).width * 0.75; const result = wrapper.wrap(line, measurer, availableWidth); assert.deepEqual(result.originalText, line, "original text has been set"); assert.lengthOf(result.wrappedText.split("\n"), 2, "wrapping occured"); assert.deepEqual(result.truncatedText, "", "non of the text has been truncated"); assert.equal(result.noBrokeWords, 0, "wrapping with breaking no word"); assert.equal(result.noLines, 2, "wrapping was needed"); assert.operator(measurer.measure(result.wrappedText).width, "<=", availableWidth, "wrapped text fits in"); });
helper.loadHeaderFixtures(path.resolve(__dirname, '..', 'fixtures', 'headers')).done((res:helper.HeaderAssert[]) => { assert.operator(res.length, '>', 0); data = res; if (filter) { data = data.filter((value:helper.HeaderAssert) => { return filter.indexOf(value.name) > -1; }); } done(); }, done);