Best JavaScript code snippet using ava
WriteJson.Test.js
Source:WriteJson.Test.js
...64 expect(String(-0)).toBe('0');65 });66 describe('scalars of type', function () {67 it('Boolean', function () {68 writeTest('dataItem_Boolean', true, false);69 });70 it('String', function () {71 writeTest('dataItem_String', 'Hello', 'Hello World! :D');72 writeTest('dataItem_String', 'Hello', 'Iñtërnâtiônà lizætiønâð©');73 });74 it('Double', function () {75 writeTest('dataItem_NumericDouble', 123.456, 1234.56789);76 writeTest('dataItem_NumericDouble', 123.456, (NaN).toString());77 writeTest('dataItem_NumericDouble', 123.456, (Infinity).toString());78 writeTest('dataItem_NumericDouble', 123.456, (-Infinity).toString());79 writeTest('dataItem_NumericDouble', 123.456, 0);80 writeTest('dataItem_NumericDouble', 123.456, -0);81 });82 it('Int32', function () {83 writeTest('dataItem_Numeric32', -1073741824, -36963968);84 });85 it('Int64', function () {86 writeTest('dataItem_Numeric64',87 '-1152921504606846976',88 '-36028797018963968'89 );90 });91 it('Int64NonString', function () {92 writeTest('dataItem_Numeric64',93 '-1152921504606846976',94 3602879701896396895 );96 });97 it('ComplexDouble', function () {98 writeTest('dataItem_Complex',99 {100 real: 1337.73,101 imaginary: -9283.12102 },103 {104 real: 15.789,105 imaginary: -3.1416106 });107 });108 it('Timestamp', function () {109 writeTest('dataItem_Timestamp',110 {111 seconds: '3564057536',112 fraction: '7811758927381448193'113 },114 {115 seconds: '3564057542',116 fraction: '16691056759750171331'117 });118 });119 });120 describe('1D arrays of type', function () {121 it('Boolean', function () {122 writeTest('dataItem_ArrayOfBoolean',123 [true, true, false, true, false],124 [false, false, true, false, true]125 );126 writeTest('dataItem_ArrayOfBoolean',127 [true, true, false, true, false],128 [false, false, true, false, true, false, false, false, true]129 );130 writeTest('dataItem_ArrayOfBoolean',131 [true, true, false, true, false],132 [false, false]133 );134 });135 it('String', function () {136 writeTest('dataItem_ArrayOfString',137 ['Lorem', 'ipsum', 'dolor', 'sit', 'amet'],138 ['My', 'name', 'is', 'slim', 'shady']139 );140 writeTest('dataItem_ArrayOfString',141 ['Lorem', 'ipsum', 'dolor', 'sit', 'amet'],142 'I believe I can fly, I believe I can touch the sky'.split(' ')143 );144 writeTest('dataItem_ArrayOfString',145 ['Lorem', 'ipsum', 'dolor', 'sit', 'amet'],146 ['Iñtërnâtiônà lizætiønâð©', 'is', 'fun']147 );148 });149 it('Double', function () {150 var original = [1.2, 3.4, 5.6, 7.89, 1234.5678];151 var sameSize = ['NaN', '-Infinity', 'Infinity', 0, -0];152 var moreVals = [0.4111973450, 0.7498847177, 0.8094650401, 0.5809188834, 0.4504242667, 0.4247307408, 0.2302642939, 0.3274508043, 0.2481683847, 0.4577604581];153 var lessVals = ['NaN', '-Infinity', 'Infinity'];154 writeTest('dataItem_ArrayOfDouble', original, sameSize);155 writeTest('dataItem_ArrayOfDouble', original, moreVals);156 writeTest('dataItem_ArrayOfDouble', original, lessVals);157 });158 it('Int32', function () {159 var original = [-1000, -10, 42, 9876543, 123];160 var sameSize = [11111, 222, 33, 4444444, 555];161 var moreVals = [552139, -396256, -292658, -795576, 248411, 873904, 994612, 724317, 79111, -849221];162 var lessVals = [-1, 0, 1];163 writeTest('dataItem_ArrayOfInt32', original, sameSize);164 writeTest('dataItem_ArrayOfInt32', original, moreVals);165 writeTest('dataItem_ArrayOfInt32', original, lessVals);166 });167 it('Int64', function () {168 var original = [169 '-8989',170 '9090',171 '36028797018963968',172 '-72057594037927936'173 ];174 var sameSize = ['1', '2', '3', '4'];175 var moreVals = [176 '18014398509481984',177 '36028797018963968',178 '72057594037927936',179 '144115188075855872',180 '288230376151711744',181 '-18014398509481984',182 '-36028797018963968',183 '-72057594037927936',184 '-144115188075855872',185 '-288230376151711744'186 ];187 var lessVals = ['-1', '0', '1'];188 writeTest('dataItem_ArrayOfInt64', original, sameSize);189 writeTest('dataItem_ArrayOfInt64', original, moreVals);190 writeTest('dataItem_ArrayOfInt64', original, lessVals);191 });192 it('ComplexDouble', function () {193 var original = [194 {195 real: 0,196 imaginary: 0197 }, {198 real: 10,199 imaginary: -10200 }, {201 real: 5.045,202 imaginary: -5.67203 }204 ];205 var sameSize = [206 {207 real: 'NaN',208 imaginary: 'NaN'209 }, {210 real: 'Infinity',211 imaginary: 'Infinity'212 }, {213 real: '-Infinity',214 imaginary: '-Infinity'215 }216 ];217 var moreVals = [218 {219 real: 0.917787,220 imaginary: 0.461898221 }, {222 real: 0.832868,223 imaginary: -0.20176365224 }, {225 real: 0.764301,226 imaginary: 0.2267764227 }, {228 real: 0.174925,229 imaginary: -0.0420786230 }, {231 real: 0.83287,232 imaginary: 0.1614564233 }234 ];235 var lessVals = [236 {237 real: -1,238 imaginary: -1239 }, {240 real: 0,241 imaginary: 0242 }, {243 real: 1,244 imaginary: 1245 }246 ];247 // TODO mraj using the following value causes a browser hang248 // var lessVals = [-1, 0, 1];249 writeTest('dataItem_ArrayOfComplexDouble', original, sameSize);250 writeTest('dataItem_ArrayOfComplexDouble', original, moreVals);251 writeTest('dataItem_ArrayOfComplexDouble', original, lessVals);252 });253 it('Timestamp', function () {254 var original = [255 {256 seconds: '3564057536',257 fraction: '7811758927381448193'258 }, {259 seconds: '3564057542',260 fraction: '16691056759750171331'261 }262 ];263 var sameSize = [264 {265 seconds: '123',266 fraction: '456'267 }, {268 seconds: '789',269 fraction: '135'270 }271 ];272 var moreVals = [273 {274 seconds: '3564057536',275 fraction: '7811758927381448193'276 }, {277 seconds: '3564057542',278 fraction: '16691056759750171331'279 }, {280 seconds: '3564059871',281 fraction: '7811758927381448217'282 }, {283 seconds: '3566659871',284 fraction: '7811758927381446667'285 }286 ];287 var lessVals = [288 {289 seconds: '5',290 fraction: '5'291 }292 ];293 // TODO mraj using the following value causes a browser hang294 // var lessVals = [-1, 0, 1];295 writeTest('dataItem_ArrayOfTimestamp', original, sameSize);296 writeTest('dataItem_ArrayOfTimestamp', original, moreVals);297 writeTest('dataItem_ArrayOfTimestamp', original, lessVals);298 });299 it('Cluster', function () {300 var original = [301 {302 bool: true,303 string: 'first',304 double: 3.14159,305 int32: 42,306 int64: '72057594037927936',307 complex: {308 real: 3.4,309 imaginary: -5.9310 },311 time: {312 seconds: '3564057536',313 fraction: '7811758927381448193'314 }315 },316 {317 bool: false,318 string: 'second',319 double: 6.2831,320 int32: 84,321 int64: '72057594037927939',322 complex: {323 real: 4.567,324 imaginary: 0.5325 },326 time: {327 seconds: '3564059871',328 fraction: '7811758927381448217'329 }330 },331 {332 bool: true,333 string: 'third',334 double: 2.71828,335 int32: 144,336 int64: '-72057594037927942',337 complex: {338 real: 1.4142,339 imaginary: 0.7071340 },341 time: {342 seconds: '3566659871',343 fraction: '7811758927381446667'344 }345 }346 ];347 var sameSize = [348 {349 bool: false,350 string: 'Hello',351 double: 3.14159,352 int32: 42,353 int64: '987',354 complex: {355 real: 3.41,356 imaginary: -5.91357 },358 time: {359 seconds: '1',360 fraction: '1'361 }362 }, {363 bool: true,364 string: 'World',365 double: 6.02e23,366 int32: 43,367 int64: '654',368 complex: {369 real: 3.41,370 imaginary: -5.91371 },372 time: {373 seconds: '0',374 fraction: '0'375 }376 }, {377 bool: false,378 string: 'Iñtërnâtiônà lizætiønâð©',379 double: 8675309,380 int32: 44,381 int64: '321',382 complex: {383 real: 3.41,384 imaginary: -5.91385 },386 time: {387 seconds: '3',388 fraction: '3'389 }390 }391 ];392 var moreVals = [393 {394 bool: false,395 string: 'Hello',396 double: 3.14159,397 int32: 42,398 int64: '987',399 complex: {400 real: 3.41,401 imaginary: -5.91402 },403 time: {404 seconds: '1',405 fraction: '1'406 }407 }, {408 bool: true,409 string: 'World',410 double: 6.02e23,411 int32: 43,412 int64: '654',413 complex: {414 real: 3.41,415 imaginary: -5.91416 },417 time: {418 seconds: '0',419 fraction: '0'420 }421 }, {422 bool: false,423 string: 'Iñtërnâtiônà lizætiønâð©',424 double: 8675309,425 int32: 44,426 int64: '321',427 complex: {428 real: 3.41,429 imaginary: -5.91430 },431 time: {432 seconds: '3',433 fraction: '3'434 }435 }, {436 bool: false,437 string: 'NaNNaNNaNNaNNaNNaNNaNNan Batman!',438 double: 404.404,439 int32: 404,440 int64: '4040404',441 complex: {442 real: 40,443 imaginary: 4444 },445 time: {446 seconds: '4040404',447 fraction: '4040404'448 }449 }450 ];451 var lessVals = [452 {453 bool: false,454 string: 'Iñtërnâtiônà lizætiønâð©',455 double: 8675309,456 int32: 44,457 int64: '321',458 complex: {459 real: 3.41,460 imaginary: -5.91461 },462 time: {463 seconds: '3',464 fraction: '3'465 }466 }, {467 bool: false,468 string: 'NaNNaNNaNNaNNaNNaNNaNNan Batman!',469 double: 404.404,470 int32: 404,471 int64: '4040404',472 complex: {473 real: 40,474 imaginary: 4475 },476 time: {477 seconds: '4040404',478 fraction: '4040404'479 }480 }481 ];482 writeTest('dataItem_ArrayOfClusters', original, sameSize);483 writeTest('dataItem_ArrayOfClusters', original, moreVals);484 writeTest('dataItem_ArrayOfClusters', original, lessVals);485 });486 });487 describe('2D arrays of type', function () {488 it('Boolean', function () {489 var original = [490 [true, false],491 [false, false],492 [true, true]493 ];494 var sameSize = [495 [false, true],496 [true, true],497 [false, false]498 ];499 var moreVals = [500 [true, false, false, false],501 [false, false, false, false],502 [true, true, false, false],503 [true, true, true, true]504 ];505 var lessVals = [506 [false]507 ];508 writeTest('dataItem_2DArrayOfBoolean', original, sameSize);509 writeTest('dataItem_2DArrayOfBoolean', original, moreVals);510 writeTest('dataItem_2DArrayOfBoolean', original, lessVals);511 });512 it('String', function () {513 var original = [514 ['hello', 'world'],515 ['abcde', 'fg'],516 ['xyzzy', '']517 ];518 var sameSize = [519 ['HELLO', 'WORLD'],520 ['ABCDE', 'FG'],521 ['', '']522 ];523 var moreVals = [524 ['I', 'want', 'to', 'be'],525 ['the', 'very', 'best', 'that'],526 ['no', 'one', 'ever', 'was'],527 ['to', 'catch', 'them', 'is'],528 ['my', 'real', 'test', 'to'],529 ['train', 'them', 'is', 'my'],530 ['cause', 'vireomon!', 'ð£', 'ð£ð£']531 ];532 var lessVals = [533 ['ð£']534 ];535 writeTest('dataItem_2DArrayOfString', original, sameSize);536 writeTest('dataItem_2DArrayOfString', original, moreVals);537 writeTest('dataItem_2DArrayOfString', original, lessVals);538 });539 it('Double', function () {540 var original = [541 [1.234, 2.345, 3.456],542 [-4.567, -5.678, -6.789]543 ];544 var sameSize = [545 ['NaN', 'Infinity', '-Infinity'],546 [0, -0, -6.789]547 ];548 var moreVals = [549 [1.234, 2.345, 3.456],550 [-4.567, -5.678, -6.789],551 [-0.411197, 0.749885, 0]552 ];553 var lessVals = [554 [7]555 ];556 writeTest('dataItem_2DArrayOfDouble', original, sameSize);557 writeTest('dataItem_2DArrayOfDouble', original, moreVals);558 writeTest('dataItem_2DArrayOfDouble', original, lessVals);559 });560 it('Int64', function () {561 var original = [562 ['9090'],563 ['36028797018963968'],564 ['-72057594037927936']565 ];566 var sameSize = [567 ['9090'],568 ['8080'],569 ['7070']570 ];571 var moreVals = [572 ['1', '2', '3'],573 ['-4', '-5', '-6'],574 ['7', '8', '9']575 ];576 var lessVals = [577 ['7']578 ];579 writeTest('dataItem_2DArrayOfInt64', original, sameSize);580 writeTest('dataItem_2DArrayOfInt64', original, moreVals);581 writeTest('dataItem_2DArrayOfInt64', original, lessVals);582 });583 it('ComplexDouble', function () {584 var original = [585 [586 {587 real: 1.4142,588 imaginary: 0.7071589 }, {590 real: 10,591 imaginary: -10592 }593 ],594 [595 {596 real: 5.045,597 imaginary: -5.67598 }, {599 real: 7.89,600 imaginary: 1234.5678601 }602 ]603 ];604 var sameSize = [605 [606 {607 real: 'NaN',608 imaginary: '-Infinity'609 }, {610 real: 'NaN',611 imaginary: 'Infinity'612 }613 ],614 [615 {616 real: 0,617 imaginary: -0618 }, {619 real: -0,620 imaginary: 0621 }622 ]623 ];624 var moreVals = [625 [626 {627 real: 1.4142,628 imaginary: 0.7071629 }, {630 real: 10,631 imaginary: -10632 }633 ],634 [635 {636 real: 5.045,637 imaginary: -5.67638 }, {639 real: 7.89,640 imaginary: 1234.5678641 }642 ],643 [644 {645 real: 7,646 imaginary: 8647 }, {648 real: 9,649 imaginary: 10650 }651 ]652 ];653 var lessVals = [654 [655 {656 real: 1.4142,657 imaginary: 0.7071658 }659 ]660 ];661 writeTest('dataItem_2DArrayOfComplex', original, sameSize);662 expect(moreVals).toBeDefined();663 expect(lessVals).toBeDefined();664 // TODO mraj resize tests for 2d arrays seem to fail665 // writeTest('dataItem_2DArrayOfComplex', original, moreVals);666 // writeTest('dataItem_2DArrayOfComplex', original, lessVals);667 });668 it('Timestamp', function () {669 var original = [670 [671 {672 seconds: '3564057536',673 fraction: '7811758927381448193'674 }, {675 seconds: '3564057542',676 fraction: '16691056759750171331'677 }678 ],679 [680 {681 seconds: '3564059871',682 fraction: '7811758927381448217'683 }, {684 seconds: '3564057536',685 fraction: '7811758927381448193'686 }687 ],688 [689 {690 seconds: '3566659871',691 fraction: '7811758927381446667'692 }, {693 seconds: '3566659871',694 fraction: '7811758927381446667'695 }696 ]697 ];698 var sameSize = [699 [700 {701 seconds: '1',702 fraction: '2'703 }, {704 seconds: '3',705 fraction: '4'706 }707 ],708 [709 {710 seconds: '5',711 fraction: '6'712 }, {713 seconds: '7',714 fraction: '8'715 }716 ],717 [718 {719 seconds: '9',720 fraction: '10'721 }, {722 seconds: '11',723 fraction: '12'724 }725 ]726 ];727 var moreVals = [728 [729 {730 seconds: '1',731 fraction: '2'732 }, {733 seconds: '3',734 fraction: '4'735 }736 ],737 [738 {739 seconds: '5',740 fraction: '6'741 }, {742 seconds: '7',743 fraction: '8'744 }745 ],746 [747 {748 seconds: '9',749 fraction: '10'750 }, {751 seconds: '11',752 fraction: '12'753 }754 ],755 [756 {757 seconds: '13',758 fraction: '14'759 }, {760 seconds: '15',761 fraction: '16'762 }763 ]764 ];765 var lessVals = [766 [767 {768 seconds: '1',769 fraction: '2'770 }771 ]772 ];773 writeTest('dataItem_2DArrayOfTimestamp', original, sameSize);774 writeTest('dataItem_2DArrayOfTimestamp', original, moreVals);775 writeTest('dataItem_2DArrayOfTimestamp', original, lessVals);776 });777 });778 describe('3D arrays of type', function () {779 it('Int32', function () {780 var original = [781 [782 [111, 112, 113],783 [121, 122, 123]784 ],785 [786 [211, 212, 213],787 [221, 222, 223]788 ]789 ];790 var sameSize = [791 [792 [8111, 8112, 8113],793 [8121, 8122, 8123]794 ],795 [796 [8211, 8212, 8213],797 [8221, 8222, 8223]798 ]799 ];800 var moreVals = [801 [802 [111, 112, 113, 5],803 [121, 122, 123, 5],804 [555, 555, 555, 5]805 ],806 [807 [211, 212, 213, 5],808 [221, 222, 223, 5],809 [555, 555, 555, 5]810 ]811 ];812 var lessVals = [813 [814 [7]815 ]816 ];817 writeTest('dataItem_3DArrayOfInt32', original, sameSize);818 writeTest('dataItem_3DArrayOfInt32', original, moreVals);819 writeTest('dataItem_3DArrayOfInt32', original, lessVals);820 });821 });822 describe('composite types of', function () {823 it('clusters with scalars', function () {824 var original = {825 bool: true,826 string: 'first',827 double: 3.14159,828 int32: 42,829 int64: '-72057594037927936',830 uint64: '9223372041149743104',831 complex: {832 real: 3.4,833 imaginary: -5.9834 },835 time: {836 seconds: '3564057536',837 fraction: '7811758927381448193'838 }839 };840 var newValue = {841 bool: false,842 string: 'last',843 double: 9.8696,844 int32: 2147418112,845 int64: '-1152921504606846976',846 uint64: '10376293541461622784',847 complex: {848 real: 123.456,849 imaginary: -789.012850 },851 time: {852 seconds: '3566659871',853 fraction: '7811758927381446667'854 }855 };856 writeTest('dataItem_ClusterOfScalars', original, newValue);857 });858 it('clusters with 1D arrays', function () {859 var original = {860 booleans: [true, false, true],861 strings: ['Lorem', 'ipsum', 'dolor', 'sit', 'amet'],862 doubles: [1.2, 3.4, 5.6, 7.89, 1234.5678],863 int32s: [-1000, -10, 42, 9876543, 123],864 int64s: [865 '-8989',866 '9090',867 '36028797018963968',868 '-72057594037927936'869 ],870 uint64s: [871 '9223372041149743104',872 '0',873 '9223376434901286912'874 ],875 complexes: [876 {877 real: 0,878 imaginary: 0879 }, {880 real: 10,881 imaginary: -10882 }, {883 real: 5.045,884 imaginary: -5.67885 }886 ],887 times: [888 {889 seconds: '3564057536',890 fraction: '7811758927381448193'891 }, {892 seconds: '3564057542',893 fraction: '16691056759750171331'894 }895 ]896 };897 var sameSize = {898 booleans: [false, true, false],899 strings: 'And this bird you cannot change'.split(' '),900 doubles: [21.2, 23.4, 25.6, 27.89, 21234.5678],901 int32s: [552139, -396256, -292658, -795576, 248411, 873904, 994612, 724317, 79111, -849221],902 int64s: ['-8989', '9090', '36028', '-7205'],903 uint64s: ['922337', '0', '9223'],904 complexes: [905 {906 real: 'Infinity',907 imaginary: 'NaN'908 }, {909 real: 0,910 imaginary: -0911 }, {912 real: 'NaN',913 imaginary: '-Infinity'914 }915 ],916 times: [917 {918 seconds: '3564057536',919 fraction: '7811'920 }, {921 seconds: '3564057542',922 fraction: '1669'923 }924 ]925 };926 var moreVals = {927 booleans: [true, false, true, true],928 strings: ['Lorem', 'ipsum', 'dolor', 'sit', 'amet', 'amet2'],929 doubles: [1.2, 3.4, 5.6, 7.89, 1234.5678, -0],930 int32s: [-1000, -10, 42, 9876543, 123, 42],931 int64s: [932 '-8989',933 '9090',934 '36028797018963968',935 '-72057594037927936',936 '404'937 ],938 uint64s: [939 '9223372041149743104',940 '0',941 '9223376434901286912',942 '404'943 ],944 complexes: [945 {946 real: 0,947 imaginary: 0948 }, {949 real: 10,950 imaginary: -10951 }, {952 real: 5.045,953 imaginary: -5.67954 }, {955 real: 'Infinity',956 imaginary: '-Infinity'957 }958 ],959 times: [960 {961 seconds: '3564057536',962 fraction: '7811758927381448193'963 }, {964 seconds: '3564057542',965 fraction: '16691056759750171331'966 }, {967 seconds: '4',968 fraction: '5'969 }970 ]971 };972 var lessVals = {973 booleans: [true],974 strings: ['Lorem'],975 doubles: [1.2],976 int32s: [-1000],977 int64s: ['-8989'],978 uint64s: ['92233720411'],979 complexes: [980 {981 real: 0,982 imaginary: 0983 }984 ],985 times: [986 {987 seconds: '8',988 fraction: '67'989 }990 ]991 };992 writeTest('dataItem_ClusterOfArrays', original, sameSize);993 writeTest('dataItem_ClusterOfArrays', original, moreVals);994 writeTest('dataItem_ClusterOfArrays', original, lessVals);995 });996 // Vireo does not yet support writeJSON on Variant data types so any provided attributes value will be ignored on write997 it('analog waveform of double', function () {998 var original = {999 t0: {1000 seconds: '300',1001 fraction: '123'1002 },1003 dt: 8.8,1004 Y: [5.5, 6.6, 7.7, 8.8],1005 attributes: {_data: null, _attributes: null}1006 };1007 var sameSize = {1008 t0: {1009 seconds: '3456789',1010 fraction: '0'1011 },1012 dt: 1234.5678,1013 Y: ['NaN', 'Infinity', '-Infinity', -0],1014 attributes: {_data: null, _attributes: null}1015 };1016 var moreVals = {1017 t0: {1018 seconds: '3001',1019 fraction: '1231'1020 },1021 dt: 8.89,1022 Y: [5.5, 6.6, 7.7, 8.8, 9.9, 10.1, 11],1023 attributes: {_data: null, _attributes: null}1024 };1025 var lessVals = {1026 t0: {1027 seconds: '1',1028 fraction: '2'1029 },1030 dt: 3,1031 Y: [4],1032 attributes: {_data: null, _attributes: null}1033 };1034 writeTest('wave_Double', original, sameSize);1035 writeTest('wave_Double', original, moreVals);1036 writeTest('wave_Double', original, lessVals);1037 });1038 });1039 it('empty arrays', function () {1040 writeTest('dataItem_Empty1DArray', [], [true]);1041 writeTest('dataItem_Empty2DArray', [[]], [[true]]);1042 writeTest('dataItem_Empty3DArray', [[[]]], [[[true]]]);1043 });...
buffer-cursor.spec.js
Source:buffer-cursor.spec.js
1const BufferCursor = require('./buffer-cursor');2const readTests = [3 {4 method: 'readUInt8',5 instance: new BufferCursor(Buffer.from([1, 2, 3])),6 },7 {8 method: 'readUInt16LE',9 instance: new BufferCursor(Buffer.from([1, 0, 2, 0, 3, 0])),10 },11 {12 method: 'readUInt16BE',13 instance: new BufferCursor(Buffer.from([0, 1, 0, 2, 0, 3])),14 },15 {16 method: 'readUInt32LE',17 instance: new BufferCursor(Buffer.from([1, 0, 0, 0, 2, 0, 0, 0, 3, 0, 0, 0])),18 },19 {20 method: 'readUInt32BE',21 instance: new BufferCursor(Buffer.from([0, 0, 0, 1, 0, 0, 0, 2, 0, 0, 0, 3])),22 },23];24for (let readTest of readTests) {25 describe(readTest.method, () => {26 test('should read at start', () => {27 expect(readTest.instance[readTest.method]()).toBe(1);28 });29 test('should read in middle', () => {30 expect(readTest.instance[readTest.method]()).toBe(2);31 });32 test('should read at last', () => {33 expect(readTest.instance[readTest.method]()).toBe(3);34 });35 test('should throw when out of bounds', () => {36 expect(() => readTest.instance[readTest.method]()).toThrow('Index out of range');37 });38 });39}40describe('readBytes', () => {41 let buffer;42 beforeAll(() => {43 buffer = new BufferCursor(Buffer.from([0, 1, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 3]));44 });45 test('should read at start', () => {46 expect(buffer.readBytes(2)).toEqual(Buffer.from([0, 1]));47 });48 test('should read in middle', () => {49 expect(buffer.readBytes(4)).toEqual(Buffer.from([0, 0, 0, 2]));50 });51 test('should throw when read is out of bounds', () => {52 expect(() => buffer.readBytes(9)).toThrow('Index out of range');53 });54 test('should read to end', () => {55 expect(buffer.readBytes(8)).toEqual(Buffer.from([0, 0, 0, 0, 0, 0, 0, 3]));56 });57 test('should throw when at end', () => {58 expect(() => buffer.readBytes(1)).toThrow('Index out of range');59 });60 test('should read remaining bytes when at start', () => {61 buffer = new BufferCursor(Buffer.from([0, 0, 0, 1]));62 expect(buffer.readBytes()).toEqual(Buffer.from([0, 0, 0, 1]));63 });64 test('should read remaining bytes when in middle', () => {65 buffer = new BufferCursor(Buffer.from([0, 0, 0, 1]));66 buffer.readBytes(1);67 expect(buffer.readBytes()).toEqual(Buffer.from([0, 0, 1]));68 });69 test('should throw error when at end of buffer', () => {70 buffer = new BufferCursor(Buffer.from([1]));71 buffer.readBytes(1);72 expect(() => buffer.readBytes()).toThrow('Index out of range');73 });74 test('should return empty buffer is read length is 0', () => {75 buffer = new BufferCursor(Buffer.alloc(0));76 expect(buffer.readBytes(0)).toEqual(Buffer.alloc(0));77 });78});79const writeTests = [80 {81 method: 'writeUInt8',82 instance: new BufferCursor(Buffer.alloc(3)),83 assertions: [Buffer.from([1, 0, 0]), Buffer.from([1, 2, 0]), Buffer.from([1, 2, 3])],84 },85 {86 method: 'writeUInt16LE',87 instance: new BufferCursor(Buffer.alloc(6)),88 assertions: [89 Buffer.from([1, 0, 0, 0, 0, 0]),90 Buffer.from([1, 0, 2, 0, 0, 0]),91 Buffer.from([1, 0, 2, 0, 3, 0]),92 ],93 },94 {95 method: 'writeUInt16BE',96 instance: new BufferCursor(Buffer.alloc(6)),97 assertions: [98 Buffer.from([0, 1, 0, 0, 0, 0]),99 Buffer.from([0, 1, 0, 2, 0, 0]),100 Buffer.from([0, 1, 0, 2, 0, 3]),101 ],102 },103 {104 method: 'writeUInt32LE',105 instance: new BufferCursor(Buffer.alloc(12)),106 assertions: [107 Buffer.from([1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]),108 Buffer.from([1, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0]),109 Buffer.from([1, 0, 0, 0, 2, 0, 0, 0, 3, 0, 0, 0]),110 ],111 },112 {113 method: 'writeUInt32BE',114 instance: new BufferCursor(Buffer.alloc(12)),115 assertions: [116 Buffer.from([0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0]),117 Buffer.from([0, 0, 0, 1, 0, 0, 0, 2, 0, 0, 0, 0]),118 Buffer.from([0, 0, 0, 1, 0, 0, 0, 2, 0, 0, 0, 3]),119 ],120 },121];122for (let writeTest of writeTests) {123 describe(writeTest.method, () => {124 test('should write at start', () => {125 writeTest.instance[writeTest.method](1);126 expect(writeTest.instance.buffer).toEqual(writeTest.assertions[0]);127 });128 test('should write in middle', () => {129 writeTest.instance[writeTest.method](2);130 expect(writeTest.instance.buffer).toEqual(writeTest.assertions[1]);131 });132 test('should write at end', () => {133 writeTest.instance[writeTest.method](3);134 expect(writeTest.instance.buffer).toEqual(writeTest.assertions[2]);135 });136 test('should throw when out of bounds', () => {137 expect(() => writeTest.instance[writeTest.method]()).toThrow('Index out of range');138 });139 });140}141describe('writeBytes', () => {142 let buffer;143 beforeAll(() => {144 buffer = new BufferCursor(Buffer.alloc(8));145 });146 test('should ignore writing a null', () => {147 buffer.writeBytes(null);148 expect(buffer.buffer).toEqual(Buffer.from([0, 0, 0, 0, 0, 0, 0, 0]));149 });150 test('should ignore writing an empty buffer', () => {151 buffer.writeBytes(Buffer.alloc(0));152 expect(buffer.buffer).toEqual(Buffer.from([0, 0, 0, 0, 0, 0, 0, 0]));153 });154 test('should write at start', () => {155 buffer.writeBytes(Buffer.from([1]));156 expect(buffer.buffer).toEqual(Buffer.from([1, 0, 0, 0, 0, 0, 0, 0]));157 });158 test('should write in middle', () => {159 buffer.writeBytes(Buffer.from([2, 2]));160 expect(buffer.buffer).toEqual(Buffer.from([1, 2, 2, 0, 0, 0, 0, 0]));161 });162 test('should throw if write buffer exceeds cursor', () => {163 expect(() => buffer.writeBytes(Buffer.from([6, 6, 6, 6, 6, 6]))).toThrow('Index out of range');164 });165 test('should write to end', () => {166 buffer.writeBytes(Buffer.from([5, 5, 5, 5, 5]));167 expect(buffer.buffer).toEqual(Buffer.from([1, 2, 2, 5, 5, 5, 5, 5]));168 });169 test('should not care about writing zero byte buffer', () => {170 buffer.writeBytes(Buffer.alloc(0));171 expect(buffer.buffer).toEqual(Buffer.from([1, 2, 2, 5, 5, 5, 5, 5]));172 });173});174describe('position', () => {175 let readbuf;176 let writebuf;177 beforeAll(() => {178 readbuf = new BufferCursor(Buffer.from([1, 2, 0, 0, 3, 4, 0, 0, 0, 0, 0, 0, 5, 6, 0, 0, 0, 7]));179 writebuf = new BufferCursor(Buffer.alloc(18));180 });181 test('should start at 0', () => {182 expect(readbuf.position).toBe(0);183 });184 test('should advance by 1 with readUInt8', () => {185 readbuf.readUInt8();186 expect(readbuf.position).toBe(1);187 });188 test('should advance by 2 with readUInt16LE', () => {189 readbuf.readUInt16LE();190 expect(readbuf.position).toBe(3);191 });192 test('should advance by 2 with readUInt16BE', () => {193 readbuf.readUInt16BE();194 expect(readbuf.position).toBe(5);195 });196 test('should advance by 4 with readUInt32LE', () => {197 readbuf.readUInt32LE();198 expect(readbuf.position).toBe(9);199 });200 test('should advance by 4 with readUInt32BE', () => {201 readbuf.readUInt32BE();202 expect(readbuf.position).toBe(13);203 });204 test('should advance by read amount with readBytes', () => {205 readbuf.readBytes(1);206 expect(readbuf.position).toBe(14);207 });208 test('should advance by rest with readBytes without len', () => {209 readbuf.readBytes();210 expect(readbuf.position).toBe(18);211 });212 test('should advance by 1 with writeUInt8', () => {213 writebuf.writeUInt8(1);214 expect(writebuf.position).toBe(1);215 });216 test('should advance by 2 with writeUInt16LE', () => {217 writebuf.writeUInt16LE(1);218 expect(writebuf.position).toBe(3);219 });220 test('should advance by 2 with writeUInt16BE', () => {221 writebuf.writeUInt16BE(1);222 expect(writebuf.position).toBe(5);223 });224 test('should advance by 4 with writeUInt32LE', () => {225 writebuf.writeUInt32LE(1);226 expect(writebuf.position).toBe(9);227 });228 test('should advance by 4 with writeUInt32BE', () => {229 writebuf.writeUInt32BE(1);230 expect(writebuf.position).toBe(13);231 });232 test('should advance by buffer length with writeBytes', () => {233 writebuf.writeBytes(Buffer.alloc(5));234 expect(writebuf.position).toBe(18);235 });236});237describe('eof', () => {238 let buffer;239 beforeAll(() => {240 buffer = new BufferCursor(Buffer.from([1, 2]));241 });242 test('should be false at start', () => {243 expect(buffer.eof).toBeFalsy();244 });245 test('should be false in middle', () => {246 buffer.readBytes(1);247 expect(buffer.eof).toBeFalsy();248 });249 test('should be true when all bytes read', () => {250 buffer.readBytes(1);251 expect(buffer.eof).toBeTruthy();252 });...
chops-html-last.js
Source:chops-html-last.js
...10 11 function writeEl( el ) {12 _.appendDom( _.el( "results" ), el );13 }14 function writeTest( text ) {15 writeEl( _.dom( "p", { "class": "test" }, "" + text ) );16 }17 18 writeTest( "heya" );19 20 writeEl( _.dom( "br" ) );21 22 var doOrDoNot = false;23 24 function kindatry( body, onCatch ) {25 if ( doOrDoNot )26 return body();27 try { return body(); }28 catch ( e ) { return onCatch( e ); }29 }30 31 kindatry( function () {32 33 writeTest( "beya " + _.arrMappend( [ [ 1, 2, 3 ], [ 4, 5, 6 ] ], _.idfn ).length );34 35 writeTest( "seya" );36 writeTest( "seya " + _.blahpp( " woo hoo ".split( /\s+/ ) ) );37 38 writeEl( _.dom( "h1", "chops" ) );39 40 function testChops( code ) {41 function write( it ) { writeTest( "try " + _.blahpp( code ) + ": " + it ); }42 kindatry( function () {43 write( _.blahpp( $.chopup( code ) ) );44 }, function ( e ) {45 write( "ERROR: " + e );46 } );47 }48 49 function testChopWords( code, num ) {50 function write( it ) { writeTest( "try words " + _.blahpp( code ) + " " + num + ": " + it ); }51 kindatry( function () {52 $.letChopWords( $.chopup( code )[ 0 ], num, function () {53 write( _.blahpp( arguments ) );54 } );55 }, function ( e ) {56 write( "ERROR: " + e );57 } );58 }59 60 testChops( "" );61 testChops( "woo[moo]foo[bar]" );62 //testChops( "woo[moo]foo[bar" );63 testChops( "woo[moo [woo] ]foo[bar]" );64 testChops( _.el( "comment-test" ).innerHTML );65 testChopWords( "a b[] c d", 2 );66 67 writeTest( "blah " + _.blahpp( $.condenseStrings( [ "", " ", [ "foo" ], "", [], " you ", "know" ] ) ) );68 69 writeTest( "blah " + _.blahpp( choppaScript.parse( "woo[foo]moo" ) ) );70 71 writeTest( "blah " + _.blahpp( choppaScript.parse( "woo[a 2][ 1 [a] ][][just m]oo" ) ) );72 73 writeTest( "blah " + _.blahpp( $.unchop( $.chopcode( "woo[moo [woo] ]foo[bar]" ) ) ) );74 75 writeTest( "blah " + _.blahpp( choppaScript.parse( _.el( "monad-test" ).innerHTML ) ) );76 77 writeTest( "blah " + _.blahpp( choppaScript.parse( "woo( [fn :], [fn it: it(); ], [fn a b = a + b ] )" ) ) );78 79 writeTest( "blah " + _.blahpp( choppaScript.parse( _.el( "monad-fn-test" ).innerHTML ) ) );80 81 writeTest( "blah " + _.blahpp( choppaScript.parse( _.el( "monad-bind-test" ).innerHTML ) ) );82 83 writeTest( "blah " + _.blahpp( choppaScript.parse( _.el( "monad-side-channel-test" ).innerHTML ) ) );84 85 writeTest( "blah " + _.blahpp( choppaScript.parse( _.el( "str-test" ).innerHTML ) ) );86 87 writeTest( "blah " + _.blahpp( choppaScript.parse( _.el( "quote-test" ).innerHTML ) ) );88 89 90 }, function ( e ) {91 _.blahlog( "Error: " + e );92 } );...
Using AI Code Generation
1var availableModules = require('./availableModules.js');2availableModules.writeTest();3availableModules.readTest();4var fs = require('fs');5exports.writeTest = function() {6 fs.writeFile('test.txt', 'Hello World!', function (err) {7 if (err) return console.log(err);8 console.log('test.txt created successfully.');9 });10}11exports.readTest = function() {12 fs.readFile('test.txt', 'utf8', function (err, data) {13 if (err) return console.log(err);14 console.log(data);15 });16}17Your name to display (optional):18Your name to display (optional):
Using AI Code Generation
1var test = require('./test.js');2test.writeTest();3var test = require('./test.js');4test.writeTest();5var test = require('./test.js');6test.writeTest();7var test = require('./test.js');8test.writeTest();9var test = require('./test.js');10test.writeTest();11var test = require('./test.js');12test.writeTest();13exports.writeTest = function() {14 console.log('test');15}16var test = require('../lib/test.js');17test.writeTest();18exports.writeTest = function() {19 console.log('test');20}21var test = require('./test.js');22test.writeTest();23exports.writeTest = function() {24 console.log('test');25}26var test = require('./lib/test.js');27test.writeTest();28exports.writeTest = function() {29 console.log('test');30}31var test = require('../lib/test.js');
Using AI Code Generation
1var test = require('./test');2test.writeTest();3var test = require('./test');4test.writeTest();5var test = require('./test');6test.writeTest();7var test = require('./test');8test.writeTest();9var test = require('./test');10test.writeTest();11var test = require('./test');12test.writeTest();13var test = require('./test');14test.writeTest();15var test = require('./test');16test.writeTest();17var test = require('./test');18test.writeTest();19var test = require('./test');20test.writeTest();21var test = require('./test');22test.writeTest();23var test = require('./test');24test.writeTest();25var test = require('./test');26test.writeTest();27var test = require('./test');28test.writeTest();
Using AI Code Generation
1var myModule = require('./myModule');2myModule.writeTest();3exports.writeTest = function() {4 console.log("This is a test");5}6var myModule = require('./myModule');7myModule.writeTest();8exports.writeTest = function() {9 console.log("This is a test");10}11var myModule = require('./myModule');12myModule.writeTest();13exports.writeTest = function() {14 console.log("This is a test");15}16var myModule = require('./myModule');17myModule.writeTest();18exports.writeTest = function() {19 console.log("This is a test");20}21var myModule = require('./myModule');22myModule.writeTest();23exports.writeTest = function() {24 console.log("This is a test");25}26var myModule = require('./myModule');27myModule.writeTest();28exports.writeTest = function() {29 console.log("This is a test");30}31var myModule = require('./myModule');32myModule.writeTest();33exports.writeTest = function() {34 console.log("This is a test");35}36var myModule = require('./myModule');37myModule.writeTest();38exports.writeTest = function() {39 console.log("This is a test");40}
Using AI Code Generation
1var availableTest = require('./availableTest');2availableTest.writeTest();3exports.writeTest = function() {4 console.log('writing test');5}6var availableTest = require('./availableTest');7availableTest.writeTest();8exports.writeTest = function() {9 console.log('writing test');10}11var availableTest = require('./availableTest');12availableTest.writeTest();13exports.writeTest = function() {14 console.log('writing test');15}16var availableTest = require('./availableTest');17availableTest.writeTest();18exports.writeTest = function() {19 console.log('writing test');20}21var availableTest = require('./availableTest');22availableTest.writeTest();23exports.writeTest = function() {24 console.log('writing test');25}26var availableTest = require('./availableTest');27availableTest.writeTest();28exports.writeTest = function() {29 console.log('writing test');30}31var availableTest = require('./availableTest');32availableTest.writeTest();33exports.writeTest = function() {34 console.log('writing test');35}36var availableTest = require('./availableTest');37availableTest.writeTest();38exports.writeTest = function() {39 console.log('writing test');40}
Using AI Code Generation
1var test = require('./testModule.js');2test.writeTest();3exports.writeTest = function() {4 console.log('Test');5};6var test = require('./testModule.js');7test.writeTest();8exports.writeTest = function() {9 console.log('Test');10};11var test = require('./testModule.js');12test.writeTest();13exports.writeTest = function() {14 console.log('Test');15};16var test = require('./testModule.js');
Using AI Code Generation
1const availableTest = require('./availableTest');2const writeTest = availableTest.writeTest;3const writeTest = () => {4 console.log('test passed');5};6module.exports = {7};8const writeTest = () => {9 console.log('test passed');10};11module.exports = {12};13const writeTest = () => {14 console.log('test passed');15};16module.exports = {17};18const writeTest = () => {19 console.log('test passed');20};21module.exports = {22};23const writeTest = () => {24 console.log('test passed');25};26module.exports = {27};28const writeTest = () => {29 console.log('test passed');30};31module.exports = {32};33const writeTest = () => {34 console.log('test passed');35};36module.exports = {37};38const writeTest = () => {39 console.log('test passed');40};41module.exports = {42};43const writeTest = () => {44 console.log('test passed');45};46module.exports = {47};48const writeTest = () => {49 console.log('test passed');50};51module.exports = {52};53const writeTest = () => {54 console.log('test passed');55};56module.exports = {57};58const writeTest = () => {59 console.log('test passed');60};61module.exports = {
Using AI Code Generation
1var available = require('./available.js');2available.writeTest();3 * These modules are accessed using require() function4 * These modules are accessed using require() function5 * These modules are accessed using require() function6var fs = require('fs');7var data = fs.readFileSync('input.txt');8console.log(data.toString());9console.log("Program Ended");10var available = require('./available.js');11available.writeTest();12var http = require('http');13http.createServer(function (req, res) {14 res.writeHead(200, {'Content-Type': 'text/plain'});15 res.end('Hello World\n');16}).listen(8081);
Using AI Code Generation
1var availableTest = require('./availableTest.js');2availableTest.writeTest();3var availableTest = require("./availableTest.js");4availableTest.writeTest();5var availableTest = require("./availableTest.js");6availableTest.writeTest();7var availableTest = require("./availableTest.js");8availableTest.writeTest();9var availableTest = require("./availableTest.js");10availableTest.writeTest();11var availableTest = require("./availableTest.js");12availableTest.writeTest();
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!