code.gitea.io/gitea@v1.21.7/web_src/js/render/ansi.test.js (about) 1 import {renderAnsi} from './ansi.js'; 2 3 test('renderAnsi', () => { 4 expect(renderAnsi('abc')).toEqual('abc'); 5 expect(renderAnsi('abc\n')).toEqual('abc'); 6 expect(renderAnsi('abc\r\n')).toEqual('abc'); 7 expect(renderAnsi('\r')).toEqual(''); 8 expect(renderAnsi('\rx\rabc')).toEqual('x\nabc'); 9 expect(renderAnsi('\rabc\rx\r')).toEqual('abc\nx'); 10 expect(renderAnsi('\x1b[30mblack\x1b[37mwhite')).toEqual('<span class="ansi-black-fg">black</span><span class="ansi-white-fg">white</span>'); // unclosed 11 expect(renderAnsi('<script>')).toEqual('<script>'); 12 expect(renderAnsi('\x1b[1A\x1b[2Ktest\x1b[1B\x1b[1A\x1b[2K')).toEqual('test'); 13 expect(renderAnsi('\x1b[1A\x1b[2K\rtest\r\x1b[1B\x1b[1A\x1b[2K')).toEqual('test'); 14 expect(renderAnsi('\x1b[1A\x1b[2Ktest\x1b[1B\x1b[1A\x1b[2K')).toEqual('test'); 15 expect(renderAnsi('\x1b[1A\x1b[2K\rtest\r\x1b[1B\x1b[1A\x1b[2K')).toEqual('test'); 16 17 // treat "\033[0K" and "\033[0J" (Erase display/line) as "\r", then it will be covered to "\n" finally. 18 expect(renderAnsi('a\x1b[Kb\x1b[2Jc')).toEqual('a\nb\nc'); 19 expect(renderAnsi('\x1b[48;5;88ma\x1b[38;208;48;5;159mb\x1b[m')).toEqual(`<span style="background-color:rgb(135,0,0)">a</span><span style="background-color:rgb(175,255,255)">b</span>`); 20 });