diff options
author | Daniel Baumann <daniel@debian.org> | 2024-10-18 20:33:49 +0200 |
---|---|---|
committer | Daniel Baumann <daniel@debian.org> | 2024-12-12 23:57:56 +0100 |
commit | e68b9d00a6e05b3a941f63ffb696f91e554ac5ec (patch) | |
tree | 97775d6c13b0f416af55314eb6a89ef792474615 /web_src/js/render/ansi.test.js | |
parent | Initial commit. (diff) | |
download | forgejo-e68b9d00a6e05b3a941f63ffb696f91e554ac5ec.tar.xz forgejo-e68b9d00a6e05b3a941f63ffb696f91e554ac5ec.zip |
Adding upstream version 9.0.3.
Signed-off-by: Daniel Baumann <daniel@debian.org>
Diffstat (limited to 'web_src/js/render/ansi.test.js')
-rw-r--r-- | web_src/js/render/ansi.test.js | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/web_src/js/render/ansi.test.js b/web_src/js/render/ansi.test.js new file mode 100644 index 0000000..5afff71 --- /dev/null +++ b/web_src/js/render/ansi.test.js @@ -0,0 +1,20 @@ +import {renderAnsi} from './ansi.js'; + +test('renderAnsi', () => { + expect(renderAnsi('abc')).toEqual('abc'); + expect(renderAnsi('abc\n')).toEqual('abc'); + expect(renderAnsi('abc\r\n')).toEqual('abc'); + expect(renderAnsi('\r')).toEqual(''); + expect(renderAnsi('\rx\rabc')).toEqual('x\nabc'); + expect(renderAnsi('\rabc\rx\r')).toEqual('abc\nx'); + expect(renderAnsi('\x1b[30mblack\x1b[37mwhite')).toEqual('<span class="ansi-black-fg">black</span><span class="ansi-white-fg">white</span>'); // unclosed + expect(renderAnsi('<script>')).toEqual('<script>'); + expect(renderAnsi('\x1b[1A\x1b[2Ktest\x1b[1B\x1b[1A\x1b[2K')).toEqual('test'); + expect(renderAnsi('\x1b[1A\x1b[2K\rtest\r\x1b[1B\x1b[1A\x1b[2K')).toEqual('test'); + expect(renderAnsi('\x1b[1A\x1b[2Ktest\x1b[1B\x1b[1A\x1b[2K')).toEqual('test'); + expect(renderAnsi('\x1b[1A\x1b[2K\rtest\r\x1b[1B\x1b[1A\x1b[2K')).toEqual('test'); + + // treat "\033[0K" and "\033[0J" (Erase display/line) as "\r", then it will be covered to "\n" finally. + expect(renderAnsi('a\x1b[Kb\x1b[2Jc')).toEqual('a\nb\nc'); + 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>`); +}); |