How to use getChars method in storybook-root

Best JavaScript code snippet using storybook-root

Terminal.test.ts

Source:Terminal.test.ts Github

copy

Full Screen

...516 term.buffer.lines.get(INIT_ROWS - 1).setCell(0, CellData.fromCharData([0, 'b', 0, 'b'.charCodeAt(0)]));517 term.buffer.y = INIT_ROWS - 1; // Move cursor to last line518 term.scroll();519 assert.equal(term.buffer.lines.length, INIT_ROWS + 1);520 assert.equal(term.buffer.lines.get(0).loadCell(0, new CellData()).getChars(), 'a');521 assert.equal(term.buffer.lines.get(INIT_ROWS - 1).loadCell(0, new CellData()).getChars(), 'b');522 assert.equal(term.buffer.lines.get(INIT_ROWS).loadCell(0, new CellData()).getChars(), '');523 });524 it('should properly scroll inside a scroll region (scrollTop set)', () => {525 term.buffer.lines.get(0).setCell(0, CellData.fromCharData([0, 'a', 0, 'a'.charCodeAt(0)]));526 term.buffer.lines.get(1).setCell(0, CellData.fromCharData([0, 'b', 0, 'b'.charCodeAt(0)]));527 term.buffer.lines.get(2).setCell(0, CellData.fromCharData([0, 'c', 0, 'c'.charCodeAt(0)]));528 term.buffer.y = INIT_ROWS - 1; // Move cursor to last line529 term.buffer.scrollTop = 1;530 term.scroll();531 assert.equal(term.buffer.lines.length, INIT_ROWS);532 assert.equal(term.buffer.lines.get(0).loadCell(0, new CellData()).getChars(), 'a');533 assert.equal(term.buffer.lines.get(1).loadCell(0, new CellData()).getChars(), 'c');534 });535 it('should properly scroll inside a scroll region (scrollBottom set)', () => {536 term.buffer.lines.get(0).setCell(0, CellData.fromCharData([0, 'a', 0, 'a'.charCodeAt(0)]));537 term.buffer.lines.get(1).setCell(0, CellData.fromCharData([0, 'b', 0, 'b'.charCodeAt(0)]));538 term.buffer.lines.get(2).setCell(0, CellData.fromCharData([0, 'c', 0, 'c'.charCodeAt(0)]));539 term.buffer.lines.get(3).setCell(0, CellData.fromCharData([0, 'd', 0, 'd'.charCodeAt(0)]));540 term.buffer.lines.get(4).setCell(0, CellData.fromCharData([0, 'e', 0, 'e'.charCodeAt(0)]));541 term.buffer.y = 3;542 term.buffer.scrollBottom = 3;543 term.scroll();544 assert.equal(term.buffer.lines.length, INIT_ROWS + 1);545 assert.equal(term.buffer.lines.get(0).loadCell(0, new CellData()).getChars(), 'a', '\'a\' should be pushed to the scrollback');546 assert.equal(term.buffer.lines.get(1).loadCell(0, new CellData()).getChars(), 'b');547 assert.equal(term.buffer.lines.get(2).loadCell(0, new CellData()).getChars(), 'c');548 assert.equal(term.buffer.lines.get(3).loadCell(0, new CellData()).getChars(), 'd');549 assert.equal(term.buffer.lines.get(4).loadCell(0, new CellData()).getChars(), '', 'a blank line should be added at scrollBottom\'s index');550 assert.equal(term.buffer.lines.get(5).loadCell(0, new CellData()).getChars(), 'e');551 });552 it('should properly scroll inside a scroll region (scrollTop and scrollBottom set)', () => {553 term.buffer.lines.get(0).setCell(0, CellData.fromCharData([0, 'a', 0, 'a'.charCodeAt(0)]));554 term.buffer.lines.get(1).setCell(0, CellData.fromCharData([0, 'b', 0, 'b'.charCodeAt(0)]));555 term.buffer.lines.get(2).setCell(0, CellData.fromCharData([0, 'c', 0, 'c'.charCodeAt(0)]));556 term.buffer.lines.get(3).setCell(0, CellData.fromCharData([0, 'd', 0, 'd'.charCodeAt(0)]));557 term.buffer.lines.get(4).setCell(0, CellData.fromCharData([0, 'e', 0, 'e'.charCodeAt(0)]));558 term.buffer.y = INIT_ROWS - 1; // Move cursor to last line559 term.buffer.scrollTop = 1;560 term.buffer.scrollBottom = 3;561 term.scroll();562 assert.equal(term.buffer.lines.length, INIT_ROWS);563 assert.equal(term.buffer.lines.get(0).loadCell(0, new CellData()).getChars(), 'a');564 assert.equal(term.buffer.lines.get(1).loadCell(0, new CellData()).getChars(), 'c', '\'b\' should be removed from the buffer');565 assert.equal(term.buffer.lines.get(2).loadCell(0, new CellData()).getChars(), 'd');566 assert.equal(term.buffer.lines.get(3).loadCell(0, new CellData()).getChars(), '', 'a blank line should be added at scrollBottom\'s index');567 assert.equal(term.buffer.lines.get(4).loadCell(0, new CellData()).getChars(), 'e');568 });569 });570 describe('when scrollback === 0', () => {571 beforeEach(() => {572 term.setOption('scrollback', 0);573 assert.equal(term.buffer.lines.maxLength, INIT_ROWS);574 });575 it('should create a new line and shift everything up', () => {576 term.buffer.lines.get(0).setCell(0, CellData.fromCharData([0, 'a', 0, 'a'.charCodeAt(0)]));577 term.buffer.lines.get(1).setCell(0, CellData.fromCharData([0, 'b', 0, 'b'.charCodeAt(0)]));578 term.buffer.lines.get(INIT_ROWS - 1).setCell(0, CellData.fromCharData([0, 'c', 0, 'c'.charCodeAt(0)]));579 term.buffer.y = INIT_ROWS - 1; // Move cursor to last line580 assert.equal(term.buffer.lines.length, INIT_ROWS);581 term.scroll();582 assert.equal(term.buffer.lines.length, INIT_ROWS);583 // 'a' gets pushed out of buffer584 assert.equal(term.buffer.lines.get(0).loadCell(0, new CellData()).getChars(), 'b');585 assert.equal(term.buffer.lines.get(1).loadCell(0, new CellData()).getChars(), '');586 assert.equal(term.buffer.lines.get(INIT_ROWS - 2).loadCell(0, new CellData()).getChars(), 'c');587 assert.equal(term.buffer.lines.get(INIT_ROWS - 1).loadCell(0, new CellData()).getChars(), '');588 });589 it('should properly scroll inside a scroll region (scrollTop set)', () => {590 term.buffer.lines.get(0).setCell(0, CellData.fromCharData([0, 'a', 0, 'a'.charCodeAt(0)]));591 term.buffer.lines.get(1).setCell(0, CellData.fromCharData([0, 'b', 0, 'b'.charCodeAt(0)]));592 term.buffer.lines.get(2).setCell(0, CellData.fromCharData([0, 'c', 0, 'c'.charCodeAt(0)]));593 term.buffer.y = INIT_ROWS - 1; // Move cursor to last line594 term.buffer.scrollTop = 1;595 term.scroll();596 assert.equal(term.buffer.lines.length, INIT_ROWS);597 assert.equal(term.buffer.lines.get(0).loadCell(0, new CellData()).getChars(), 'a');598 assert.equal(term.buffer.lines.get(1).loadCell(0, new CellData()).getChars(), 'c');599 });600 it('should properly scroll inside a scroll region (scrollBottom set)', () => {601 term.buffer.lines.get(0).setCell(0, CellData.fromCharData([0, 'a', 0, 'a'.charCodeAt(0)]));602 term.buffer.lines.get(1).setCell(0, CellData.fromCharData([0, 'b', 0, 'b'.charCodeAt(0)]));603 term.buffer.lines.get(2).setCell(0, CellData.fromCharData([0, 'c', 0, 'c'.charCodeAt(0)]));604 term.buffer.lines.get(3).setCell(0, CellData.fromCharData([0, 'd', 0, 'd'.charCodeAt(0)]));605 term.buffer.lines.get(4).setCell(0, CellData.fromCharData([0, 'e', 0, 'e'.charCodeAt(0)]));606 term.buffer.y = 3;607 term.buffer.scrollBottom = 3;608 term.scroll();609 assert.equal(term.buffer.lines.length, INIT_ROWS);610 assert.equal(term.buffer.lines.get(0).loadCell(0, new CellData()).getChars(), 'b');611 assert.equal(term.buffer.lines.get(1).loadCell(0, new CellData()).getChars(), 'c');612 assert.equal(term.buffer.lines.get(2).loadCell(0, new CellData()).getChars(), 'd');613 assert.equal(term.buffer.lines.get(3).loadCell(0, new CellData()).getChars(), '', 'a blank line should be added at scrollBottom\'s index');614 assert.equal(term.buffer.lines.get(4).loadCell(0, new CellData()).getChars(), 'e');615 });616 it('should properly scroll inside a scroll region (scrollTop and scrollBottom set)', () => {617 term.buffer.lines.get(0).setCell(0, CellData.fromCharData([0, 'a', 0, 'a'.charCodeAt(0)]));618 term.buffer.lines.get(1).setCell(0, CellData.fromCharData([0, 'b', 0, 'b'.charCodeAt(0)]));619 term.buffer.lines.get(2).setCell(0, CellData.fromCharData([0, 'c', 0, 'c'.charCodeAt(0)]));620 term.buffer.lines.get(3).setCell(0, CellData.fromCharData([0, 'd', 0, 'd'.charCodeAt(0)]));621 term.buffer.lines.get(4).setCell(0, CellData.fromCharData([0, 'e', 0, 'e'.charCodeAt(0)]));622 term.buffer.y = INIT_ROWS - 1; // Move cursor to last line623 term.buffer.scrollTop = 1;624 term.buffer.scrollBottom = 3;625 term.scroll();626 assert.equal(term.buffer.lines.length, INIT_ROWS);627 assert.equal(term.buffer.lines.get(0).loadCell(0, new CellData()).getChars(), 'a');628 assert.equal(term.buffer.lines.get(1).loadCell(0, new CellData()).getChars(), 'c', '\'b\' should be removed from the buffer');629 assert.equal(term.buffer.lines.get(2).loadCell(0, new CellData()).getChars(), 'd');630 assert.equal(term.buffer.lines.get(3).loadCell(0, new CellData()).getChars(), '', 'a blank line should be added at scrollBottom\'s index');631 assert.equal(term.buffer.lines.get(4).loadCell(0, new CellData()).getChars(), 'e');632 });633 });634 });635 });636 describe('Third level shift', () => {637 let evKeyDown: any;638 let evKeyPress: any;639 beforeEach(() => {640 term.handler = () => { };641 term.showCursor = () => { };642 term.clearSelection = () => { };643 // term.compositionHelper = {644 // isComposing: false,645 // keydown: {646 // bind: () => {647 // return () => { return true; };648 // }649 // }650 // };651 evKeyDown = {652 preventDefault: () => { },653 stopPropagation: () => { },654 type: 'keydown',655 altKey: null,656 keyCode: null657 };658 evKeyPress = {659 preventDefault: () => { },660 stopPropagation: () => { },661 type: 'keypress',662 altKey: null,663 charCode: null,664 keyCode: null665 };666 });667 describe('with macOptionIsMeta', () => {668 beforeEach(() => {669 term.browser.isMac = true;670 term.setOption('macOptionIsMeta', true);671 });672 it('should interfere with the alt key on keyDown', () => {673 evKeyDown.altKey = true;674 evKeyDown.keyCode = 81;675 assert.equal(term.keyDown(evKeyDown), false);676 evKeyDown.altKey = true;677 evKeyDown.keyCode = 192;678 assert.equal(term.keyDown(evKeyDown), false);679 });680 });681 describe('On Mac OS', () => {682 beforeEach(() => {683 term.browser.isMac = true;684 });685 it('should not interfere with the alt key on keyDown', () => {686 evKeyDown.altKey = true;687 evKeyDown.keyCode = 81;688 assert.equal(term.keyDown(evKeyDown), true);689 evKeyDown.altKey = true;690 evKeyDown.keyCode = 192;691 assert.equal(term.keyDown(evKeyDown), true);692 });693 it('should interefere with the alt + arrow keys', () => {694 evKeyDown.altKey = true;695 evKeyDown.keyCode = 37;696 assert.equal(term.keyDown(evKeyDown), false);697 evKeyDown.altKey = true;698 evKeyDown.keyCode = 39;699 assert.equal(term.keyDown(evKeyDown), false);700 });701 it('should emit key with alt + key on keyPress', (done) => {702 const keys = ['@', '@', '\\', '\\', '|', '|'];703 term.on('keypress', (key) => {704 if (key) {705 const index = keys.indexOf(key);706 assert(index !== -1, 'Emitted wrong key: ' + key);707 keys.splice(index, 1);708 }709 if (keys.length === 0) done();710 });711 evKeyPress.altKey = true;712 // @713 evKeyPress.charCode = null;714 evKeyPress.keyCode = 64;715 term.keyPress(evKeyPress);716 // Firefox @717 evKeyPress.charCode = 64;718 evKeyPress.keyCode = 0;719 term.keyPress(evKeyPress);720 // \721 evKeyPress.charCode = null;722 evKeyPress.keyCode = 92;723 term.keyPress(evKeyPress);724 // Firefox \725 evKeyPress.charCode = 92;726 evKeyPress.keyCode = 0;727 term.keyPress(evKeyPress);728 // |729 evKeyPress.charCode = null;730 evKeyPress.keyCode = 124;731 term.keyPress(evKeyPress);732 // Firefox |733 evKeyPress.charCode = 124;734 evKeyPress.keyCode = 0;735 term.keyPress(evKeyPress);736 });737 });738 describe('On MS Windows', () => {739 beforeEach(() => {740 term.browser.isMSWindows = true;741 });742 it('should not interfere with the alt + ctrl key on keyDown', () => {743 evKeyPress.altKey = true;744 evKeyPress.ctrlKey = true;745 evKeyPress.keyCode = 81;746 assert.equal(term.keyDown(evKeyPress), true);747 evKeyDown.altKey = true;748 evKeyDown.ctrlKey = true;749 evKeyDown.keyCode = 81;750 assert.equal(term.keyDown(evKeyDown), true);751 });752 it('should interefere with the alt + ctrl + arrow keys', () => {753 evKeyDown.altKey = true;754 evKeyDown.ctrlKey = true;755 evKeyDown.keyCode = 37;756 assert.equal(term.keyDown(evKeyDown), false);757 evKeyDown.keyCode = 39;758 assert.equal(term.keyDown(evKeyDown), false);759 });760 it('should emit key with alt + ctrl + key on keyPress', (done) => {761 const keys = ['@', '@', '\\', '\\', '|', '|'];762 term.on('keypress', (key) => {763 if (key) {764 const index = keys.indexOf(key);765 assert(index !== -1, 'Emitted wrong key: ' + key);766 keys.splice(index, 1);767 }768 if (keys.length === 0) done();769 });770 evKeyPress.altKey = true;771 evKeyPress.ctrlKey = true;772 // @773 evKeyPress.charCode = null;774 evKeyPress.keyCode = 64;775 term.keyPress(evKeyPress);776 // Firefox @777 evKeyPress.charCode = 64;778 evKeyPress.keyCode = 0;779 term.keyPress(evKeyPress);780 // \781 evKeyPress.charCode = null;782 evKeyPress.keyCode = 92;783 term.keyPress(evKeyPress);784 // Firefox \785 evKeyPress.charCode = 92;786 evKeyPress.keyCode = 0;787 term.keyPress(evKeyPress);788 // |789 evKeyPress.charCode = null;790 evKeyPress.keyCode = 124;791 term.keyPress(evKeyPress);792 // Firefox |793 evKeyPress.charCode = 124;794 evKeyPress.keyCode = 0;795 term.keyPress(evKeyPress);796 });797 });798 });799 describe('unicode - surrogates', () => {800 it('2 characters per cell', function (): void {801 this.timeout(10000); // This is needed because istanbul patches code and slows it down802 const high = String.fromCharCode(0xD800);803 const cell = new CellData();804 for (let i = 0xDC00; i <= 0xDCFF; ++i) {805 term.write(high + String.fromCharCode(i));806 const tchar = term.buffer.lines.get(0).loadCell(0, cell);807 expect(tchar.getChars()).eql(high + String.fromCharCode(i));808 expect(tchar.getChars().length).eql(2);809 expect(tchar.getWidth()).eql(1);810 expect(term.buffer.lines.get(0).loadCell(1, cell).getChars()).eql('');811 term.reset();812 }813 });814 it('2 characters at last cell', () => {815 const high = String.fromCharCode(0xD800);816 const cell = new CellData();817 for (let i = 0xDC00; i <= 0xDCFF; ++i) {818 term.buffer.x = term.cols - 1;819 term.write(high + String.fromCharCode(i));820 expect(term.buffer.lines.get(0).loadCell(term.buffer.x - 1, cell).getChars()).eql(high + String.fromCharCode(i));821 expect(term.buffer.lines.get(0).loadCell(term.buffer.x - 1, cell).getChars().length).eql(2);822 expect(term.buffer.lines.get(1).loadCell(0, cell).getChars()).eql('');823 term.reset();824 }825 });826 it('2 characters per cell over line end with autowrap', () => {827 const high = String.fromCharCode(0xD800);828 const cell = new CellData();829 for (let i = 0xDC00; i <= 0xDCFF; ++i) {830 term.buffer.x = term.cols - 1;831 term.wraparoundMode = true;832 term.write('a' + high + String.fromCharCode(i));833 expect(term.buffer.lines.get(0).loadCell(term.cols - 1, cell).getChars()).eql('a');834 expect(term.buffer.lines.get(1).loadCell(0, cell).getChars()).eql(high + String.fromCharCode(i));835 expect(term.buffer.lines.get(1).loadCell(0, cell).getChars().length).eql(2);836 expect(term.buffer.lines.get(1).loadCell(1, cell).getChars()).eql('');837 term.reset();838 }839 });840 it('2 characters per cell over line end without autowrap', () => {841 const high = String.fromCharCode(0xD800);842 const cell = new CellData();843 for (let i = 0xDC00; i <= 0xDCFF; ++i) {844 term.buffer.x = term.cols - 1;845 term.wraparoundMode = false;846 term.write('a' + high + String.fromCharCode(i));847 // auto wraparound mode should cut off the rest of the line848 expect(term.buffer.lines.get(0).loadCell(term.cols - 1, cell).getChars()).eql('a');849 expect(term.buffer.lines.get(0).loadCell(term.cols - 1, cell).getChars().length).eql(1);850 expect(term.buffer.lines.get(1).loadCell(1, cell).getChars()).eql('');851 term.reset();852 }853 });854 it('splitted surrogates', () => {855 const high = String.fromCharCode(0xD800);856 const cell = new CellData();857 for (let i = 0xDC00; i <= 0xDCFF; ++i) {858 term.write(high);859 term.write(String.fromCharCode(i));860 const tchar = term.buffer.lines.get(0).loadCell(0, cell);861 expect(tchar.getChars()).eql(high + String.fromCharCode(i));862 expect(tchar.getChars().length).eql(2);863 expect(tchar.getWidth()).eql(1);864 expect(term.buffer.lines.get(0).loadCell(1, cell).getChars()).eql('');865 term.reset();866 }867 });868 });869 describe('unicode - combining characters', () => {870 const cell = new CellData();871 it('café', () => {872 term.write('cafe\u0301');873 term.buffer.lines.get(0).loadCell(3, cell);874 expect(cell.getChars()).eql('e\u0301');875 expect(cell.getChars().length).eql(2);876 expect(cell.getWidth()).eql(1);877 });878 it('café - end of line', () => {879 term.buffer.x = term.cols - 1 - 3;880 term.write('cafe\u0301');881 term.buffer.lines.get(0).loadCell(term.cols - 1, cell);882 expect(cell.getChars()).eql('e\u0301');883 expect(cell.getChars().length).eql(2);884 expect(cell.getWidth()).eql(1);885 term.buffer.lines.get(0).loadCell(1, cell);886 expect(cell.getChars()).eql('');887 expect(cell.getChars().length).eql(0);888 expect(cell.getWidth()).eql(1);889 });890 it('multiple combined é', () => {891 term.wraparoundMode = true;892 term.write(Array(100).join('e\u0301'));893 for (let i = 0; i < term.cols; ++i) {894 term.buffer.lines.get(0).loadCell(i, cell);895 expect(cell.getChars()).eql('e\u0301');896 expect(cell.getChars().length).eql(2);897 expect(cell.getWidth()).eql(1);898 }899 term.buffer.lines.get(1).loadCell(0, cell);900 expect(cell.getChars()).eql('e\u0301');901 expect(cell.getChars().length).eql(2);902 expect(cell.getWidth()).eql(1);903 });904 it('multiple surrogate with combined', () => {905 term.wraparoundMode = true;906 term.write(Array(100).join('\uD800\uDC00\u0301'));907 for (let i = 0; i < term.cols; ++i) {908 term.buffer.lines.get(0).loadCell(i, cell);909 expect(cell.getChars()).eql('\uD800\uDC00\u0301');910 expect(cell.getChars().length).eql(3);911 expect(cell.getWidth()).eql(1);912 }913 term.buffer.lines.get(1).loadCell(0, cell);914 expect(cell.getChars()).eql('\uD800\uDC00\u0301');915 expect(cell.getChars().length).eql(3);916 expect(cell.getWidth()).eql(1);917 });918 });919 describe('unicode - fullwidth characters', () => {920 const cell = new CellData();921 it('cursor movement even', () => {922 expect(term.buffer.x).eql(0);923 term.write('¥');924 expect(term.buffer.x).eql(2);925 });926 it('cursor movement odd', () => {927 term.buffer.x = 1;928 expect(term.buffer.x).eql(1);929 term.write('¥');930 expect(term.buffer.x).eql(3);931 });932 it('line of ¥ even', () => {933 term.wraparoundMode = true;934 term.write(Array(50).join('¥'));935 for (let i = 0; i < term.cols; ++i) {936 term.buffer.lines.get(0).loadCell(i, cell);937 if (i % 2) {938 expect(cell.getChars()).eql('');939 expect(cell.getChars().length).eql(0);940 expect(cell.getWidth()).eql(0);941 } else {942 expect(cell.getChars()).eql('¥');943 expect(cell.getChars().length).eql(1);944 expect(cell.getWidth()).eql(2);945 }946 }947 term.buffer.lines.get(1).loadCell(0, cell);948 expect(cell.getChars()).eql('¥');949 expect(cell.getChars().length).eql(1);950 expect(cell.getWidth()).eql(2);951 });952 it('line of ¥ odd', () => {953 term.wraparoundMode = true;954 term.buffer.x = 1;955 term.write(Array(50).join('¥'));956 for (let i = 1; i < term.cols - 1; ++i) {957 term.buffer.lines.get(0).loadCell(i, cell);958 if (!(i % 2)) {959 expect(cell.getChars()).eql('');960 expect(cell.getChars().length).eql(0);961 expect(cell.getWidth()).eql(0);962 } else {963 expect(cell.getChars()).eql('¥');964 expect(cell.getChars().length).eql(1);965 expect(cell.getWidth()).eql(2);966 }967 }968 term.buffer.lines.get(0).loadCell(term.cols - 1, cell);969 expect(cell.getChars()).eql('');970 expect(cell.getChars().length).eql(0);971 expect(cell.getWidth()).eql(1);972 term.buffer.lines.get(1).loadCell(0, cell);973 expect(cell.getChars()).eql('¥');974 expect(cell.getChars().length).eql(1);975 expect(cell.getWidth()).eql(2);976 });977 it('line of ¥ with combining odd', () => {978 term.wraparoundMode = true;979 term.buffer.x = 1;980 term.write(Array(50).join('¥\u0301'));981 for (let i = 1; i < term.cols - 1; ++i) {982 term.buffer.lines.get(0).loadCell(i, cell);983 if (!(i % 2)) {984 expect(cell.getChars()).eql('');985 expect(cell.getChars().length).eql(0);986 expect(cell.getWidth()).eql(0);987 } else {988 expect(cell.getChars()).eql('¥\u0301');989 expect(cell.getChars().length).eql(2);990 expect(cell.getWidth()).eql(2);991 }992 }993 term.buffer.lines.get(0).loadCell(term.cols - 1, cell);994 expect(cell.getChars()).eql('');995 expect(cell.getChars().length).eql(0);996 expect(cell.getWidth()).eql(1);997 term.buffer.lines.get(1).loadCell(0, cell);998 expect(cell.getChars()).eql('¥\u0301');999 expect(cell.getChars().length).eql(2);1000 expect(cell.getWidth()).eql(2);1001 });1002 it('line of ¥ with combining even', () => {1003 term.wraparoundMode = true;1004 term.write(Array(50).join('¥\u0301'));1005 for (let i = 0; i < term.cols; ++i) {1006 term.buffer.lines.get(0).loadCell(i, cell);1007 if (i % 2) {1008 expect(cell.getChars()).eql('');1009 expect(cell.getChars().length).eql(0);1010 expect(cell.getWidth()).eql(0);1011 } else {1012 expect(cell.getChars()).eql('¥\u0301');1013 expect(cell.getChars().length).eql(2);1014 expect(cell.getWidth()).eql(2);1015 }1016 }1017 term.buffer.lines.get(1).loadCell(0, cell);1018 expect(cell.getChars()).eql('¥\u0301');1019 expect(cell.getChars().length).eql(2);1020 expect(cell.getWidth()).eql(2);1021 });1022 it('line of surrogate fullwidth with combining odd', () => {1023 term.wraparoundMode = true;1024 term.buffer.x = 1;1025 term.write(Array(50).join('\ud843\ude6d\u0301'));1026 for (let i = 1; i < term.cols - 1; ++i) {1027 term.buffer.lines.get(0).loadCell(i, cell);1028 if (!(i % 2)) {1029 expect(cell.getChars()).eql('');1030 expect(cell.getChars().length).eql(0);1031 expect(cell.getWidth()).eql(0);1032 } else {1033 expect(cell.getChars()).eql('\ud843\ude6d\u0301');1034 expect(cell.getChars().length).eql(3);1035 expect(cell.getWidth()).eql(2);1036 }1037 }1038 term.buffer.lines.get(0).loadCell(term.cols - 1, cell);1039 expect(cell.getChars()).eql('');1040 expect(cell.getChars().length).eql(0);1041 expect(cell.getWidth()).eql(1);1042 term.buffer.lines.get(1).loadCell(0, cell);1043 expect(cell.getChars()).eql('\ud843\ude6d\u0301');1044 expect(cell.getChars().length).eql(3);1045 expect(cell.getWidth()).eql(2);1046 });1047 it('line of surrogate fullwidth with combining even', () => {1048 term.wraparoundMode = true;1049 term.write(Array(50).join('\ud843\ude6d\u0301'));1050 for (let i = 0; i < term.cols; ++i) {1051 term.buffer.lines.get(0).loadCell(i, cell);1052 if (i % 2) {1053 expect(cell.getChars()).eql('');1054 expect(cell.getChars().length).eql(0);1055 expect(cell.getWidth()).eql(0);1056 } else {1057 expect(cell.getChars()).eql('\ud843\ude6d\u0301');1058 expect(cell.getChars().length).eql(3);1059 expect(cell.getWidth()).eql(2);1060 }1061 }1062 term.buffer.lines.get(1).loadCell(0, cell);1063 expect(cell.getChars()).eql('\ud843\ude6d\u0301');1064 expect(cell.getChars().length).eql(3);1065 expect(cell.getWidth()).eql(2);1066 });1067 });1068 describe('insert mode', () => {1069 const cell = new CellData();1070 it('halfwidth - all', () => {1071 term.write(Array(9).join('0123456789').slice(-80));1072 term.buffer.x = 10;1073 term.buffer.y = 0;1074 term.insertMode = true;1075 term.write('abcde');1076 expect(term.buffer.lines.get(0).length).eql(term.cols);1077 expect(term.buffer.lines.get(0).loadCell(10, cell).getChars()).eql('a');1078 expect(term.buffer.lines.get(0).loadCell(14, cell).getChars()).eql('e');1079 expect(term.buffer.lines.get(0).loadCell(15, cell).getChars()).eql('0');1080 expect(term.buffer.lines.get(0).loadCell(79, cell).getChars()).eql('4');1081 });1082 it('fullwidth - insert', () => {1083 term.write(Array(9).join('0123456789').slice(-80));1084 term.buffer.x = 10;1085 term.buffer.y = 0;1086 term.insertMode = true;1087 term.write('¥¥¥');1088 expect(term.buffer.lines.get(0).length).eql(term.cols);1089 expect(term.buffer.lines.get(0).loadCell(10, cell).getChars()).eql('¥');1090 expect(term.buffer.lines.get(0).loadCell(11, cell).getChars()).eql('');1091 expect(term.buffer.lines.get(0).loadCell(14, cell).getChars()).eql('¥');1092 expect(term.buffer.lines.get(0).loadCell(15, cell).getChars()).eql('');1093 expect(term.buffer.lines.get(0).loadCell(79, cell).getChars()).eql('3');1094 });1095 it('fullwidth - right border', () => {1096 term.write(Array(41).join('¥'));1097 term.buffer.x = 10;1098 term.buffer.y = 0;1099 term.insertMode = true;1100 term.write('a');1101 expect(term.buffer.lines.get(0).length).eql(term.cols);1102 expect(term.buffer.lines.get(0).loadCell(10, cell).getChars()).eql('a');1103 expect(term.buffer.lines.get(0).loadCell(11, cell).getChars()).eql('¥');1104 expect(term.buffer.lines.get(0).loadCell(79, cell).getChars()).eql(''); // fullwidth char got replaced1105 term.write('b');1106 expect(term.buffer.lines.get(0).length).eql(term.cols);1107 expect(term.buffer.lines.get(0).loadCell(11, cell).getChars()).eql('b');1108 expect(term.buffer.lines.get(0).loadCell(12, cell).getChars()).eql('¥');1109 expect(term.buffer.lines.get(0).loadCell(79, cell).getChars()).eql(''); // empty cell after fullwidth1110 });1111 });...

Full Screen

Full Screen

4.5 清除可选类型的尾类型递归.ts

Source:4.5 清除可选类型的尾类型递归.ts Github

copy

Full Screen

1/**2 * 当可选类型中出现递归时, ts 会判断是不是 无限递归 ,而报错3 * */4{5 type InfiniteBox<T> = { item: InfiniteBox<T> };6 type Unpack<T> = T extends { item: infer U } ? Unpack<U> : T;7 // error: Type instantiation is excessively deep and possibly infinite.8 // type Test = Unpack<InfiniteBox<number>>9 type Test2 = Unpack<{ item: { item: { item: { item: number } } } }>; // 有限的递归 ok10}11{12 type TrimLeft<T extends string> = T extends ` ${infer Rest}`13 ? TrimLeft<Rest>14 : T;15 // Test = "hello" | "world"16 type Test1 = TrimLeft<" hello" | " world">;17 // 报错 递归超过50次18 // error: Type instantiation is excessively deep and possibly infinite.19 // type Test = TrimLeft<"20}21{22 // 这个类型不能被 尾类型递归 优化23 // 因为 最后是一个类型24 type GetChars<S> = S extends `${infer Char}${infer Rest}`25 ? Char | GetChars<Rest>26 : never;27 type Test1 = GetChars<"1234567890">;28 // error 超过50个29 // type Test2 = GetChars<"123456789012345678901234567890123456789012345678901234567890">;30}31{32 // 为了被 尾递归优化, 就需要写一个帮助函数33 // 递归时没有其他额外的内容`34 type GetChars<S> = GetCharsHelper<S, never>;35 type GetCharsHelper<S, Acc> = S extends `${infer Char}${infer Rest}`36 ? GetCharsHelper<Rest, Char | Acc>37 : Acc;38 type Test1 = GetChars<"01234657890">;39 // 依然ok40 type Test2 =41 GetChars<"1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890">;42 // 也是ok43 type Test3 =44 GetChars<"当 TypeScript 检测到可能的无限递归或任何可能需要很长时间并影响您的编辑器体验的类型扩展时,它通常需要优雅地失败。因此,TypeScript 具有启发式方法,可确保在尝试分离无限深的类型或处理会生成大量中间结果的类型时不会脱轨。这就是 TypeScript 4.5 对条件类型执行一些尾递归消除的原因。只要条件类型的一个分支只是另一种条件类型,TypeScript 就可以避免中间实例化。仍然有一些启发式方法可以确保这些类型不会偏离轨道,但它们要大得多。">;45}...

Full Screen

Full Screen

pretty-env.ts

Source:pretty-env.ts Github

copy

Full Screen

...51 // so I will list each newline.52 const envList: EnvList = stdout.toString().trim().split("\n");53 const { nameMaxSize, valueMaxSize } = getMaxSize(envList);54 let tableLength = Math.trunc(nameMaxSize + valueMaxSize + MARGIN);55 let displayText = getChars(tableLength, "-");56 for (const env of envList) {57 let nameSpaceLength = 0;58 let valueSpaceLength = 0;59 const name = env.split("=")[0];60 const value = env.split("=")[1];61 if (nameMaxSize > name.length) {62 nameSpaceLength = Math.trunc(nameMaxSize - name.length);63 }64 if (valueMaxSize > value.length) {65 valueSpaceLength = Math.trunc(valueMaxSize - value.length);66 }67 displayText += "\n";68 displayText += getChars(1, "|");69 displayText += getChars(LEFT_MARGIN, " ");70 if (name.length > (nameMaxSize - ELLIPSES_TEXT.length)) {71 displayText += name.substring(72 0,73 nameMaxSize - (ELLIPSES_TEXT.length + 1),74 );75 displayText += ELLIPSES_TEXT;76 } else {77 displayText += name;78 }79 if (nameSpaceLength) {80 displayText += getChars(nameSpaceLength - LEFT_MARGIN, " ");81 }82 displayText += getChars(1, "|");83 displayText += getChars(LEFT_MARGIN, " ");84 if (value.length > (valueMaxSize - ELLIPSES_TEXT.length)) {85 displayText += value.substring(86 0,87 valueMaxSize - (ELLIPSES_TEXT.length + 1),88 );89 displayText += ELLIPSES_TEXT;90 } else {91 displayText += value;92 }93 if (valueSpaceLength) {94 displayText += getChars(valueSpaceLength - LEFT_MARGIN, " ");95 }96 displayText += getChars(1, "|");97 displayText += "\n";98 displayText += getChars(tableLength, "-");99 }100 console.log(displayText);101};...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1import { mount } from '@vue/test-utils'2import StorybookRoot from './storybook-root.vue'3describe('storybook-root', () => {4 test('getChars method', () => {5 const wrapper = mount(StorybookRoot)6 const result = wrapper.vm.getChars()7 expect(result).toBe('Hello World')8 })9})10export default {11 methods: {12 getChars() {13 }14 }15}16import { mount } from '@vue/test-utils'17import StorybookRoot from './storybook-root.vue'18describe('storybook-root', () => {19 test('getChars method', () => {20 const wrapper = mount(StorybookRoot)21 const result = wrapper.vm.getChars()22 expect(result).toBe('Hello World')23 })24})25 6 | test('getChars method', () => {26 7 | const wrapper = mount(StorybookRoot)27 > 8 | const result = wrapper.vm.getChars()28 9 | expect(result).toBe('Hello World')29 10 | })30 11 | })31 at Object.toBe (test.js:8:30)

Full Screen

Using AI Code Generation

copy

Full Screen

1var storybook = require('storybook-root');2storybook.getChars(function(err,chars){3 console.log(chars);4});5storybook.getChars(function(err,chars){6 console.log(chars);7});8require('storybook-root.php');9storybook\getChars(function($err,$chars){10 echo $chars;11});12require('storybook-root.php');13storybook\getChars(function($err,$chars){14 echo $chars;15});16use storybook\storybook;17storybook::getChars(function($err,$chars){18 echo $chars;19});20use storybook\storybook;21$storybook = new storybook();22$storybook->getChars(function($err,$chars){23 echo $chars;24});25use storybook\storybook;26storybook::getChars(function($err,$chars){27 echo $chars;28});29use storybook\storybook;30$storybook = new storybook();31$storybook->getChars(function($err,$chars){32 echo $chars;33});34use storybook\storybook;35storybook::getChars(function($err,$chars){36 echo $chars;37});38use storybook\storybook;39$storybook = new storybook();40$storybook->getChars(function($err,$chars){41 echo $chars;42});43use storybook\storybook;44storybook::getChars(function($err,$chars){45 echo $chars;46});47use storybook\storybook;48$storybook = new storybook();49$storybook->getChars(function($err,$chars){

Full Screen

Using AI Code Generation

copy

Full Screen

1var root = require("storybook-root");2root.getChars();3module.exports = {4 getChars: function() {5 return ["Harry Potter", "Hermione Granger", "Ron Weasley"];6 }7};8var root = require("storybook-root");9root.getChars();10module.exports = {11 getChars: function() {12 return ["Harry Potter", "Hermione Granger", "Ron Weasley"];13 }14};15var root = require("storybook-root");16root.getChars();17module.exports = {18 getChars: function() {19 return ["Harry Potter", "Hermione Granger", "Ron Weasley"];20 }21};22var root = require("storybook-root");23root.getChars();24module.exports = {25 getChars: function() {26 return ["Harry Potter", "Hermione Granger", "Ron Weasley"];27 }28};29var root = require("storybook-root");30root.getChars();31module.exports = {32 getChars: function() {33 return ["Harry Potter", "Hermione Granger", "Ron Weasley"];34 }35};36var root = require("storybook-root");37root.getChars();38module.exports = {39 getChars: function() {40 return ["Harry Potter", "Hermione Granger", "Ron Weasley"];41 }42};43var root = require("storybook-root");44root.getChars();45module.exports = {46 getChars: function() {

Full Screen

Using AI Code Generation

copy

Full Screen

1const { getChars } = require('storybook-root');2getChars().then(chars => {3 console.log(chars);4});5const { getChars } = require('storybook-root');6getChars().then(chars => {7 console.log(chars);8});9const { getChars } = require('storybook-root');10getChars().then(chars => {11 console.log(chars);12});13const { getChars } = require('storybook-root');14getChars().then(chars => {15 console.log(chars);16});17const { getChars } = require('storybook-root');18getChars().then(chars => {19 console.log(chars);20});21const { getChars } = require('storybook-root');22getChars().then(chars => {23 console.log(chars);24});25const { getChars } = require('storybook-root');26getChars().then(chars => {27 console.log(chars);28});29const { getChars } = require('storybook-root');30getChars().then(chars => {31 console.log(chars);32});33const { getChars } = require('storybook-root');34getChars().then(chars => {35 console.log(chars);36});37const { getChars } = require('storybook-root');38getChars().then(chars => {39 console.log(chars);40});41const { getChars } = require('storybook

Full Screen

Using AI Code Generation

copy

Full Screen

1var storybook = require('storybook-root');2storybook.getChars(function(err, chars){3 if(err){4 console.log(err);5 }else{6 console.log(chars);7 }8});9exports.getChars = function(callback){10 fs.readFile(path.join(__dirname, 'data', 'chars.json'), function(err, data){11 if(err){12 callback(err, null);13 }else{14 var chars = JSON.parse(data);15 callback(null, chars);16 }17 });18};19fs.readFile = function(filename, callback){20 fs.open(filename, 'r', function(err, fd){21 if(err){22 callback(err, null);23 }else{24 fs.fstat(fd, function(err, stat){25 if(err){26 callback(err, null);27 }else{28 var buf = new Buffer(stat.size);29 fs.read(fd, buf, 0, stat.size,

Full Screen

Using AI Code Generation

copy

Full Screen

1import React from 'react';2import ReactDOM from 'react-dom';3import { getChars } from './components/storybook-root';4class Test extends React.Component {5 constructor(props) {6 super(props);7 this.state = {8 }9 }10 componentDidMount() {11 getChars()12 .then((chars) => {13 this.setState({14 })15 })16 }17 render() {18 return (19 {this.state.characters.map((char) => {20 return (21 <h1>{char.name}</h1>22 <p>{char.description}</p>23 })}24 }25}26ReactDOM.render(27 document.getElementById('root')28);

Full Screen

Using AI Code Generation

copy

Full Screen

1var storybookRoot = require('storybook-root');2var characters = storybookRoot.getChars();3console.log(characters);4var storybookRoot = require('storybook-root');5var characters = storybookRoot.getChars();6console.log(characters);7var storybookRoot = require('storybook-root');8var characters = storybookRoot.getChars();9console.log(characters);10var storybookRoot = require('storybook-root');11var characters = storybookRoot.getChars();12console.log(characters);13var storybookRoot = require('storybook-root');14var characters = storybookRoot.getChars();15console.log(characters);16var storybookRoot = require('storybook-root');

Full Screen

Using AI Code Generation

copy

Full Screen

1var root = require('storybook-root');2var chars = root.getChars();3var story = root.getStory(chars[0]);4console.log(story);5var root = require('storybook-root');6var chars = root.getChars();7var story = root.getStory(chars[0]);8console.log(story);9var root = require('storybook-root');10var chars = root.getChars();11var story = root.getStory(chars[0]);12console.log(story);13var root = require('storybook-root');14var chars = root.getChars();15var story = root.getStory(chars[0]);16console.log(story);17var root = require('storybook-root');18var chars = root.getChars();19var story = root.getStory(chars[0]);20console.log(story);21var root = require('storybook-root');

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 storybook-root 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