How to use getBuffer method in rewire

Best JavaScript code snippet using rewire

multi-file-patch.test.js

Source:multi-file-patch.test.js Github

copy

Full Screen

...30 .multiFilePatch;31 });32 it('defaults to creating an exact copy', function() {33 const dup = original.clone();34 assert.strictEqual(dup.getBuffer(), original.getBuffer());35 assert.strictEqual(dup.getPatchLayer(), original.getPatchLayer());36 assert.strictEqual(dup.getHunkLayer(), original.getHunkLayer());37 assert.strictEqual(dup.getUnchangedLayer(), original.getUnchangedLayer());38 assert.strictEqual(dup.getAdditionLayer(), original.getAdditionLayer());39 assert.strictEqual(dup.getDeletionLayer(), original.getDeletionLayer());40 assert.strictEqual(dup.getNoNewlineLayer(), original.getNoNewlineLayer());41 assert.strictEqual(dup.getFilePatches(), original.getFilePatches());42 });43 it('creates a copy with a new PatchBuffer', function() {44 const {multiFilePatch} = multiFilePatchBuilder().build();45 const dup = original.clone({patchBuffer: multiFilePatch.getPatchBuffer()});46 assert.strictEqual(dup.getBuffer(), multiFilePatch.getBuffer());47 assert.strictEqual(dup.getPatchLayer(), multiFilePatch.getPatchLayer());48 assert.strictEqual(dup.getHunkLayer(), multiFilePatch.getHunkLayer());49 assert.strictEqual(dup.getUnchangedLayer(), multiFilePatch.getUnchangedLayer());50 assert.strictEqual(dup.getAdditionLayer(), multiFilePatch.getAdditionLayer());51 assert.strictEqual(dup.getDeletionLayer(), multiFilePatch.getDeletionLayer());52 assert.strictEqual(dup.getNoNewlineLayer(), multiFilePatch.getNoNewlineLayer());53 assert.strictEqual(dup.getFilePatches(), original.getFilePatches());54 });55 it('creates a copy with a new set of file patches', function() {56 const nfp = [57 filePatchBuilder().build().filePatch,58 filePatchBuilder().build().filePatch,59 ];60 const dup = original.clone({filePatches: nfp});61 assert.strictEqual(dup.getBuffer(), original.getBuffer());62 assert.strictEqual(dup.getPatchLayer(), original.getPatchLayer());63 assert.strictEqual(dup.getHunkLayer(), original.getHunkLayer());64 assert.strictEqual(dup.getUnchangedLayer(), original.getUnchangedLayer());65 assert.strictEqual(dup.getAdditionLayer(), original.getAdditionLayer());66 assert.strictEqual(dup.getDeletionLayer(), original.getDeletionLayer());67 assert.strictEqual(dup.getNoNewlineLayer(), original.getNoNewlineLayer());68 assert.strictEqual(dup.getFilePatches(), nfp);69 });70 });71 it('has an accessor for its file patches', function() {72 const {multiFilePatch} = multiFilePatchBuilder()73 .addFilePatch(filePatch => filePatch.setOldFile(file => file.path('file-0.txt')))74 .addFilePatch(filePatch => filePatch.setOldFile(file => file.path('file-1.txt')))75 .build();76 assert.lengthOf(multiFilePatch.getFilePatches(), 2);77 const [fp0, fp1] = multiFilePatch.getFilePatches();78 assert.strictEqual(fp0.getOldPath(), 'file-0.txt');79 assert.strictEqual(fp1.getOldPath(), 'file-1.txt');80 });81 describe('didAnyChangeExecutableMode()', function() {82 it('detects when at least one patch contains an executable mode change', function() {83 const {multiFilePatch: yes} = multiFilePatchBuilder()84 .addFilePatch(filePatch => {85 filePatch.setOldFile(file => file.path('file-0.txt'));86 filePatch.setNewFile(file => file.path('file-0.txt').executable());87 })88 .build();89 assert.isTrue(yes.didAnyChangeExecutableMode());90 });91 it('detects when none of the patches contain an executable mode change', function() {92 const {multiFilePatch: no} = multiFilePatchBuilder()93 .addFilePatch(filePatch => filePatch.setOldFile(file => file.path('file-0.txt')))94 .addFilePatch(filePatch => filePatch.setOldFile(file => file.path('file-1.txt')))95 .build();96 assert.isFalse(no.didAnyChangeExecutableMode());97 });98 });99 describe('anyHaveTypechange()', function() {100 it('detects when at least one patch contains a symlink change', function() {101 const {multiFilePatch: yes} = multiFilePatchBuilder()102 .addFilePatch(filePatch => filePatch.setOldFile(file => file.path('file-0.txt')))103 .addFilePatch(filePatch => {104 filePatch.setOldFile(file => file.path('file-0.txt'));105 filePatch.setNewFile(file => file.path('file-0.txt').symlinkTo('somewhere.txt'));106 })107 .build();108 assert.isTrue(yes.anyHaveTypechange());109 });110 it('detects when none of its patches contain a symlink change', function() {111 const {multiFilePatch: no} = multiFilePatchBuilder()112 .addFilePatch(filePatch => filePatch.setOldFile(file => file.path('file-0.txt')))113 .addFilePatch(filePatch => filePatch.setOldFile(file => file.path('file-1.txt')))114 .build();115 assert.isFalse(no.anyHaveTypechange());116 });117 });118 it('computes the maximum line number width of any hunk in any patch', function() {119 const {multiFilePatch} = multiFilePatchBuilder()120 .addFilePatch(fp => {121 fp.setOldFile(f => f.path('file-0.txt'));122 fp.addHunk(h => h.oldRow(10));123 fp.addHunk(h => h.oldRow(99));124 })125 .addFilePatch(fp => {126 fp.setOldFile(f => f.path('file-1.txt'));127 fp.addHunk(h => h.oldRow(5));128 fp.addHunk(h => h.oldRow(15));129 })130 .build();131 assert.strictEqual(multiFilePatch.getMaxLineNumberWidth(), 3);132 });133 it('locates an individual FilePatch by marker lookup', function() {134 const builder = multiFilePatchBuilder();135 for (let i = 0; i < 10; i++) {136 builder.addFilePatch(fp => {137 fp.setOldFile(f => f.path(`file-${i}.txt`));138 fp.addHunk(h => {139 h.oldRow(1).unchanged('a', 'b').added('c').deleted('d').unchanged('e');140 });141 fp.addHunk(h => {142 h.oldRow(10).unchanged('f').deleted('g', 'h', 'i').unchanged('j');143 });144 });145 }146 const {multiFilePatch} = builder.build();147 const fps = multiFilePatch.getFilePatches();148 assert.isUndefined(multiFilePatch.getFilePatchAt(-1));149 assert.strictEqual(multiFilePatch.getFilePatchAt(0), fps[0]);150 assert.strictEqual(multiFilePatch.getFilePatchAt(9), fps[0]);151 assert.strictEqual(multiFilePatch.getFilePatchAt(10), fps[1]);152 assert.strictEqual(multiFilePatch.getFilePatchAt(99), fps[9]);153 assert.isUndefined(multiFilePatch.getFilePatchAt(101));154 });155 it('creates a set of all unique paths referenced by patches', function() {156 const {multiFilePatch} = multiFilePatchBuilder()157 .addFilePatch(fp => {158 fp.setOldFile(f => f.path('file-0-before.txt'));159 fp.setNewFile(f => f.path('file-0-after.txt'));160 })161 .addFilePatch(fp => {162 fp.status('added');163 fp.nullOldFile();164 fp.setNewFile(f => f.path('file-1.txt'));165 })166 .addFilePatch(fp => {167 fp.setOldFile(f => f.path('file-2.txt'));168 fp.setNewFile(f => f.path('file-2.txt'));169 })170 .build();171 assert.sameMembers(172 Array.from(multiFilePatch.getPathSet()),173 ['file-0-before.txt', 'file-0-after.txt', 'file-1.txt', 'file-2.txt'],174 );175 });176 it('locates a Hunk by marker lookup', function() {177 const {multiFilePatch} = multiFilePatchBuilder()178 .addFilePatch(fp => {179 fp.addHunk(h => h.oldRow(1).added('0', '1', '2', '3', '4'));180 fp.addHunk(h => h.oldRow(10).deleted('5', '6', '7', '8', '9'));181 })182 .addFilePatch(fp => {183 fp.addHunk(h => h.oldRow(5).unchanged('10', '11').added('12').deleted('13'));184 fp.addHunk(h => h.oldRow(20).unchanged('14').deleted('15'));185 })186 .addFilePatch(fp => {187 fp.status('deleted');188 fp.addHunk(h => h.oldRow(4).deleted('16', '17', '18', '19'));189 })190 .build();191 const [fp0, fp1, fp2] = multiFilePatch.getFilePatches();192 assert.isUndefined(multiFilePatch.getHunkAt(-1));193 assert.strictEqual(multiFilePatch.getHunkAt(0), fp0.getHunks()[0]);194 assert.strictEqual(multiFilePatch.getHunkAt(4), fp0.getHunks()[0]);195 assert.strictEqual(multiFilePatch.getHunkAt(5), fp0.getHunks()[1]);196 assert.strictEqual(multiFilePatch.getHunkAt(9), fp0.getHunks()[1]);197 assert.strictEqual(multiFilePatch.getHunkAt(10), fp1.getHunks()[0]);198 assert.strictEqual(multiFilePatch.getHunkAt(15), fp1.getHunks()[1]);199 assert.strictEqual(multiFilePatch.getHunkAt(16), fp2.getHunks()[0]);200 assert.strictEqual(multiFilePatch.getHunkAt(19), fp2.getHunks()[0]);201 assert.isUndefined(multiFilePatch.getHunkAt(21));202 });203 it('represents itself as an apply-ready string', function() {204 const {multiFilePatch} = multiFilePatchBuilder()205 .addFilePatch(fp => {206 fp.setOldFile(f => f.path('file-0.txt'));207 fp.addHunk(h => h.oldRow(1).unchanged('0;0;0').added('0;0;1').deleted('0;0;2').unchanged('0;0;3'));208 fp.addHunk(h => h.oldRow(10).unchanged('0;1;0').added('0;1;1').deleted('0;1;2').unchanged('0;1;3'));209 })210 .addFilePatch(fp => {211 fp.setOldFile(f => f.path('file-1.txt'));212 fp.addHunk(h => h.oldRow(1).unchanged('1;0;0').added('1;0;1').deleted('1;0;2').unchanged('1;0;3'));213 fp.addHunk(h => h.oldRow(10).unchanged('1;1;0').added('1;1;1').deleted('1;1;2').unchanged('1;1;3'));214 })215 .build();216 assert.strictEqual(multiFilePatch.toString(), dedent`217 diff --git a/file-0.txt b/file-0.txt218 --- a/file-0.txt219 +++ b/file-0.txt220 @@ -1,3 +1,3 @@221 0;0;0222 +0;0;1223 -0;0;2224 0;0;3225 @@ -10,3 +10,3 @@226 0;1;0227 +0;1;1228 -0;1;2229 0;1;3230 diff --git a/file-1.txt b/file-1.txt231 --- a/file-1.txt232 +++ b/file-1.txt233 @@ -1,3 +1,3 @@234 1;0;0235 +1;0;1236 -1;0;2237 1;0;3238 @@ -10,3 +10,3 @@239 1;1;0240 +1;1;1241 -1;1;2242 1;1;3\n243 `);244 });245 it('adopts a new buffer', function() {246 const {multiFilePatch} = multiFilePatchBuilder()247 .addFilePatch(fp => {248 fp.setOldFile(f => f.path('A0.txt'));249 fp.addHunk(h => h.unchanged('a0').added('a1').deleted('a2').unchanged('a3'));250 })251 .addFilePatch(fp => {252 fp.setOldFile(f => f.path('A1.txt'));253 fp.addHunk(h => h.unchanged('a4').deleted('a5').unchanged('a6'));254 fp.addHunk(h => h.unchanged('a7').added('a8').unchanged('a9'));255 })256 .addFilePatch(fp => {257 fp.setOldFile(f => f.path('A2.txt'));258 fp.addHunk(h => h.oldRow(99).deleted('a10').noNewline());259 })260 .build();261 const nextBuffer = new PatchBuffer();262 multiFilePatch.adoptBuffer(nextBuffer);263 assert.strictEqual(nextBuffer.getBuffer(), multiFilePatch.getBuffer());264 assert.strictEqual(nextBuffer.getLayer('patch'), multiFilePatch.getPatchLayer());265 assert.strictEqual(nextBuffer.getLayer('hunk'), multiFilePatch.getHunkLayer());266 assert.strictEqual(nextBuffer.getLayer('unchanged'), multiFilePatch.getUnchangedLayer());267 assert.strictEqual(nextBuffer.getLayer('addition'), multiFilePatch.getAdditionLayer());268 assert.strictEqual(nextBuffer.getLayer('deletion'), multiFilePatch.getDeletionLayer());269 assert.strictEqual(nextBuffer.getLayer('nonewline'), multiFilePatch.getNoNewlineLayer());270 assert.deepEqual(nextBuffer.getBuffer().getText(), dedent`271 a0272 a1273 a2274 a3275 a4276 a5277 a6278 a7279 a8280 a9281 a10282 No newline at end of file283 `);284 const assertMarkedLayerRanges = (layer, ranges) => {285 assert.deepEqual(layer.getMarkers().map(m => m.getRange().serialize()), ranges);286 };287 assertMarkedLayerRanges(nextBuffer.getLayer('patch'), [288 [[0, 0], [3, 2]], [[4, 0], [9, 2]], [[10, 0], [11, 26]],289 ]);290 assertMarkedLayerRanges(nextBuffer.getLayer('hunk'), [291 [[0, 0], [3, 2]], [[4, 0], [6, 2]], [[7, 0], [9, 2]], [[10, 0], [11, 26]],292 ]);293 assertMarkedLayerRanges(nextBuffer.getLayer('unchanged'), [294 [[0, 0], [0, 2]], [[3, 0], [3, 2]], [[4, 0], [4, 2]], [[6, 0], [6, 2]], [[7, 0], [7, 2]], [[9, 0], [9, 2]],295 ]);296 assertMarkedLayerRanges(nextBuffer.getLayer('addition'), [297 [[1, 0], [1, 2]], [[8, 0], [8, 2]],298 ]);299 assertMarkedLayerRanges(nextBuffer.getLayer('deletion'), [300 [[2, 0], [2, 2]], [[5, 0], [5, 2]], [[10, 0], [10, 3]],301 ]);302 assertMarkedLayerRanges(nextBuffer.getLayer('nonewline'), [303 [[11, 0], [11, 26]],304 ]);305 assert.strictEqual(multiFilePatch.getBufferRowForDiffPosition('A0.txt', 1), 0);306 assert.strictEqual(multiFilePatch.getBufferRowForDiffPosition('A1.txt', 5), 7);307 });308 describe('derived patch generation', function() {309 let multiFilePatch, rowSet;310 beforeEach(function() {311 // The row content pattern here is: ${fileno};${hunkno};${lineno}, with a (**) if it's selected312 multiFilePatch = multiFilePatchBuilder()313 .addFilePatch(fp => {314 fp.setOldFile(f => f.path('file-0.txt'));315 fp.addHunk(h => h.oldRow(1).unchanged('0;0;0').added('0;0;1').deleted('0;0;2').unchanged('0;0;3'));316 fp.addHunk(h => h.oldRow(10).unchanged('0;1;0').added('0;1;1').deleted('0;1;2').unchanged('0;1;3'));317 })318 .addFilePatch(fp => {319 fp.setOldFile(f => f.path('file-1.txt'));320 fp.addHunk(h => h.oldRow(1).unchanged('1;0;0').added('1;0;1 (**)').deleted('1;0;2').unchanged('1;0;3'));321 fp.addHunk(h => h.oldRow(10).unchanged('1;1;0').added('1;1;1').deleted('1;1;2 (**)').unchanged('1;1;3'));322 })323 .addFilePatch(fp => {324 fp.setOldFile(f => f.path('file-2.txt'));325 fp.addHunk(h => h.oldRow(1).unchanged('2;0;0').added('2;0;1').deleted('2;0;2').unchanged('2;0;3'));326 fp.addHunk(h => h.oldRow(10).unchanged('2;1;0').added('2;1;1').deleted('2;2;2').unchanged('2;1;3'));327 })328 .addFilePatch(fp => {329 fp.setOldFile(f => f.path('file-3.txt'));330 fp.addHunk(h => h.oldRow(1).unchanged('3;0;0').added('3;0;1 (**)').deleted('3;0;2 (**)').unchanged('3;0;3'));331 fp.addHunk(h => h.oldRow(10).unchanged('3;1;0').added('3;1;1').deleted('3;2;2').unchanged('3;1;3'));332 })333 .build()334 .multiFilePatch;335 // Buffer rows corresponding to the rows marked with (**) above336 rowSet = new Set([9, 14, 25, 26]);337 });338 it('generates a stage patch for arbitrary buffer rows', function() {339 const stagePatch = multiFilePatch.getStagePatchForLines(rowSet);340 assert.strictEqual(stagePatch.getBuffer().getText(), dedent`341 1;0;0342 1;0;1 (**)343 1;0;2344 1;0;3345 1;1;0346 1;1;2 (**)347 1;1;3348 3;0;0349 3;0;1 (**)350 3;0;2 (**)351 3;0;3352 `);353 assert.lengthOf(stagePatch.getFilePatches(), 2);354 const [fp0, fp1] = stagePatch.getFilePatches();355 assert.strictEqual(fp0.getOldPath(), 'file-1.txt');356 assertInFilePatch(fp0, stagePatch.getBuffer()).hunks(357 {358 startRow: 0, endRow: 3,359 header: '@@ -1,3 +1,4 @@',360 regions: [361 {kind: 'unchanged', string: ' 1;0;0\n', range: [[0, 0], [0, 5]]},362 {kind: 'addition', string: '+1;0;1 (**)\n', range: [[1, 0], [1, 10]]},363 {kind: 'unchanged', string: ' 1;0;2\n 1;0;3\n', range: [[2, 0], [3, 5]]},364 ],365 },366 {367 startRow: 4, endRow: 6,368 header: '@@ -10,3 +11,2 @@',369 regions: [370 {kind: 'unchanged', string: ' 1;1;0\n', range: [[4, 0], [4, 5]]},371 {kind: 'deletion', string: '-1;1;2 (**)\n', range: [[5, 0], [5, 10]]},372 {kind: 'unchanged', string: ' 1;1;3\n', range: [[6, 0], [6, 5]]},373 ],374 },375 );376 assert.strictEqual(fp1.getOldPath(), 'file-3.txt');377 assertInFilePatch(fp1, stagePatch.getBuffer()).hunks(378 {379 startRow: 7, endRow: 10,380 header: '@@ -1,3 +1,3 @@',381 regions: [382 {kind: 'unchanged', string: ' 3;0;0\n', range: [[7, 0], [7, 5]]},383 {kind: 'addition', string: '+3;0;1 (**)\n', range: [[8, 0], [8, 10]]},384 {kind: 'deletion', string: '-3;0;2 (**)\n', range: [[9, 0], [9, 10]]},385 {kind: 'unchanged', string: ' 3;0;3\n', range: [[10, 0], [10, 5]]},386 ],387 },388 );389 });390 it('generates a stage patch from an arbitrary hunk', function() {391 const hunk = multiFilePatch.getFilePatches()[0].getHunks()[1];392 const stagePatch = multiFilePatch.getStagePatchForHunk(hunk);393 assert.strictEqual(stagePatch.getBuffer().getText(), dedent`394 0;1;0395 0;1;1396 0;1;2397 0;1;3398 `);399 assert.lengthOf(stagePatch.getFilePatches(), 1);400 const [fp0] = stagePatch.getFilePatches();401 assert.strictEqual(fp0.getOldPath(), 'file-0.txt');402 assert.strictEqual(fp0.getNewPath(), 'file-0.txt');403 assertInFilePatch(fp0, stagePatch.getBuffer()).hunks(404 {405 startRow: 0, endRow: 3,406 header: '@@ -10,3 +10,3 @@',407 regions: [408 {kind: 'unchanged', string: ' 0;1;0\n', range: [[0, 0], [0, 5]]},409 {kind: 'addition', string: '+0;1;1\n', range: [[1, 0], [1, 5]]},410 {kind: 'deletion', string: '-0;1;2\n', range: [[2, 0], [2, 5]]},411 {kind: 'unchanged', string: ' 0;1;3\n', range: [[3, 0], [3, 5]]},412 ],413 },414 );415 });416 it('generates an unstage patch for arbitrary buffer rows', function() {417 const unstagePatch = multiFilePatch.getUnstagePatchForLines(rowSet);418 assert.strictEqual(unstagePatch.getBuffer().getText(), dedent`419 1;0;0420 1;0;1 (**)421 1;0;3422 1;1;0423 1;1;1424 1;1;2 (**)425 1;1;3426 3;0;0427 3;0;1 (**)428 3;0;2 (**)429 3;0;3430 `);431 assert.lengthOf(unstagePatch.getFilePatches(), 2);432 const [fp0, fp1] = unstagePatch.getFilePatches();433 assert.strictEqual(fp0.getOldPath(), 'file-1.txt');434 assertInFilePatch(fp0, unstagePatch.getBuffer()).hunks(435 {436 startRow: 0, endRow: 2,437 header: '@@ -1,3 +1,2 @@',438 regions: [439 {kind: 'unchanged', string: ' 1;0;0\n', range: [[0, 0], [0, 5]]},440 {kind: 'deletion', string: '-1;0;1 (**)\n', range: [[1, 0], [1, 10]]},441 {kind: 'unchanged', string: ' 1;0;3\n', range: [[2, 0], [2, 5]]},442 ],443 },444 {445 startRow: 3, endRow: 6,446 header: '@@ -10,3 +9,4 @@',447 regions: [448 {kind: 'unchanged', string: ' 1;1;0\n 1;1;1\n', range: [[3, 0], [4, 5]]},449 {kind: 'addition', string: '+1;1;2 (**)\n', range: [[5, 0], [5, 10]]},450 {kind: 'unchanged', string: ' 1;1;3\n', range: [[6, 0], [6, 5]]},451 ],452 },453 );454 assert.strictEqual(fp1.getOldPath(), 'file-3.txt');455 assertInFilePatch(fp1, unstagePatch.getBuffer()).hunks(456 {457 startRow: 7, endRow: 10,458 header: '@@ -1,3 +1,3 @@',459 regions: [460 {kind: 'unchanged', string: ' 3;0;0\n', range: [[7, 0], [7, 5]]},461 {kind: 'deletion', string: '-3;0;1 (**)\n', range: [[8, 0], [8, 10]]},462 {kind: 'addition', string: '+3;0;2 (**)\n', range: [[9, 0], [9, 10]]},463 {kind: 'unchanged', string: ' 3;0;3\n', range: [[10, 0], [10, 5]]},464 ],465 },466 );467 });468 it('generates an unstage patch for an arbitrary hunk', function() {469 const hunk = multiFilePatch.getFilePatches()[1].getHunks()[0];470 const unstagePatch = multiFilePatch.getUnstagePatchForHunk(hunk);471 assert.strictEqual(unstagePatch.getBuffer().getText(), dedent`472 1;0;0473 1;0;1 (**)474 1;0;2475 1;0;3476 `);477 assert.lengthOf(unstagePatch.getFilePatches(), 1);478 const [fp0] = unstagePatch.getFilePatches();479 assert.strictEqual(fp0.getOldPath(), 'file-1.txt');480 assert.strictEqual(fp0.getNewPath(), 'file-1.txt');481 assertInFilePatch(fp0, unstagePatch.getBuffer()).hunks(482 {483 startRow: 0, endRow: 3,484 header: '@@ -1,3 +1,3 @@',485 regions: [486 {kind: 'unchanged', string: ' 1;0;0\n', range: [[0, 0], [0, 5]]},487 {kind: 'deletion', string: '-1;0;1 (**)\n', range: [[1, 0], [1, 10]]},488 {kind: 'addition', string: '+1;0;2\n', range: [[2, 0], [2, 5]]},489 {kind: 'unchanged', string: ' 1;0;3\n', range: [[3, 0], [3, 5]]},490 ],491 },492 );493 });494 });495 describe('maximum selection index', function() {496 it('returns zero if there are no selections', function() {497 const {multiFilePatch} = multiFilePatchBuilder().addFilePatch().build();498 assert.strictEqual(multiFilePatch.getMaxSelectionIndex(new Set()), 0);499 });500 it('returns the ordinal index of the highest selected change row', function() {501 const {multiFilePatch} = multiFilePatchBuilder()502 .addFilePatch(fp => {503 fp.addHunk(h => h.unchanged('.').added('0', '1', 'x *').unchanged('.'));504 fp.addHunk(h => h.unchanged('.').deleted('2').added('3').unchanged('.'));505 })506 .addFilePatch(fp => {507 fp.addHunk(h => h.unchanged('.').deleted('4', '5 *', '6').unchanged('.'));508 fp.addHunk(h => h.unchanged('.').added('7').unchanged('.'));509 })510 .build();511 assert.strictEqual(multiFilePatch.getMaxSelectionIndex(new Set([3])), 2);512 assert.strictEqual(multiFilePatch.getMaxSelectionIndex(new Set([3, 11])), 5);513 });514 });515 describe('selection range by change index', function() {516 it('selects the last change row if no longer present', function() {517 const {multiFilePatch} = multiFilePatchBuilder()518 .addFilePatch(fp => {519 fp.addHunk(h => h.unchanged('.').added('0', '1', '2').unchanged('.'));520 fp.addHunk(h => h.unchanged('.').deleted('3').added('4').unchanged('.'));521 })522 .addFilePatch(fp => {523 fp.addHunk(h => h.unchanged('.').deleted('5', '6', '7').unchanged('.'));524 fp.addHunk(h => h.unchanged('.').added('8').unchanged('.'));525 })526 .build();527 assert.deepEqual(multiFilePatch.getSelectionRangeForIndex(9).serialize(), [[15, 0], [15, Infinity]]);528 });529 it('returns the range of the change row by ordinal', function() {530 const {multiFilePatch} = multiFilePatchBuilder()531 .addFilePatch(fp => {532 fp.addHunk(h => h.unchanged('.').added('0', '1', '2').unchanged('.'));533 fp.addHunk(h => h.unchanged('.').deleted('3').added('4').unchanged('.'));534 })535 .addFilePatch(fp => {536 fp.addHunk(h => h.unchanged('.').deleted('5', '6', '7').unchanged('.'));537 fp.addHunk(h => h.unchanged('.').added('8').unchanged('.'));538 })539 .build();540 assert.deepEqual(multiFilePatch.getSelectionRangeForIndex(0).serialize(), [[1, 0], [1, Infinity]]);541 assert.deepEqual(multiFilePatch.getSelectionRangeForIndex(1).serialize(), [[2, 0], [2, Infinity]]);542 assert.deepEqual(multiFilePatch.getSelectionRangeForIndex(2).serialize(), [[3, 0], [3, Infinity]]);543 assert.deepEqual(multiFilePatch.getSelectionRangeForIndex(3).serialize(), [[6, 0], [6, Infinity]]);544 assert.deepEqual(multiFilePatch.getSelectionRangeForIndex(4).serialize(), [[7, 0], [7, Infinity]]);545 assert.deepEqual(multiFilePatch.getSelectionRangeForIndex(5).serialize(), [[10, 0], [10, Infinity]]);546 assert.deepEqual(multiFilePatch.getSelectionRangeForIndex(6).serialize(), [[11, 0], [11, Infinity]]);547 assert.deepEqual(multiFilePatch.getSelectionRangeForIndex(7).serialize(), [[12, 0], [12, Infinity]]);548 assert.deepEqual(multiFilePatch.getSelectionRangeForIndex(8).serialize(), [[15, 0], [15, Infinity]]);549 });550 });551 describe('file-patch spanning selection detection', function() {552 let multiFilePatch;553 beforeEach(function() {554 multiFilePatch = multiFilePatchBuilder()555 .addFilePatch(fp => {556 fp.setOldFile(f => f.path('file-0'));557 fp.addHunk(h => h.unchanged('0').added('1').deleted('2', '3').unchanged('4'));558 fp.addHunk(h => h.unchanged('5').added('6').unchanged('7'));559 })560 .addFilePatch(fp => {561 fp.setOldFile(f => f.path('file-1'));562 fp.addHunk(h => h.unchanged('8').deleted('9', '10').unchanged('11'));563 })564 .build()565 .multiFilePatch;566 });567 it('with buffer positions belonging to a single patch', function() {568 assert.isFalse(multiFilePatch.spansMultipleFiles([1, 5]));569 });570 it('with buffer positions belonging to multiple patches', function() {571 assert.isTrue(multiFilePatch.spansMultipleFiles([6, 10]));572 });573 });574 describe('isPatchVisible', function() {575 it('returns false if patch exceeds large diff threshold', function() {576 const multiFilePatch = multiFilePatchBuilder()577 .addFilePatch(fp => {578 fp.setOldFile(f => f.path('file-0'));579 fp.renderStatus(DEFERRED);580 })581 .build()582 .multiFilePatch;583 assert.isFalse(multiFilePatch.isPatchVisible('file-0'));584 });585 it('returns false if patch is collapsed', function() {586 const multiFilePatch = multiFilePatchBuilder()587 .addFilePatch(fp => {588 fp.setOldFile(f => f.path('file-0'));589 fp.renderStatus(COLLAPSED);590 }).build().multiFilePatch;591 assert.isFalse(multiFilePatch.isPatchVisible('file-0'));592 });593 it('returns true if patch is expanded', function() {594 const multiFilePatch = multiFilePatchBuilder()595 .addFilePatch(fp => {596 fp.setOldFile(f => f.path('file-0'));597 fp.renderStatus(EXPANDED);598 })599 .build()600 .multiFilePatch;601 assert.isTrue(multiFilePatch.isPatchVisible('file-0'));602 });603 it('multiFilePatch with multiple hunks returns correct values', function() {604 const multiFilePatch = multiFilePatchBuilder()605 .addFilePatch(fp => {606 fp.setOldFile(f => f.path('expanded-file'));607 fp.renderStatus(EXPANDED);608 })609 .addFilePatch(fp => {610 fp.setOldFile(f => f.path('too-large-file'));611 fp.renderStatus(DEFERRED);612 })613 .addFilePatch(fp => {614 fp.setOldFile(f => f.path('collapsed-file'));615 fp.renderStatus(COLLAPSED);616 })617 .build()618 .multiFilePatch;619 assert.isTrue(multiFilePatch.isPatchVisible('expanded-file'));620 assert.isFalse(multiFilePatch.isPatchVisible('too-large-file'));621 assert.isFalse(multiFilePatch.isPatchVisible('collapsed-file'));622 });623 it('returns false if patch does not exist', function() {624 const multiFilePatch = multiFilePatchBuilder()625 .addFilePatch(fp => {626 fp.setOldFile(f => f.path('file-0'));627 fp.renderStatus(EXPANDED);628 })629 .build()630 .multiFilePatch;631 assert.isFalse(multiFilePatch.isPatchVisible('invalid-file-path'));632 });633 });634 describe('getPreviewPatchBuffer', function() {635 it('returns a PatchBuffer containing nearby rows of the MultiFilePatch', function() {636 const {multiFilePatch} = multiFilePatchBuilder()637 .addFilePatch(fp => {638 fp.setOldFile(f => f.path('file.txt'));639 fp.addHunk(h => h.unchanged('0').added('1', '2').unchanged('3').deleted('4', '5').unchanged('6'));640 fp.addHunk(h => h.unchanged('7').deleted('8').unchanged('9', '10'));641 })642 .build();643 const subPatch = multiFilePatch.getPreviewPatchBuffer('file.txt', 6, 4);644 assert.strictEqual(subPatch.getBuffer().getText(), dedent`645 2646 3647 4648 5649 `);650 assertMarkerRanges(subPatch.getLayer('patch'), [[0, 0], [3, 1]]);651 assertMarkerRanges(subPatch.getLayer('hunk'), [[0, 0], [3, 1]]);652 assertMarkerRanges(subPatch.getLayer('unchanged'), [[1, 0], [1, 1]]);653 assertMarkerRanges(subPatch.getLayer('addition'), [[0, 0], [0, 1]]);654 assertMarkerRanges(subPatch.getLayer('deletion'), [[2, 0], [3, 1]]);655 assertMarkerRanges(subPatch.getLayer('nonewline'));656 });657 it('truncates the returned buffer at hunk boundaries', function() {658 const {multiFilePatch} = multiFilePatchBuilder()659 .addFilePatch(fp => {660 fp.setOldFile(f => f.path('file.txt'));661 fp.addHunk(h => h.unchanged('0').added('1', '2').unchanged('3'));662 fp.addHunk(h => h.unchanged('7').deleted('8').unchanged('9', '10'));663 })664 .build();665 // diff row 8 = buffer row 9666 const subPatch = multiFilePatch.getPreviewPatchBuffer('file.txt', 8, 4);667 assert.strictEqual(subPatch.getBuffer().getText(), dedent`668 7669 8670 9671 `);672 assertMarkerRanges(subPatch.getLayer('patch'), [[0, 0], [2, 1]]);673 assertMarkerRanges(subPatch.getLayer('hunk'), [[0, 0], [2, 1]]);674 assertMarkerRanges(subPatch.getLayer('unchanged'), [[0, 0], [0, 1]], [[2, 0], [2, 1]]);675 assertMarkerRanges(subPatch.getLayer('addition'));676 assertMarkerRanges(subPatch.getLayer('deletion'), [[1, 0], [1, 1]]);677 assertMarkerRanges(subPatch.getLayer('nonewline'));678 });679 it('excludes zero-length markers from adjacent patches, hunks, and regions', function() {680 const {multiFilePatch} = multiFilePatchBuilder()681 .addFilePatch(fp => {682 fp.setOldFile(f => f.path('mode-change-0.txt'));683 fp.setNewFile(f => f.path('mode-change-0.txt').executable());684 fp.empty();685 })686 .addFilePatch(fp => {687 fp.setOldFile(f => f.path('file.txt'));688 fp.addHunk(h => h.unchanged('0').added('1', '2').unchanged('3'));689 })690 .addFilePatch(fp => {691 fp.setOldFile(f => f.path('mode-change-1.txt').executable());692 fp.setNewFile(f => f.path('mode-change-1.txt'));693 fp.empty();694 })695 .build();696 // diff row 4 = buffer row 3697 const subPatch = multiFilePatch.getPreviewPatchBuffer('file.txt', 4, 4);698 assert.strictEqual(subPatch.getBuffer().getText(), dedent`699 0700 1701 2702 3703 `);704 assertMarkerRanges(subPatch.getLayer('patch'), [[0, 0], [3, 1]]);705 assertMarkerRanges(subPatch.getLayer('hunk'), [[0, 0], [3, 1]]);706 assertMarkerRanges(subPatch.getLayer('unchanged'), [[0, 0], [0, 1]], [[3, 0], [3, 1]]);707 assertMarkerRanges(subPatch.getLayer('addition'), [[1, 0], [2, 1]]);708 assertMarkerRanges(subPatch.getLayer('deletion'));709 assertMarkerRanges(subPatch.getLayer('nonewline'));710 });711 it('logs and returns an empty buffer when called with invalid arguments', function() {712 sinon.stub(console, 'error');713 const {multiFilePatch} = multiFilePatchBuilder().build();714 const subPatch = multiFilePatch.getPreviewPatchBuffer('file.txt', 6, 4);715 assert.strictEqual(subPatch.getBuffer().getText(), '');716 // eslint-disable-next-line no-console717 assert.isTrue(console.error.called);718 });719 });720 describe('diff position translation', function() {721 it('offsets rows in the first hunk by the first hunk header', function() {722 const {multiFilePatch} = multiFilePatchBuilder()723 .addFilePatch(fp => {724 fp.setOldFile(f => f.path('file.txt'));725 fp.addHunk(h => {726 h.unchanged('0 (1)').added('1 (2)', '2 (3)').deleted('3 (4)', '4 (5)', '5 (6)').unchanged('6 (7)');727 });728 })729 .build();730 assert.strictEqual(multiFilePatch.getBufferRowForDiffPosition('file.txt', 1), 0);731 assert.strictEqual(multiFilePatch.getBufferRowForDiffPosition('file.txt', 7), 6);732 });733 it('offsets rows by the number of hunks before the diff row', function() {734 const {multiFilePatch} = multiFilePatchBuilder()735 .addFilePatch(fp => {736 fp.setOldFile(f => f.path('file.txt'));737 fp.addHunk(h => h.unchanged('0 (1)').added('1 (2)', '2 (3)').deleted('3 (4)').unchanged('4 (5)'));738 fp.addHunk(h => h.unchanged('5 (7)').added('6 (8)', '7 (9)', '8 (10)').unchanged('9 (11)'));739 fp.addHunk(h => h.unchanged('10 (13)').deleted('11 (14)').unchanged('12 (15)'));740 })741 .build();742 assert.strictEqual(multiFilePatch.getBufferRowForDiffPosition('file.txt', 7), 5);743 assert.strictEqual(multiFilePatch.getBufferRowForDiffPosition('file.txt', 11), 9);744 assert.strictEqual(multiFilePatch.getBufferRowForDiffPosition('file.txt', 13), 10);745 assert.strictEqual(multiFilePatch.getBufferRowForDiffPosition('file.txt', 15), 12);746 });747 it('resets the offset at the start of each file patch', function() {748 const {multiFilePatch} = multiFilePatchBuilder()749 .addFilePatch(fp => {750 fp.setOldFile(f => f.path('0.txt'));751 fp.addHunk(h => h.unchanged('0 (1)').added('1 (2)', '2 (3)').unchanged('3 (4)')); // Offset +1752 fp.addHunk(h => h.unchanged('4 (6)').deleted('5 (7)', '6 (8)', '7 (9)').unchanged('8 (10)')); // Offset +2753 fp.addHunk(h => h.unchanged('9 (12)').deleted('10 (13)').unchanged('11 (14)')); // Offset +3754 })755 .addFilePatch(fp => {756 fp.setOldFile(f => f.path('1.txt'));757 fp.addHunk(h => h.unchanged('12 (1)').added('13 (2)').unchanged('14 (3)')); // Offset +1758 fp.addHunk(h => h.unchanged('15 (5)').deleted('16 (6)', '17 (7)', '18 (8)').unchanged('19 (9)')); // Offset +2759 })760 .addFilePatch(fp => {761 fp.setOldFile(f => f.path('2.txt'));762 fp.addHunk(h => h.unchanged('20 (1)').added('21 (2)', '22 (3)', '23 (4)', '24 (5)').unchanged('25 (6)')); // Offset +1763 fp.addHunk(h => h.unchanged('26 (8)').deleted('27 (9)', '28 (10)').unchanged('29 (11)')); // Offset +2764 fp.addHunk(h => h.unchanged('30 (13)').added('31 (14)').unchanged('32 (15)')); // Offset +3765 })766 .build();767 assert.strictEqual(multiFilePatch.getBufferRowForDiffPosition('0.txt', 1), 0);768 assert.strictEqual(multiFilePatch.getBufferRowForDiffPosition('0.txt', 4), 3);769 assert.strictEqual(multiFilePatch.getBufferRowForDiffPosition('0.txt', 6), 4);770 assert.strictEqual(multiFilePatch.getBufferRowForDiffPosition('0.txt', 10), 8);771 assert.strictEqual(multiFilePatch.getBufferRowForDiffPosition('0.txt', 12), 9);772 assert.strictEqual(multiFilePatch.getBufferRowForDiffPosition('0.txt', 14), 11);773 assert.strictEqual(multiFilePatch.getBufferRowForDiffPosition('1.txt', 1), 12);774 assert.strictEqual(multiFilePatch.getBufferRowForDiffPosition('1.txt', 3), 14);775 assert.strictEqual(multiFilePatch.getBufferRowForDiffPosition('1.txt', 5), 15);776 assert.strictEqual(multiFilePatch.getBufferRowForDiffPosition('1.txt', 9), 19);777 assert.strictEqual(multiFilePatch.getBufferRowForDiffPosition('2.txt', 1), 20);778 assert.strictEqual(multiFilePatch.getBufferRowForDiffPosition('2.txt', 6), 25);779 assert.strictEqual(multiFilePatch.getBufferRowForDiffPosition('2.txt', 8), 26);780 assert.strictEqual(multiFilePatch.getBufferRowForDiffPosition('2.txt', 11), 29);781 assert.strictEqual(multiFilePatch.getBufferRowForDiffPosition('2.txt', 13), 30);782 assert.strictEqual(multiFilePatch.getBufferRowForDiffPosition('2.txt', 15), 32);783 });784 it('set the offset for diff-gated file patch upon expanding', function() {785 const {multiFilePatch} = multiFilePatchBuilder()786 .addFilePatch(fp => {787 fp.setOldFile(f => f.path('1.txt'));788 fp.addHunk(h => h.unchanged('0 (1)').added('1 (2)', '2 (3)').deleted('3 (4)').unchanged('4 (5)'));789 fp.addHunk(h => h.unchanged('5 (7)').added('6 (8)', '7 (9)', '8 (10)').unchanged('9 (11)'));790 fp.addHunk(h => h.unchanged('10 (13)').deleted('11 (14)').unchanged('12 (15)'));791 fp.renderStatus(DEFERRED);792 })793 .build();794 assert.isTrue(multiFilePatch.isDiffRowOffsetIndexEmpty('1.txt'));795 const [fp] = multiFilePatch.getFilePatches();796 multiFilePatch.expandFilePatch(fp);797 assert.isFalse(multiFilePatch.isDiffRowOffsetIndexEmpty('1.txt'));798 assert.strictEqual(multiFilePatch.getBufferRowForDiffPosition('1.txt', 11), 9);799 });800 it('does not reset the offset for normally collapsed file patch upon expanding', function() {801 const {multiFilePatch} = multiFilePatchBuilder()802 .addFilePatch(fp => {803 fp.setOldFile(f => f.path('0.txt'));804 fp.addHunk(h => h.oldRow(1).unchanged('0-0').deleted('0-1', '0-2').unchanged('0-3'));805 })806 .build();807 const [fp] = multiFilePatch.getFilePatches();808 const stub = sinon.stub(multiFilePatch, 'populateDiffRowOffsetIndices');809 multiFilePatch.collapseFilePatch(fp);810 assert.strictEqual(multiFilePatch.getBuffer().getText(), '');811 multiFilePatch.expandFilePatch(fp);812 assert.isFalse(stub.called);813 });814 it('returns null when called with an unrecognized filename', function() {815 sinon.stub(console, 'error');816 const {multiFilePatch} = multiFilePatchBuilder().build();817 assert.isNull(multiFilePatch.getBufferRowForDiffPosition('file.txt', 1));818 // eslint-disable-next-line no-console819 assert.isTrue(console.error.called);820 });821 it('returns null when called with an out of range diff row', function() {822 sinon.stub(console, 'error');823 const {multiFilePatch} = multiFilePatchBuilder()824 .addFilePatch(fp => {825 fp.setOldFile(f => f.path('file.txt'));826 fp.addHunk(h => {827 h.unchanged('0').added('1').unchanged('2');828 });829 })830 .build();831 assert.isNull(multiFilePatch.getBufferRowForDiffPosition('file.txt', 5));832 // eslint-disable-next-line no-console833 assert.isTrue(console.error.called);834 });835 });836 describe('collapsing and expanding file patches', function() {837 function hunk({index, start, last}) {838 return {839 startRow: start, endRow: start + 3,840 header: '@@ -1,4 +1,2 @@',841 regions: [842 {kind: 'unchanged', string: ` ${index}-0\n`, range: [[start, 0], [start, 3]]},843 {kind: 'deletion', string: `-${index}-1\n-${index}-2\n`, range: [[start + 1, 0], [start + 2, 3]]},844 {kind: 'unchanged', string: ` ${index}-3${last ? '' : '\n'}`, range: [[start + 3, 0], [start + 3, 3]]},845 ],846 };847 }848 function patchTextForIndexes(indexes) {849 return indexes.map(index => {850 return dedent`851 ${index}-0852 ${index}-1853 ${index}-2854 ${index}-3855 `;856 }).join('\n');857 }858 describe('when there is a single file patch', function() {859 it('collapses and expands the only file patch', function() {860 const {multiFilePatch} = multiFilePatchBuilder()861 .addFilePatch(fp => {862 fp.setOldFile(f => f.path('0.txt'));863 fp.addHunk(h => h.oldRow(1).unchanged('0-0').deleted('0-1', '0-2').unchanged('0-3'));864 })865 .build();866 const [fp0] = multiFilePatch.getFilePatches();867 multiFilePatch.collapseFilePatch(fp0);868 assert.strictEqual(multiFilePatch.getBuffer().getText(), '');869 assertInFilePatch(fp0, multiFilePatch.getBuffer()).hunks();870 multiFilePatch.expandFilePatch(fp0);871 assert.strictEqual(multiFilePatch.getBuffer().getText(), patchTextForIndexes([0]));872 assertInFilePatch(fp0, multiFilePatch.getBuffer()).hunks(hunk({index: 0, start: 0, last: true}));873 });874 });875 describe('when there are multiple file patches', function() {876 let multiFilePatch, fp0, fp1, fp2, fp3;877 beforeEach(function() {878 const {multiFilePatch: mfp} = multiFilePatchBuilder()879 .addFilePatch(fp => {880 fp.setOldFile(f => f.path('0.txt'));881 fp.addHunk(h => h.oldRow(1).unchanged('0-0').deleted('0-1', '0-2').unchanged('0-3'));882 })883 .addFilePatch(fp => {884 fp.setOldFile(f => f.path('1.txt'));885 fp.addHunk(h => h.oldRow(1).unchanged('1-0').deleted('1-1', '1-2').unchanged('1-3'));886 })887 .addFilePatch(fp => {888 fp.setOldFile(f => f.path('2.txt'));889 fp.addHunk(h => h.oldRow(1).unchanged('2-0').deleted('2-1', '2-2').unchanged('2-3'));890 })891 .addFilePatch(fp => {892 fp.setOldFile(f => f.path('3.txt'));893 fp.addHunk(h => h.oldRow(1).unchanged('3-0').deleted('3-1', '3-2').unchanged('3-3'));894 })895 .build();896 multiFilePatch = mfp;897 const patches = multiFilePatch.getFilePatches();898 fp0 = patches[0];899 fp1 = patches[1];900 fp2 = patches[2];901 fp3 = patches[3];902 });903 it('collapses and expands the first file patch with all following expanded', function() {904 multiFilePatch.collapseFilePatch(fp0);905 assert.strictEqual(multiFilePatch.getBuffer().getText(), patchTextForIndexes([1, 2, 3]));906 assertInFilePatch(fp0, multiFilePatch.getBuffer()).hunks();907 assertInFilePatch(fp1, multiFilePatch.getBuffer()).hunks(hunk({index: 1, start: 0}));908 assertInFilePatch(fp2, multiFilePatch.getBuffer()).hunks(hunk({index: 2, start: 4}));909 assertInFilePatch(fp3, multiFilePatch.getBuffer()).hunks(hunk({index: 3, start: 8, last: true}));910 multiFilePatch.expandFilePatch(fp0);911 assert.strictEqual(multiFilePatch.getBuffer().getText(), patchTextForIndexes([0, 1, 2, 3]));912 assertInFilePatch(fp0, multiFilePatch.getBuffer()).hunks(hunk({index: 0, start: 0}));913 assertInFilePatch(fp1, multiFilePatch.getBuffer()).hunks(hunk({index: 1, start: 4}));914 assertInFilePatch(fp2, multiFilePatch.getBuffer()).hunks(hunk({index: 2, start: 8}));915 assertInFilePatch(fp3, multiFilePatch.getBuffer()).hunks(hunk({index: 3, start: 12, last: true}));916 });917 it('collapses and expands an intermediate file patch while all previous patches are collapsed', function() {918 // collapse pervious files919 multiFilePatch.collapseFilePatch(fp0);920 multiFilePatch.collapseFilePatch(fp1);921 // collapse intermediate file922 multiFilePatch.collapseFilePatch(fp2);923 assert.strictEqual(multiFilePatch.getBuffer().getText(), patchTextForIndexes([3]));924 assertInFilePatch(fp0, multiFilePatch.getBuffer()).hunks();925 assertInFilePatch(fp1, multiFilePatch.getBuffer()).hunks();926 assertInFilePatch(fp2, multiFilePatch.getBuffer()).hunks();927 assertInFilePatch(fp3, multiFilePatch.getBuffer()).hunks(hunk({index: 3, start: 0, last: true}));928 multiFilePatch.expandFilePatch(fp2);929 assert.strictEqual(multiFilePatch.getBuffer().getText(), patchTextForIndexes([2, 3]));930 assertInFilePatch(fp0, multiFilePatch.getBuffer()).hunks();931 assertInFilePatch(fp1, multiFilePatch.getBuffer()).hunks();932 assertInFilePatch(fp2, multiFilePatch.getBuffer()).hunks(hunk({index: 2, start: 0}));933 assertInFilePatch(fp3, multiFilePatch.getBuffer()).hunks(hunk({index: 3, start: 4, last: true}));934 });935 it('collapses and expands an intermediate file patch while all following patches are collapsed', function() {936 // collapse following files937 multiFilePatch.collapseFilePatch(fp2);938 multiFilePatch.collapseFilePatch(fp3);939 // collapse intermediate file940 multiFilePatch.collapseFilePatch(fp1);941 assert.strictEqual(multiFilePatch.getBuffer().getText(), patchTextForIndexes([0]));942 assertInFilePatch(fp0, multiFilePatch.getBuffer()).hunks(hunk({index: 0, start: 0, last: true}));943 assertInFilePatch(fp1, multiFilePatch.getBuffer()).hunks();944 assertInFilePatch(fp2, multiFilePatch.getBuffer()).hunks();945 assertInFilePatch(fp3, multiFilePatch.getBuffer()).hunks();946 multiFilePatch.expandFilePatch(fp1);947 assert.strictEqual(multiFilePatch.getBuffer().getText(), patchTextForIndexes([0, 1]));948 assertInFilePatch(fp0, multiFilePatch.getBuffer()).hunks(hunk({index: 0, start: 0}));949 assertInFilePatch(fp1, multiFilePatch.getBuffer()).hunks(hunk({index: 1, start: 4, last: true}));950 assertInFilePatch(fp2, multiFilePatch.getBuffer()).hunks();951 assertInFilePatch(fp3, multiFilePatch.getBuffer()).hunks();952 });953 it('collapses and expands a file patch with uncollapsed file patches before and after it', function() {954 multiFilePatch.collapseFilePatch(fp2);955 assert.strictEqual(multiFilePatch.getBuffer().getText(), patchTextForIndexes([0, 1, 3]));956 assertInFilePatch(fp0, multiFilePatch.getBuffer()).hunks(hunk({index: 0, start: 0}));957 assertInFilePatch(fp1, multiFilePatch.getBuffer()).hunks(hunk({index: 1, start: 4}));958 assertInFilePatch(fp2, multiFilePatch.getBuffer()).hunks();959 assertInFilePatch(fp3, multiFilePatch.getBuffer()).hunks(hunk({index: 3, start: 8, last: true}));960 multiFilePatch.expandFilePatch(fp2);961 assert.strictEqual(multiFilePatch.getBuffer().getText(), patchTextForIndexes([0, 1, 2, 3]));962 assertInFilePatch(fp0, multiFilePatch.getBuffer()).hunks(hunk({index: 0, start: 0}));963 assertInFilePatch(fp1, multiFilePatch.getBuffer()).hunks(hunk({index: 1, start: 4}));964 assertInFilePatch(fp2, multiFilePatch.getBuffer()).hunks(hunk({index: 2, start: 8}));965 assertInFilePatch(fp3, multiFilePatch.getBuffer()).hunks(hunk({index: 3, start: 12, last: true}));966 });967 it('collapses and expands the final file patch with all previous expanded', function() {968 multiFilePatch.collapseFilePatch(fp3);969 assert.strictEqual(multiFilePatch.getBuffer().getText(), patchTextForIndexes([0, 1, 2]));970 assertInFilePatch(fp0, multiFilePatch.getBuffer()).hunks(hunk({index: 0, start: 0}));971 assertInFilePatch(fp1, multiFilePatch.getBuffer()).hunks(hunk({index: 1, start: 4}));972 assertInFilePatch(fp2, multiFilePatch.getBuffer()).hunks(hunk({index: 2, start: 8, last: true}));973 assertInFilePatch(fp3, multiFilePatch.getBuffer()).hunks();974 multiFilePatch.expandFilePatch(fp3);975 assert.strictEqual(multiFilePatch.getBuffer().getText(), patchTextForIndexes([0, 1, 2, 3]));976 assertInFilePatch(fp0, multiFilePatch.getBuffer()).hunks(hunk({index: 0, start: 0}));977 assertInFilePatch(fp1, multiFilePatch.getBuffer()).hunks(hunk({index: 1, start: 4}));978 assertInFilePatch(fp2, multiFilePatch.getBuffer()).hunks(hunk({index: 2, start: 8}));979 assertInFilePatch(fp3, multiFilePatch.getBuffer()).hunks(hunk({index: 3, start: 12, last: true}));980 });981 it('collapses and expands the final two file patches', function() {982 multiFilePatch.collapseFilePatch(fp3);983 multiFilePatch.collapseFilePatch(fp2);984 assert.strictEqual(multiFilePatch.getBuffer().getText(), patchTextForIndexes([0, 1]));985 assertInFilePatch(fp0, multiFilePatch.getBuffer()).hunks(hunk({index: 0, start: 0}));986 assertInFilePatch(fp1, multiFilePatch.getBuffer()).hunks(hunk({index: 1, start: 4, last: true}));987 assertInFilePatch(fp2, multiFilePatch.getBuffer()).hunks();988 assertInFilePatch(fp3, multiFilePatch.getBuffer()).hunks();989 multiFilePatch.expandFilePatch(fp3);990 assert.strictEqual(multiFilePatch.getBuffer().getText(), patchTextForIndexes([0, 1, 3]));991 assertInFilePatch(fp0, multiFilePatch.getBuffer()).hunks(hunk({index: 0, start: 0}));992 assertInFilePatch(fp1, multiFilePatch.getBuffer()).hunks(hunk({index: 1, start: 4}));993 assertInFilePatch(fp2, multiFilePatch.getBuffer()).hunks();994 assertInFilePatch(fp3, multiFilePatch.getBuffer()).hunks(hunk({index: 3, start: 8, last: true}));995 multiFilePatch.expandFilePatch(fp2);996 assert.strictEqual(multiFilePatch.getBuffer().getText(), patchTextForIndexes([0, 1, 2, 3]));997 assertInFilePatch(fp0, multiFilePatch.getBuffer()).hunks(hunk({index: 0, start: 0}));998 assertInFilePatch(fp1, multiFilePatch.getBuffer()).hunks(hunk({index: 1, start: 4}));999 assertInFilePatch(fp2, multiFilePatch.getBuffer()).hunks(hunk({index: 2, start: 8}));1000 assertInFilePatch(fp3, multiFilePatch.getBuffer()).hunks(hunk({index: 3, start: 12, last: true}));1001 });1002 describe('when all patches are collapsed', function() {1003 beforeEach(function() {1004 multiFilePatch.collapseFilePatch(fp0);1005 multiFilePatch.collapseFilePatch(fp1);1006 multiFilePatch.collapseFilePatch(fp2);1007 multiFilePatch.collapseFilePatch(fp3);1008 });1009 it('expands the first file patch', function() {1010 assert.strictEqual(multiFilePatch.getBuffer().getText(), '');1011 multiFilePatch.expandFilePatch(fp0);1012 assert.strictEqual(multiFilePatch.getBuffer().getText(), patchTextForIndexes([0]));1013 assertInFilePatch(fp0, multiFilePatch.getBuffer()).hunks(hunk({index: 0, start: 0, last: true}));1014 assertInFilePatch(fp1, multiFilePatch.getBuffer()).hunks();1015 assertInFilePatch(fp2, multiFilePatch.getBuffer()).hunks();1016 assertInFilePatch(fp3, multiFilePatch.getBuffer()).hunks();1017 });1018 it('expands a non-first file patch', function() {1019 assert.strictEqual(multiFilePatch.getBuffer().getText(), '');1020 multiFilePatch.expandFilePatch(fp2);1021 assert.strictEqual(multiFilePatch.getBuffer().getText(), patchTextForIndexes([2]));1022 assertInFilePatch(fp0, multiFilePatch.getBuffer()).hunks();1023 assertInFilePatch(fp1, multiFilePatch.getBuffer()).hunks();1024 assertInFilePatch(fp2, multiFilePatch.getBuffer()).hunks(hunk({index: 2, start: 0, last: true}));1025 assertInFilePatch(fp3, multiFilePatch.getBuffer()).hunks();1026 });1027 it('expands the final file patch', function() {1028 assert.strictEqual(multiFilePatch.getBuffer().getText(), '');1029 multiFilePatch.expandFilePatch(fp3);1030 assert.strictEqual(multiFilePatch.getBuffer().getText(), patchTextForIndexes([3]));1031 assertInFilePatch(fp0, multiFilePatch.getBuffer()).hunks();1032 assertInFilePatch(fp1, multiFilePatch.getBuffer()).hunks();1033 assertInFilePatch(fp2, multiFilePatch.getBuffer()).hunks();1034 assertInFilePatch(fp3, multiFilePatch.getBuffer()).hunks(hunk({index: 3, start: 0, last: true}));1035 });1036 it('expands all patches in order', function() {1037 assert.strictEqual(multiFilePatch.getBuffer().getText(), '');1038 multiFilePatch.expandFilePatch(fp0);1039 assertInFilePatch(fp0, multiFilePatch.getBuffer()).hunks(hunk({index: 0, start: 0, last: true}));1040 assertInFilePatch(fp1, multiFilePatch.getBuffer()).hunks();1041 assertInFilePatch(fp2, multiFilePatch.getBuffer()).hunks();1042 assertInFilePatch(fp3, multiFilePatch.getBuffer()).hunks();1043 multiFilePatch.expandFilePatch(fp1);1044 assertInFilePatch(fp0, multiFilePatch.getBuffer()).hunks(hunk({index: 0, start: 0}));1045 assertInFilePatch(fp1, multiFilePatch.getBuffer()).hunks(hunk({index: 1, start: 4, last: true}));1046 assertInFilePatch(fp2, multiFilePatch.getBuffer()).hunks();1047 assertInFilePatch(fp3, multiFilePatch.getBuffer()).hunks();1048 multiFilePatch.expandFilePatch(fp2);1049 assertInFilePatch(fp0, multiFilePatch.getBuffer()).hunks(hunk({index: 0, start: 0}));1050 assertInFilePatch(fp1, multiFilePatch.getBuffer()).hunks(hunk({index: 1, start: 4}));1051 assertInFilePatch(fp2, multiFilePatch.getBuffer()).hunks(hunk({index: 2, start: 8, last: true}));1052 assertInFilePatch(fp3, multiFilePatch.getBuffer()).hunks();1053 multiFilePatch.expandFilePatch(fp3);1054 assertInFilePatch(fp0, multiFilePatch.getBuffer()).hunks(hunk({index: 0, start: 0}));1055 assertInFilePatch(fp1, multiFilePatch.getBuffer()).hunks(hunk({index: 1, start: 4}));1056 assertInFilePatch(fp2, multiFilePatch.getBuffer()).hunks(hunk({index: 2, start: 8}));1057 assertInFilePatch(fp3, multiFilePatch.getBuffer()).hunks(hunk({index: 3, start: 12, last: true}));1058 });1059 it('expands all patches in reverse order', function() {1060 assert.strictEqual(multiFilePatch.getBuffer().getText(), '');1061 multiFilePatch.expandFilePatch(fp3);1062 assertInFilePatch(fp0, multiFilePatch.getBuffer()).hunks();1063 assertInFilePatch(fp1, multiFilePatch.getBuffer()).hunks();1064 assertInFilePatch(fp2, multiFilePatch.getBuffer()).hunks();1065 assertInFilePatch(fp3, multiFilePatch.getBuffer()).hunks(hunk({index: 3, start: 0, last: true}));1066 multiFilePatch.expandFilePatch(fp2);1067 assertInFilePatch(fp0, multiFilePatch.getBuffer()).hunks();1068 assertInFilePatch(fp1, multiFilePatch.getBuffer()).hunks();1069 assertInFilePatch(fp2, multiFilePatch.getBuffer()).hunks(hunk({index: 2, start: 0}));1070 assertInFilePatch(fp3, multiFilePatch.getBuffer()).hunks(hunk({index: 3, start: 4, last: true}));1071 multiFilePatch.expandFilePatch(fp1);1072 assertInFilePatch(fp0, multiFilePatch.getBuffer()).hunks();1073 assertInFilePatch(fp1, multiFilePatch.getBuffer()).hunks(hunk({index: 1, start: 0}));1074 assertInFilePatch(fp2, multiFilePatch.getBuffer()).hunks(hunk({index: 2, start: 4}));1075 assertInFilePatch(fp3, multiFilePatch.getBuffer()).hunks(hunk({index: 3, start: 8, last: true}));1076 multiFilePatch.expandFilePatch(fp0);1077 assertInFilePatch(fp0, multiFilePatch.getBuffer()).hunks(hunk({index: 0, start: 0}));1078 assertInFilePatch(fp1, multiFilePatch.getBuffer()).hunks(hunk({index: 1, start: 4}));1079 assertInFilePatch(fp2, multiFilePatch.getBuffer()).hunks(hunk({index: 2, start: 8}));1080 assertInFilePatch(fp3, multiFilePatch.getBuffer()).hunks(hunk({index: 3, start: 12, last: true}));1081 });1082 });1083 it('is deterministic regardless of the order in which collapse and expand operations are performed', function() {1084 this.timeout(60000);1085 const patches = multiFilePatch.getFilePatches();1086 function expectVisibleAfter(ops, i) {1087 return ops.reduce((visible, op) => (op.index === i ? op.visibleAfter : visible), true);1088 }1089 const operations = [];1090 for (let i = 0; i < patches.length; i++) {1091 operations.push({1092 index: i,1093 visibleAfter: false,1094 name: `collapse fp${i}`,1095 canHappenAfter: ops => expectVisibleAfter(ops, i),1096 action: () => multiFilePatch.collapseFilePatch(patches[i]),1097 });1098 operations.push({1099 index: i,1100 visibleAfter: true,1101 name: `expand fp${i}`,1102 canHappenAfter: ops => !expectVisibleAfter(ops, i),1103 action: () => multiFilePatch.expandFilePatch(patches[i]),1104 });1105 }1106 const operationSequences = [];1107 function generateSequencesAfter(prefix) {1108 const possible = operations1109 .filter(op => !prefix.includes(op))1110 .filter(op => op.canHappenAfter(prefix));1111 if (possible.length === 0) {1112 operationSequences.push(prefix);1113 } else {1114 for (const next of possible) {1115 generateSequencesAfter([...prefix, next]);1116 }1117 }1118 }1119 generateSequencesAfter([]);1120 for (const sequence of operationSequences) {1121 // Uncomment to see which sequence is causing problems1122 // console.log(sequence.map(op => op.name).join(' -> '));1123 // Reset to the all-expanded state1124 multiFilePatch.expandFilePatch(fp0);1125 multiFilePatch.expandFilePatch(fp1);1126 multiFilePatch.expandFilePatch(fp2);1127 multiFilePatch.expandFilePatch(fp3);1128 // Perform the operations1129 for (const operation of sequence) {1130 operation.action();1131 }1132 // Ensure the TextBuffer and Markers are in the expected states1133 const visibleIndexes = [];1134 for (let i = 0; i < patches.length; i++) {1135 if (patches[i].getRenderStatus().isVisible()) {1136 visibleIndexes.push(i);1137 }1138 }1139 const lastVisibleIndex = Math.max(...visibleIndexes);1140 assert.strictEqual(multiFilePatch.getBuffer().getText(), patchTextForIndexes(visibleIndexes));1141 let start = 0;1142 for (let i = 0; i < patches.length; i++) {1143 const patchAssertions = assertInFilePatch(patches[i], multiFilePatch.getBuffer());1144 if (patches[i].getRenderStatus().isVisible()) {1145 patchAssertions.hunks(hunk({index: i, start, last: lastVisibleIndex === i}));1146 start += 4;1147 } else {1148 patchAssertions.hunks();1149 }1150 }1151 }1152 });1153 });1154 describe('when a file patch has no content', function() {1155 it('collapses and expands', function() {1156 const {multiFilePatch} = multiFilePatchBuilder()1157 .addFilePatch(fp => {1158 fp.setOldFile(f => f.path('0.txt').executable());1159 fp.setNewFile(f => f.path('0.txt'));1160 fp.empty();1161 })1162 .build();1163 assert.strictEqual(multiFilePatch.getBuffer().getText(), '');1164 const [fp0] = multiFilePatch.getFilePatches();1165 multiFilePatch.collapseFilePatch(fp0);1166 assert.strictEqual(multiFilePatch.getBuffer().getText(), '');1167 assertInFilePatch(fp0, multiFilePatch.getBuffer()).hunks();1168 assert.deepEqual(fp0.getMarker().getRange().serialize(), [[0, 0], [0, 0]]);1169 assert.isTrue(fp0.getMarker().isValid());1170 assert.isFalse(fp0.getMarker().isDestroyed());1171 multiFilePatch.expandFilePatch(fp0);1172 assert.strictEqual(multiFilePatch.getBuffer().getText(), '');1173 assertInFilePatch(fp0, multiFilePatch.getBuffer()).hunks();1174 assert.deepEqual(fp0.getMarker().getRange().serialize(), [[0, 0], [0, 0]]);1175 assert.isTrue(fp0.getMarker().isValid());1176 assert.isFalse(fp0.getMarker().isDestroyed());1177 });1178 it('does not insert a trailing newline when expanding a final content-less patch', function() {1179 const {multiFilePatch} = multiFilePatchBuilder()1180 .addFilePatch(fp => {1181 fp.setOldFile(f => f.path('0.txt'));1182 fp.addHunk(h => h.unchanged('0').added('1').unchanged('2'));1183 })1184 .addFilePatch(fp => {1185 fp.setOldFile(f => f.path('1.txt').executable());1186 fp.setNewFile(f => f.path('1.txt'));1187 fp.empty();1188 })1189 .build();1190 const [fp0, fp1] = multiFilePatch.getFilePatches();1191 assert.isTrue(fp1.getRenderStatus().isVisible());1192 assert.strictEqual(multiFilePatch.getBuffer().getText(), dedent`1193 01194 11195 21196 `);1197 assert.deepEqual(fp0.getMarker().getRange().serialize(), [[0, 0], [2, 1]]);1198 assert.deepEqual(fp1.getMarker().getRange().serialize(), [[2, 1], [2, 1]]);1199 multiFilePatch.collapseFilePatch(fp1);1200 assert.isFalse(fp1.getRenderStatus().isVisible());1201 assert.strictEqual(multiFilePatch.getBuffer().getText(), dedent`1202 01203 11204 21205 `);1206 assert.deepEqual(fp0.getMarker().getRange().serialize(), [[0, 0], [2, 1]]);1207 assert.deepEqual(fp1.getMarker().getRange().serialize(), [[2, 1], [2, 1]]);1208 multiFilePatch.expandFilePatch(fp1);1209 assert.isTrue(fp1.getRenderStatus().isVisible());1210 assert.strictEqual(multiFilePatch.getBuffer().getText(), dedent`1211 01212 11213 21214 `);1215 assert.deepEqual(fp0.getMarker().getRange().serialize(), [[0, 0], [2, 1]]);1216 assert.deepEqual(fp1.getMarker().getRange().serialize(), [[2, 1], [2, 1]]);1217 });1218 });1219 });...

Full Screen

Full Screen

server-tests.js

Source:server-tests.js Github

copy

Full Screen

...105 onComplete();106 }107 }108 // from Buffer (async)109 bufferData.getBuffer(function (error, buffer) {110 testBuffer(error, buffer, 'getBuffer from Buffer async');111 });112 // from Buffer (sync)113 testBuffer(null, bufferData.getBuffer(), 'getBuffer from Buffer sync');114 // from ArrayBuffer (async)115 arrayBufferData.getBuffer(function (error, buffer) {116 testBuffer(error, buffer, 'getBuffer from ArrayBuffer async');117 });118 // from ArrayBuffer (sync)119 testBuffer(null, arrayBufferData.getBuffer(), 'getBuffer from ArrayBuffer sync');120 // from binary (async)121 binaryData.getBuffer(function (error, buffer) {122 testBuffer(error, buffer, 'getBuffer from binary async');123 });124 // from binary (sync)125 testBuffer(null, binaryData.getBuffer(), 'getBuffer from binary sync');126 // from data URI (async)127 dataUriData.getBuffer(function (error, buffer) {128 testBuffer(error, buffer, 'getBuffer from data URI async');129 });130 // from data URI (sync)131 testBuffer(null, dataUriData.getBuffer(), 'getBuffer from data URI sync');132 // from URL (async)133 urlData.getBuffer(function (error, buffer) {134 testBuffer(error, buffer, 'getBuffer from URL async');135 });136 // from URL (sync)137 testBuffer(null, urlData.getBuffer(), 'getBuffer from URL sync');138 // from filepath (async)139 filePathData.getBuffer(function (error, buffer) {140 testBuffer(error, buffer, 'getBuffer filepath async');141 });142 // from filepath (sync)143 testBuffer(null, filePathData.getBuffer(), 'getBuffer filepath sync');144});145// getDataUri146Tinytest.addAsync('cfs-data - server - getDataUri', function(test, onComplete) {147 var total = 12, done = 0;148 function testURI(error, uri, testType) {149 test.isFalse(!!error, testType + ' got error: ' + (error && error.message));150 test.equal(typeof uri, "string", testType + ' got no URI string');151 test.equal(uri, 'data:text/plain;base64,SGVsbG8gV29ybGQ=', testType + ' got invalid URI');152 done++;153 if (total === done) {154 onComplete();155 }156 }157 // from Buffer (async)...

Full Screen

Full Screen

photooxy.js

Source:photooxy.js Github

copy

Full Screen

1__path = process.cwd()2const express = require('express')3var router = express.Router();4const fs = require('fs')5const fetch = require('node-fetch')6const { photoXy_1, photoXy_2 } = require('../scraper/photooxy')7const UrlPhotooxy = {8 shadow: 'https://photooxy.com/logo-and-text-effects/shadow-text-effect-in-the-sky-394.html',9 captain_amerika: 'https://photooxy.com/captain-america-text-generator-403.html',10 cup: 'https://photooxy.com/logo-and-text-effects/write-text-on-the-cup-392.html',11 romantic: 'https://photooxy.com/logo-and-text-effects/romantic-messages-for-your-loved-one-391.html',12 smoke: 'https://photooxy.com/other-design/create-an-easy-smoke-type-effect-390.html',13 burn_paper: 'https://photooxy.com/logo-and-text-effects/write-text-on-burn-paper-388.html',14 naruto: 'https://photooxy.com/manga-and-anime/make-naruto-banner-online-free-378.html',15 love_message: 'https://photooxy.com/logo-and-text-effects/create-a-picture-of-love-message-377.html',16 tik_tok: 'https://photooxy.com/logo-and-text-effects/make-tik-tok-text-effect-375.html',17 flower_heart: 'https://photooxy.com/logo-and-text-effects/text-inside-the-flower-heart-369.html',18 wodden_board: 'https://photooxy.com/logo-and-text-effects/writing-on-wooden-boards-368.html',19 glowing_neon: 'https://photooxy.com/logo-and-text-effects/make-smoky-neon-glow-effect-343.html'20}21router.get('/photooxy1', async (req, res) => {22 var text = req.query.text23 var link = req.query.link24 if (!text) return res.json({ message: 'masukan parameter Text' })25 if (!link) return res.json({ message: 'masukan parameter Link' })26 var hasil = await photoXy_1(link, text)27 try {28 var Buffer = await fetch(hasil, {29 headers: {30 "User-Agent": "Opera/9.80 (X11; Linux i686; U; ru) Presto/2.8.131 Version/11.11"31 }32 })33 var getBuffer = await Buffer.buffer()34 await fs.writeFileSync(__path + '/tmp/image.jpg', getBuffer)35 res.sendFile(__path + '/tmp/image.jpg')36 } catch(err) {37 console.log(err)38 res.json({ message: 'Ups, error' })39 }40})41router.get('/photooxy2', async (req, res) => {42 var text = req.query.text43 var text_2 = req.query.text_244 var link = req.query.link45 if (!text) return res.json({ message: 'masukan parameter Text' })46 if (!text_2) return res.json({ message: 'masukan parameter Text' })47 if (!link) return res.json({ message: 'masukan parameter Link' })48 var hasil = await photoXy_2(link, text, text_2)49 try {50 var Buffer = await fetch(hasil, {51 headers: {52 "User-Agent": "Opera/9.80 (X11; Linux i686; U; ru) Presto/2.8.131 Version/11.11"53 }54 })55 var getBuffer = await Buffer.buffer()56 await fs.writeFileSync(__path + '/tmp/image.jpg', getBuffer)57 res.sendFile(__path + '/tmp/image.jpg')58 } catch(err) {59 console.log(err)60 res.json({ message: 'Ups, error' })61 }62})63router.get('/shadow', async (req, res) => {64 var text = req.query.text65 if (!text) return res.json({ message: 'Masukan parameter Text'})66 var img = await fetch(`https://tyz-api.herokuapp.com/photooxy/photooxy1?text=${text}&link=${UrlPhotooxy.shadow}`)67 var getBuffer = await img.buffer()68 await fs.writeFileSync(__path + '/tmp/image.jpg', getBuffer)69 res.sendFile(__path + '/tmp/image.jpg')70})71router.get('/cup', async (req, res) => {72 var text = req.query.text73 if (!text) return res.json({ message: 'Masukan parameter Text'})74 var img = await fetch(`https://tyz-api.herokuapp.com/photooxy/photooxy1?text=${text}&link=${UrlPhotooxy.cup}`)75 var getBuffer = await img.buffer()76 await fs.writeFileSync(__path + '/tmp/image.jpg', getBuffer)77 res.sendFile(__path + '/tmp/image.jpg')78})79router.get('/captain_amerika', async (req, res) => {80 var text = req.query.text81 var text_2 = req.query.text_282 if (!text) return res.json({ message: 'Masukan parameter Text'})83 if (!text_2) return res.json({ message: 'Masukan parameter Text_2'})84 var img = await fetch(`https://tyz-api.herokuapp.com/photooxy/photooxy2?text=${text}&text_2=${text_2}&link=${UrlPhotooxy.captain_amerika}`)85 var getBuffer = await img.buffer()86 await fs.writeFileSync(__path + '/tmp/image.jpg', getBuffer)87 res.sendFile(__path + '/tmp/image.jpg')88})89router.get('/romantic', async (req, res) => {90 var text = req.query.text91 if (!text) return res.json({ message: 'Masukan parameter Text'})92 var img = await fetch(`https://tyz-api.herokuapp.com/photooxy/photooxy1?text=${text}&link=${UrlPhotooxy.romantic}`)93 var getBuffer = await img.buffer()94 await fs.writeFileSync(__path + '/tmp/image.jpg', getBuffer)95 res.sendFile(__path + '/tmp/image.jpg')96})97router.get('/smoke', async (req, res) => {98 var text = req.query.text99 if (!text) return res.json({ message: 'Masukan parameter Text'})100 var img = await fetch(`https://tyz-api.herokuapp.com/photooxy/photooxy1?text=${text}&link=${UrlPhotooxy.smoke}`)101 var getBuffer = await img.buffer()102 await fs.writeFileSync(__path + '/tmp/image.jpg', getBuffer)103 res.sendFile(__path + '/tmp/image.jpg')104})105router.get('/burn_paper', async (req, res) => {106 var text = req.query.text107 if (!text) return res.json({ message: 'Masukan parameter Text'})108 var img = await fetch(`https://tyz-api.herokuapp.com/photooxy/photooxy1?text=${text}&link=${UrlPhotooxy.burn_paper}`)109 var getBuffer = await img.buffer()110 await fs.writeFileSync(__path + '/tmp/image.jpg', getBuffer)111 res.sendFile(__path + '/tmp/image.jpg')112})113router.get('/naruto', async (req, res) => {114 var text = req.query.text115 if (!text) return res.json({ message: 'Masukan parameter Text'})116 var img = await fetch(`https://tyz-api.herokuapp.com/photooxy/photooxy1?text=${text}&link=${UrlPhotooxy.naruto}`)117 var getBuffer = await img.buffer()118 await fs.writeFileSync(__path + '/tmp/image.jpg', getBuffer)119 res.sendFile(__path + '/tmp/image.jpg')120})121router.get('/love_message', async (req, res) => {122 var text = req.query.text123 if (!text) return res.json({ message: 'Masukan parameter Text'})124 var img = await fetch(`https://tyz-api.herokuapp.com/photooxy/photooxy1?text=${text}&link=${UrlPhotooxy.love_message}`)125 var getBuffer = await img.buffer()126 await fs.writeFileSync(__path + '/tmp/image.jpg', getBuffer)127 res.sendFile(__path + '/tmp/image.jpg')128})129router.get('/tik_tok', async (req, res) => {130 var text = req.query.text131 var text_2 = req.query.text_2132 if (!text) return res.json({ message: 'Masukan parameter Text'})133 if (!text_2) return res.json({ message: 'Masukan parameter Text_2'})134 var img = await fetch(`https://tyz-api.herokuapp.com/photooxy/photooxy2?text=${text}&text_2=${text_2}&link=${UrlPhotooxy.tik_tok}`)135 var getBuffer = await img.buffer()136 await fs.writeFileSync(__path + '/tmp/image.jpg', getBuffer)137 res.sendFile(__path + '/tmp/image.jpg')138})139router.get('/flower_heart', async (req, res) => {140 var text = req.query.text141 if (!text) return res.json({ message: 'Masukan parameter Text'})142 var img = await fetch(`https://tyz-api.herokuapp.com/photooxy/photooxy1?text=${text}&link=${UrlPhotooxy.flower_heart}`)143 var getBuffer = await img.buffer()144 await fs.writeFileSync(__path + '/tmp/image.jpg', getBuffer)145 res.sendFile(__path + '/tmp/image.jpg')146})147router.get('/wodden_board', async (req, res) => {148 var text = req.query.text149 if (!text) return res.json({ message: 'Masukan parameter Text'})150 var img = await fetch(`https://tyz-api.herokuapp.com/photooxy/photooxy1?text=${text}&link=${UrlPhotooxy.wodden_board}`)151 var getBuffer = await img.buffer()152 await fs.writeFileSync(__path + '/tmp/image.jpg', getBuffer)153 res.sendFile(__path + '/tmp/image.jpg')154})155router.get('/glowing_neon', async (req, res) => {156 var text = req.query.text157 if (!text) return res.json({ message: 'Masukan parameter Text'})158 var img = await fetch(`https://tyz-api.herokuapp.com/photooxy/photooxy1?text=${text}&link=${UrlPhotooxy.glowing_neon}`)159 var getBuffer = await img.buffer()160 await fs.writeFileSync(__path + '/tmp/image.jpg', getBuffer)161 res.sendFile(__path + '/tmp/image.jpg')162})...

Full Screen

Full Screen

list.js

Source:list.js Github

copy

Full Screen

...35 });36 test.concurrent('lists everything with no args', (): Promise<void> => {37 return runList([], {}, 'no-args', (config, reporter): ?Promise<void> => {38 const rprtr = new BufferReporter({});39 const tree = reporter.getBuffer().slice(-1);40 const children = [{name: 'is-plain-obj@^1.0.0', color: 'dim', shadow: true}];41 const trees = [42 makeTree('left-pad@1.1.3', {color: 'bold'}),43 makeTree('sort-keys@1.1.2', {children, color: 'bold'}),44 makeTree('is-plain-obj@1.1.0'),45 ];46 rprtr.tree('list', trees);47 expect(tree).toEqual(rprtr.getBuffer());48 });49 });50 test.concurrent('respects depth flag', (): Promise<void> => {51 return runList([], {depth: 1}, 'depth-flag', (config, reporter): ?Promise<void> => {52 const rprtr = new BufferReporter({});53 const tree = reporter.getBuffer().slice(-1);54 const trees = [makeTree('sort-keys@1.1.2', {color: 'bold'}), makeTree('is-plain-obj@1.1.0')];55 rprtr.tree('list', trees);56 expect(tree).toEqual(rprtr.getBuffer());57 });58 });59 test.concurrent('accepts an argument', (): Promise<void> => {60 return runList(['is-plain-obj'], {}, 'one-arg', (config, reporter): ?Promise<void> => {61 const rprtr = new BufferReporter({});62 const tree = reporter.getBuffer().slice(-1);63 const trees = [makeTree('is-plain-obj@1.1.0')];64 rprtr.tree('list', trees);65 expect(tree).toEqual(rprtr.getBuffer());66 });67 });68 test.concurrent('accepts a pattern', (): Promise<void> => {69 return runList([], {pattern: 'is-plain-obj'}, 'one-arg', (config, reporter): ?Promise<void> => {70 const rprtr = new BufferReporter({});71 const tree = reporter.getBuffer().slice(-1);72 const trees = [makeTree('is-plain-obj@1.1.0')];73 rprtr.tree('list', trees);74 expect(tree).toEqual(rprtr.getBuffer());75 });76 });77 test.concurrent('should not throw when list is called with resolutions field', (): Promise<void> => {78 return runList([], {}, {source: '', cwd: 'resolutions'}, (config, reporter): ?Promise<void> => {79 const rprtr = new BufferReporter({});80 const tree = reporter.getBuffer().slice(-1);81 const children = [{name: 'left-pad@^1.1.3', color: 'dim', shadow: true}];82 const trees = [makeTree('depA@1.0.0', {children, color: 'bold'}), makeTree('left-pad@1.0.0')];83 rprtr.tree('list', trees);84 expect(tree).toEqual(rprtr.getBuffer());85 });86 });87 test.concurrent('respects depth flag', (): Promise<void> => {88 return runList([], {depth: 1}, 'depth-flag', (config, reporter): ?Promise<void> => {89 const rprtr = new BufferReporter({});90 const tree = reporter.getBuffer().slice(-1);91 const trees = [makeTree('sort-keys@1.1.2', {color: 'bold'}), makeTree('is-plain-obj@1.1.0')];92 rprtr.tree('list', trees);93 expect(tree).toEqual(rprtr.getBuffer());94 });95 });96 test.concurrent('matches exactly without glob in argument', (): Promise<void> => {97 return runList(['gulp'], {}, 'glob-arg', (config, reporter): ?Promise<void> => {98 const rprtr = new BufferReporter({});99 const tree = reporter.getBuffer().slice(-1);100 const trees = [makeTree('gulp@3.9.1', {color: 'bold'})];101 const messageParts = reporter.lang('deprecatedListArgs').split('undefined');102 const output = reporter.getBuffer();103 const hasWarningMessage = output.some(messages => messageParts.indexOf(String(messages.data)) > -1);104 expect(hasWarningMessage).toBe(true);105 rprtr.tree('list', trees);106 expect(tree).toEqual(rprtr.getBuffer());107 });108 });109 test.concurrent('expands a glob in argument', (): Promise<void> => {110 return runList(['gulp*'], {}, 'glob-arg', (config, reporter): ?Promise<void> => {111 const rprtr = new BufferReporter({});112 const tree = reporter.getBuffer().slice(-1);113 const trees = [makeTree('gulp@3.9.1', {color: 'bold'}), makeTree('gulp-babel@6.1.2', {color: 'bold'})];114 rprtr.tree('list', trees);115 expect(tree).toEqual(rprtr.getBuffer());116 });117 });118 test.concurrent('expands a glob in pattern', (): Promise<void> => {119 return runList([], {pattern: 'gulp*'}, 'glob-arg', (config, reporter): ?Promise<void> => {120 const rprtr = new BufferReporter({});121 const tree = reporter.getBuffer().slice(-1);122 const trees = [makeTree('gulp@3.9.1', {color: 'bold'}), makeTree('gulp-babel@6.1.2', {color: 'bold'})];123 rprtr.tree('list', trees);124 expect(tree).toEqual(rprtr.getBuffer());125 });126 });127 test('lists all dependencies when not production', (): Promise<void> => {128 return runList([], {}, 'dev-deps-prod', (config, reporter): ?Promise<void> => {129 expect(reporter.getBuffer()).toMatchSnapshot();130 });131 });132 test('does not list devDependencies when production', (): Promise<void> => {133 const isProduction: $FlowFixMe = require('../../src/constants').isProduction;134 isProduction.mockReturnValue(true);135 return runList([], {}, 'dev-deps-prod', (config, reporter): ?Promise<void> => {136 expect(reporter.getBuffer()).toMatchSnapshot();137 });138 });139 test('getParent should extract a parent object from a hash, if the parent key exists', () => {140 const mockTreesByKey = {};141 mockTreesByKey['parentPkg'] = {142 name: 'parent@1.1.1',143 children: [],144 };145 const res = getParent('parentPkg#childPkg', mockTreesByKey);146 expect(res instanceof Object).toBe(true);147 expect(res.name).toBe('parent@1.1.1');148 expect(res.children.length).toBe(0);149 });150 test('getParent should return undefined if the key does not exist in hash', () => {...

Full Screen

Full Screen

textpro.js

Source:textpro.js Github

copy

Full Screen

...5 switch(command) {6 case 'demon':7 if (!text) throw `Contoh Penggunaan\n${usedPrefix+command} teks`8 result = await meta('https://textpro.me/create-green-horror-style-text-effect-online-1036.html', [text])9 buff = await getBuffer(result)10 conn.sendMessage(m.chat, buff, 'imageMessage', { quoted: m, caption })11 break12 case 'transformer':13 if (!text) throw `Contoh Penggunaan\n${usedPrefix+command} teks`14 result = await meta('https://textpro.me/create-a-transformer-text-effect-online-1035.html', [text])15 buff = await getBuffer(result)16 conn.sendMessage(m.chat, buff, 'imageMessage', { quoted: m, caption })17 break18 case '3dstone':19 if (!text) throw `Contoh Penggunaan\n${usedPrefix+command} teks`20 result = await meta('https://textpro.me/3d-stone-cracked-cool-text-effect-1029.html', [text])21 buff = await getBuffer(result)22 conn.sendMessage(m.chat, buff, 'imageMessage', { quoted: m, caption })23 break24 case 'neon':25 if (!text) throw `Contoh Penggunaan\n${usedPrefix+command} teks`26 result = await meta('https://textpro.me/create-3d-neon-light-text-effect-online-1028.html', [text])27 buff = await getBuffer(result)28 conn.sendMessage(m.chat, buff, 'imageMessage', { quoted: m, caption })29 break30 case 'glitchtext':31 if (!text) throw `Contoh Penggunaan\n${usedPrefix+command} teks`32 result = await meta('https://textpro.me/create-impressive-glitch-text-effects-online-1027.html', [text])33 buff = await getBuffer(result)34 conn.sendMessage(m.chat, buff, 'imageMessage', { quoted: m, caption })35 break36 case 'papercut':37 if (!text) throw `Contoh Penggunaan\n${usedPrefix+command} teks`38 result = await meta('https://textpro.me/create-art-paper-cut-text-effect-online-1022.html', [text])39 buff = await getBuffer(result)40 conn.sendMessage(m.chat, buff, 'imageMessage', { quoted: m, caption })41 break42 case 'gradient':43 if (!text) throw `Contoh Penggunaan\n${usedPrefix+command} teks`44 result = await meta('https://textpro.me/online-3d-gradient-text-effect-generator-1020.html', [text])45 buff = await getBuffer(result)46 conn.sendMessage(m.chat, buff, 'imageMessage', { quoted: m, caption })47 break48 case 'brokenglass':49 if (!text) throw `Contoh Penggunaan\n${usedPrefix+command} teks`50 result = await meta('https://textpro.me/broken-glass-text-effect-free-online-1023.html', [text])51 buff = await getBuffer(result)52 conn.sendMessage(m.chat, buff, 'imageMessage', { quoted: m, caption })53 break54 case '3dmetal':55 if (!text) throw `Contoh Penggunaan\n${usedPrefix+command} teks`56 result = await meta('https://textpro.me/create-a-3d-glossy-metal-text-effect-1019.html', [text])57 buff = await getBuffer(result)58 conn.sendMessage(m.chat, buff, 'imageMessage', { quoted: m, caption })59 break60 case 'magma':61 if (!text) throw `Contoh Penggunaan\n${usedPrefix+command} teks`62 result = await meta('https://textpro.me/create-a-magma-hot-text-effect-online-1030.html', [text])63 buff = await getBuffer(result)64 conn.sendMessage(m.chat, buff, 'imageMessage', { quoted: m, caption })65 break66 case 'glitchtext2':67 if (!text) throw `Contoh Penggunaan\n${usedPrefix+command} teks1|teks2`68 result = await meta('https://textpro.me/create-a-glitch-text-effect-online-free-1026.html', seplit)69 buff = await getBuffer(result)70 conn.sendMessage(m.chat, buff, 'imageMessage', { quoted: m, caption })71 break72 case 'harrypotter':73 if (!text) throw `Contoh Penggunaan\n${usedPrefix+command} teks`74 result = await meta('https://textpro.me/create-harry-potter-text-effect-online-1025.html', [text])75 buff = await getBuffer(result)76 conn.sendMessage(m.chat, buff, 'imageMessage', { quoted: m, caption})77 break78 case 'watercolor':79 if (!text) throw `Contoh Penggunaan\n${usedPrefix+command} teks`80 result = await meta('https://textpro.me/create-a-free-online-watercolor-text-effect-1017.html', [text])81 buff = await getBuffer(result)82 conn.sendMessage(m.chat, buff, 'imageMessage', { quoted: m, caption })83 break84 case 'bpink':85 if (!text) throw `Contoh Penggunaan\n${usedPrefix+command} teks`86 result = await meta('https://textpro.me/create-blackpink-logo-style-online-1001.html', [text])87 buff = await getBuffer(result)88 conn.sendMessage(m.chat, buff, 'imageMessage', { quoted: m, caption })89 break90 case 'pornhub': case 'phlogo':91 if (!text) throw `Contoh Penggunaan\n${usedPrefix+command} teks1|teks2`92 result = await meta('https://textpro.me/pornhub-style-logo-online-generator-free-977.html', seplit)93 buff = await getBuffer(result)94 conn.sendMessage(m.chat, buff, 'imageMessage', { quoted: m, caption })95 break96 case 'captainamerica': case 'camerica':97 if (!text) throw `Contoh Penggunaan\n${usedPrefix+command} teks1|teks2`98 result = await meta('https://textpro.me/create-a-captain-america-text-effect-free-online-1039.html', seplit)99 buff = await getBuffer(result)100 conn.sendMessage(m.chat, buff, 'imageMessage', { quoted: m, caption })101 break102 case 'thunder':103 if (!text) throw `Contoh Penggunaan\n${usedPrefix+command} teks`104 result = await meta('https://textpro.me/online-thunder-text-effect-generator-1031.html', [text])105 buff = await getBuffer(result)106 conn.sendMessage(m.chat, buff, 'imageMessage', { quoted: m, caption })107 break108 case 'berry':109 if (!text) throw `Contoh Penggunaan\n${usedPrefix+command} teks`110 result = await meta('https://textpro.me/create-berry-text-effect-online-free-1033.html', [text])111 buff = await getBuffer(result)112 conn.sendMessage(m.chat, buff, 'imageMessage', { quoted: m, caption })113 break114 case 'underwater':115 if (!text) throw `Contoh Penggunaan\n${usedPrefix+command} teks`116 result = await meta('https://textpro.me/3d-underwater-text-effect-generator-online-1013.html', [text])117 buff = await getBuffer(result)118 conn.sendMessage(m.chat, buff, 'imageMessage', { quoted: m, caption })119 break120 // Tambah sendiri, w capek ajg121 }122}123f = [124 'underwater',125 'berry',126 'thunder',127 'captainamerica',128 'camerica',129'demon',130 'transformer', 131 '3dstone',132 'neon', 133 'glitchtext', 134 'papercut', 135 'gradient',136 'brokenglass',137 '3dbeach', 138 '3dmetal', 139 'magma',140 'glitchtext2',141 'harrypotter',142 'watercolor',143 'bpink',144 'pornhub',145 'phlogo'146 ]147handler.help = f148handler.tags = ['textpro']149handler.command = f150module.exports = handler151async function getBuffer(url) {152fet = await require('node-fetch')(url, { 153headers: {154"user-agent": "GoogleBot"155}156})157res = await fet.buffer()158return res159}160async function meta(url, text) {161return require('zrapi').textpro(url, text)...

Full Screen

Full Screen

addnewgarage.js

Source:addnewgarage.js Github

copy

Full Screen

1import React, { useEffect, useState } from 'react';2import { usePosition } from '../../customHooks/usePosition';3import { bufferValues } from './bufferModel';4import { makeStyles } from '@material-ui/core/styles';5import './addnewgarage.scss';6import { Button } from '@material-ui/core';7import { createNewGarage } from '../../services/services';8import SimpleModal from '../../components/modal/modal';9import ImageUpload from '../../components/imageUpload/imageUpload';10import RenderFields from './renderFields';11const useStyles = makeStyles((theme) => ({12 root: {13 '& .MuiTextField-root': {14 margin: theme.spacing(1),15 width: 200,16 },17 },18 modalPaper: {19 width: 400,20 backgroundColor: theme.palette.background.paper,21 boxShadow: theme.shadows[5],22 padding: theme.spacing(2, 4, 3),23 fontFamily: 'AvenirLight',24 },25 modalButton: {26 background: '#eea44d',27 },28}));29function AddNewGarage() {30 const classes = useStyles();31 const [modelBuffer, setModelBuffer] = useState(bufferValues);32 const [isModalOpen, setIsModalOpen] = useState(true);33 const handleChange = (e, path, index) => {34 const { value } = e.target;35 const data = [...modelBuffer];36 data[index].value = value;37 data[index].validations.isValid = true;38 setModelBuffer(data);39 };40 const position = usePosition();41 const getPosition = {42 latitude: position.latitude,43 longitude: position.longitude,44 };45 useEffect(() => {46 if (position.error) {47 setIsModalOpen(false);48 }49 }, [position, isModalOpen]);50 const saveForm = async (formData) => {51 await createNewGarage(formData).then((res) => {52 console.log(res);53 handleReset();54 });55 };56 const handleSave = () => {57 let getBuffer = [...modelBuffer];58 if (position.error !== null) {59 setIsModalOpen(true);60 }61 if (getBuffer.every((i) => i.value !== '')) {62 const payload = getBuffer.reduce((acc, next) => {63 return {64 ...acc,65 [next.name]: next.value,66 };67 }, {});68 saveForm({69 ...payload,70 ...getPosition,71 });72 } else {73 getBuffer = getBuffer.map((field) => {74 if (field.value === '') {75 field.validations.isValid = false;76 } else {77 field.validations.isValid = true;78 }79 return field;80 });81 setModelBuffer(getBuffer);82 }83 };84 const handleReset = () => {85 let getBuffer = [...modelBuffer];86 getBuffer = getBuffer.map((field) => {87 field.value = '';88 field.validations.isValid = true;89 return field;90 });91 setModelBuffer(getBuffer);92 };93 const modalBody = (94 <div className={classes.modalPaper}>95 <h2 id="simple-modal-title">Allow Geolocation</h2>96 <p id="simple-modal-description">97 If you do not allow we cannot proceed with the form98 </p>99 <Button100 className={classes.modalButton}101 onClick={() => setIsModalOpen(false)}102 >103 Accept104 </Button>105 </div>106 );107 const handleImageUpload = (image) => {108 const getBuffer = [...modelBuffer];109 getBuffer.push({110 name: 'image',111 value: image,112 validations: {113 isValid: true,114 },115 });116 setModelBuffer(getBuffer);117 };118 return (119 <div className="addnewgarage-container">120 <h3>Add New Garage</h3>121 <form className={classes.root} noValidate autoComplete="off">122 <RenderFields handleChange={handleChange} modelBuffer={modelBuffer} />123 </form>124 <ImageUpload cardName="Input Image" onChange={handleImageUpload} />125 <div>126 <Button onClick={handleSave}>Save</Button>127 <Button onClick={handleReset}>Reset</Button>128 </div>129 <SimpleModal130 open={isModalOpen}131 handleClose={() => setIsModalOpen(false)}132 body={modalBody}133 />134 </div>135 );136}...

Full Screen

Full Screen

playAlong.js

Source:playAlong.js Github

copy

Full Screen

...19}2021document.addEventListener('keydown', function (event) {22 if (event.keyCode == 65) { // C23 paPlay(player.getBuffer(), freq[0], 0);24 }25});26document.addEventListener('keydown', function (event) {27 if (event.keyCode == 87) { // C#28 paPlay(player.getBuffer(), freq[1], 0);29 }30});31document.addEventListener('keydown', function (event) {32 if (event.keyCode == 83) { // D33 paPlay(player.getBuffer(), freq[2], 0);34 }35});36document.addEventListener('keydown', function (event) {37 if (event.keyCode == 69) { // Eb38 paPlay(player.getBuffer(), freq[3], 0);39 }40});41document.addEventListener('keydown', function (event) {42 if (event.keyCode == 68) { // E43 paPlay(player.getBuffer(), freq[4], 0);44 }45});46document.addEventListener('keydown', function (event) {47 if (event.keyCode == 70) { // F48 paPlay(player.getBuffer(), freq[5], 0);49 }50});51document.addEventListener('keydown', function (event) {52 if (event.keyCode == 84) { // F#53 paPlay(player.getBuffer(), freq[6], 0);54 }55});56document.addEventListener('keydown', function (event) {57 if (event.keyCode == 71) { // G58 paPlay(player.getBuffer(), freq[7], 0);59 }60});61document.addEventListener('keydown', function (event) {62 if (event.keyCode == 89) { // Ab63 paPlay(player.getBuffer(), freq[8], 0);64 }65});66document.addEventListener('keydown', function (event) {67 if (event.keyCode == 72) { // A68 paPlay(player.getBuffer(), freq[9], 0);69 }70});71document.addEventListener('keydown', function (event) {72 if (event.keyCode == 85) { // Bb73 paPlay(player.getBuffer(), freq[10], 0);74 }75});76document.addEventListener('keydown', function (event) {77 if (event.keyCode == 74) { // B78 paPlay(player.getBuffer(), freq[11], 0);79 }80});81document.addEventListener('keydown', function (event) {82 if (event.keyCode == 75) { // C83 paPlay(player.getBuffer(), freq[12], 0);84 }85});86document.addEventListener('keydown', function (event) {87 if (event.keyCode == 79) { // C#88 paPlay(player.getBuffer(), freq[1]*2, 0);89 }90});91document.addEventListener('keydown', function (event) {92 if (event.keyCode == 76) { // D93 paPlay(player.getBuffer(), freq[2]*2, 0);94 }95});96document.addEventListener('keydown', function (event) {97 if (event.keyCode == 80) { // Eb98 paPlay(player.getBuffer(), freq[3]*2, 0);99 }100});101document.addEventListener('keydown', function (event) {102 if (event.keyCode == 186) { // E103 paPlay(player.getBuffer(), freq[4]*2, 0);104 }105});106document.addEventListener('keydown', function (event) {107 if (event.keyCode == 222) { // F108 paPlay(player.getBuffer(), freq[5]*2, 0);109 }110});111/*document.addEventListener('keydown', function (event) {112 if (event.keyCode == 32) {113 play();114 } ...

Full Screen

Full Screen

jsonwriter.js

Source:jsonwriter.js Github

copy

Full Screen

...21 });22 describe('#writeKey', () => {23 it('should write a key', () => {24 writer.writeKey('hello world');25 writer.getBuffer().should.equal('"hello world":');26 writer.clearBuffer();27 writer.writeKey('hello"world');28 writer.getBuffer().should.equal('"hello\\"world":');29 });30 });31 describe('#writeStringValue', () => {32 it('should write a key', () => {33 writer.writeStringValue('hello world');34 writer.getBuffer().should.equal('"hello world"');35 writer.clearBuffer();36 writer.writeStringValue('hello"world');37 writer.getBuffer().should.equal('"hello\\"world"');38 });39 });40 describe('#writeKeyStringValue', () => {41 it('should write a key', () => {42 writer.writeKeyStringValue('hello world', 'hello world');43 writer.getBuffer().should.equal('"hello world":"hello world"');44 writer.clearBuffer();45 writer.writeKeyStringValue('hello"world', 'hello"world');46 writer.getBuffer().should.equal('"hello\\"world":"hello\\"world"');47 });48 });49 describe('#writeKeyValue', () => {50 it('should write a key', () => {51 writer.writeKeyValue('hello world', '"hello world"');52 writer.getBuffer().should.equal('"hello world":"hello world"');53 writer.clearBuffer();54 writer.writeKeyValue('hello"world', '"hello\\"world"');55 writer.getBuffer().should.equal('"hello\\"world":"hello\\"world"');56 });57 });58 describe('#writeArrayStringValue', () => {59 it('should write a key', () => {60 writer.writeArrayStringValue('hello world');61 writer.getBuffer().should.equal('"hello world"');62 writer.clearBuffer();63 writer.writeArrayStringValue('hello"world');64 writer.getBuffer().should.equal('"hello\\"world"');65 });66 });...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var rewire = require('rewire');2var myModule = rewire('./myModule.js');3var getBuffer = myModule.__get__('getBuffer');4var buffer = getBuffer();5console.log(buffer);6var getBuffer = function() {7 return new Buffer('Hello World!');8}9module.exports.getBuffer = getBuffer;

Full Screen

Using AI Code Generation

copy

Full Screen

1var rewire = require('rewire');2var myModule = rewire('./myModule.js');3var myModuleBuffer = myModule.getBuffer();4console.log(myModuleBuffer);5var rewire = require('rewire');6var myModule = rewire('./myModule.js');7var myModuleBuffer = myModule.getBuffer();8console.log(myModuleBuffer);9var myModule = rewire(__dirname + '/myModule.js');

Full Screen

Using AI Code Generation

copy

Full Screen

1var rewire = require('rewire');2var getBuffer = rewire('./getBuffer.js');3var buffer = getBuffer.__get__('buffer');4console.log(buffer);5var buffer = new Buffer('Hello World');6var getBuffer = function() {7 return buffer;8}9module.exports = getBuffer;

Full Screen

Using AI Code Generation

copy

Full Screen

1var rewire = require('rewire');2var test = rewire('./test');3var getBuffer = test.__get__('getBuffer');4var buffer = getBuffer();5console.log(buffer.toString());6var fs = require('fs');7module.exports = {8 getBuffer: function() {9 return fs.readFileSync('test.txt');10 }11};12var proxyquire = require('proxyquire').noPreserveCache();13var getBuffer = proxyquire('./test', {fs: {readFileSync: function() {return 'test'}}}).getBuffer;14var buffer = getBuffer();15console.log(buffer.toString());

Full Screen

Using AI Code Generation

copy

Full Screen

1const rewire = require('rewire');2const test = rewire('./test.js');3const getBuffer = test.__get__('getBuffer');4const buffer = getBuffer();5console.log(buffer);6module.exports = function getBuffer() {7 return Buffer.from('Hello World');8}

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run rewire automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful