1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126
|
Description: switch test from ava to tape
Author: Xavier Guimard <yadd@debian.org>
Forwarded: not-needed
Last-Update: 2020-02-18
--- a/test.js
+++ b/test.js
@@ -1,49 +1,56 @@
-import test from 'ava';
-import ansiCodes from './fixtures/ansi-codes';
-import ansiRegex from '.';
+const test = require('tape');
+const ansiCodes = require('./fixtures/ansi-codes');
+const ansiRegex = require('.');
const consumptionCharacters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!@#$%^&*()_+1234567890-=[]{};\':"./>?,<\\|';
// Testing against codes found at: http://ascii-table.com/ansi-escape-sequences-vt-100.php
test('match ansi code in a string', t => {
- t.regex('foo\u001B[4mcake\u001B[0m', ansiRegex());
- t.regex('\u001B[4mcake\u001B[0m', ansiRegex());
- t.regex('foo\u001B[4mcake\u001B[0m', ansiRegex());
- t.regex('\u001B[0m\u001B[4m\u001B[42m\u001B[31mfoo\u001B[39m\u001B[49m\u001B[24mfoo\u001B[0m', ansiRegex());
- t.regex('foo\u001B[mfoo', ansiRegex());
+ t.ok('foo\u001B[4mcake\u001B[0m'.match(ansiRegex()));
+ t.ok('\u001B[4mcake\u001B[0m'.match(ansiRegex()));
+ t.ok('foo\u001B[4mcake\u001B[0m'.match(ansiRegex()));
+ t.ok('\u001B[0m\u001B[4m\u001B[42m\u001B[31mfoo\u001B[39m\u001B[49m\u001B[24mfoo\u001B[0m'.match(ansiRegex()));
+ t.ok('foo\u001B[mfoo'.match(ansiRegex()));
+ t.end();
});
test('match ansi code from ls command', t => {
- t.regex('\u001B[00;38;5;244m\u001B[m\u001B[00;38;5;33mfoo\u001B[0m', ansiRegex());
+ t.ok('\u001B[00;38;5;244m\u001B[m\u001B[00;38;5;33mfoo\u001B[0m'.match(ansiRegex()));
+ t.end();
});
test('match reset;setfg;setbg;italics;strike;underline sequence in a string', t => {
- t.regex('\u001B[0;33;49;3;9;4mbar\u001B[0m', ansiRegex());
+ t.ok('\u001B[0;33;49;3;9;4mbar\u001B[0m'.match(ansiRegex()));
t.is('foo\u001B[0;33;49;3;9;4mbar'.match(ansiRegex())[0], '\u001B[0;33;49;3;9;4m');
+ t.end();
});
test('match clear tabs sequence in a string', t => {
- t.regex('foo\u001B[0gbar', ansiRegex());
+ t.ok('foo\u001B[0gbar'.match(ansiRegex()));
t.is('foo\u001B[0gbar'.match(ansiRegex())[0], '\u001B[0g');
+ t.end();
});
test('match clear line from cursor right in a string', t => {
- t.regex('foo\u001B[Kbar', ansiRegex());
+ t.ok('foo\u001B[Kbar'.match(ansiRegex()));
t.is('foo\u001B[Kbar'.match(ansiRegex())[0], '\u001B[K');
+ t.end();
});
test('match clear screen in a string', t => {
- t.regex('foo\u001B[2Jbar', ansiRegex());
+ t.ok('foo\u001B[2Jbar'.match(ansiRegex()));
t.is('foo\u001B[2Jbar'.match(ansiRegex())[0], '\u001B[2J');
+ t.end();
});
test('match only first', t => {
t.is('foo\u001B[4mcake\u001B[0m'.match(ansiRegex({onlyFirst: true})).length, 1);
+ t.end();
});
test('match terminal link', t => {
- t.regex('\u001B]8;k=v;https://example-a.com/?a_b=1&c=2#tit%20le\u0007click\u001B]8;;\u0007', ansiRegex());
- t.regex('\u001B]8;;mailto:no-replay@mail.com\u0007mail\u001B]8;;\u0007', ansiRegex());
+ t.ok('\u001B]8;k=v;https://example-a.com/?a_b=1&c=2#tit%20le\u0007click\u001B]8;;\u0007'.match(ansiRegex()));
+ t.ok('\u001B]8;;mailto:no-replay@mail.com\u0007mail\u001B]8;;\u0007'.match(ansiRegex()));
t.deepEqual('\u001B]8;k=v;https://example-a.com/?a_b=1&c=2#tit%20le\u0007click\u001B]8;;\u0007'.match(ansiRegex()), [
'\u001B]8;k=v;https://example-a.com/?a_b=1&c=2#tit%20le\u0007',
'\u001B]8;;\u0007'
@@ -52,10 +59,12 @@
'\u001B]8;;mailto:no-reply@mail.com\u0007',
'\u001B]8;;\u0007'
]);
+ t.end();
});
test('match "change icon name and window title" in string', t => {
t.is('\u001B]0;sg@tota:~/git/\u0007\u001B[01;32m[sg@tota\u001B[01;37m misc-tests\u001B[01;32m]$'.match(ansiRegex())[0], '\u001B]0;sg@tota:~/git/\u0007');
+ t.end();
});
// Testing against extended codes (excluding codes ending in 0-9)
@@ -70,27 +79,31 @@
test(`${codeSet} - ${skipText}${code} → ${codeInfo[0]}`, t => {
if (skip) {
t.pass();
+ t.end();
return;
}
const string = `hel${ecode}lo`;
- t.regex(string, ansiRegex());
+ t.ok(string.match(ansiRegex()));
t.is(string.match(ansiRegex())[0], ecode);
t.is(string.replace(ansiRegex(), ''), 'hello');
+ t.end();
});
test(`${codeSet} - ${skipText}${code} should not overconsume`, t => {
if (skip) {
t.pass();
+ t.end();
return;
}
for (const c of consumptionCharacters) {
const string = ecode + c;
- t.regex(string, ansiRegex());
+ t.ok(string.match(ansiRegex()));
t.is(string.match(ansiRegex())[0], ecode);
t.is(string.replace(ansiRegex(), ''), c);
}
+ t.end();
});
}
}
|