Это ide на основе vs code(code oss), в ней будет встроенный умный апи роутинг, свой маркет с плагинами(агент харнесс, поддержка java/kotlin/мобильной разработки, командная разработка проектов, orca, оркестратор агентов
/**
* Instantiate services for use by the functions being tested.
*/
setup
(
(
)
=>
{
=
new
DisposableStore
(
)
;
=
createMockDebugModel
(
)
;
=
createTestSession
(
)
;
const
:
=
<
>
workbenchInstantiationService
(
undefined
,
)
;
=
.
createInstance
(
)
;
registerColors
(
)
;
}
)
;
teardown
(
(
)
=>
{
.
dispose
(
)
;
}
)
;
ensureNoDisposablesAreLeakedInTestSuite
(
)
;
test
(
'appendStylizedStringToContainer'
,
(
)
=>
{
const
:
=
.
createElement
(
'span'
)
;
let
:
;
.
strictEqual
(
0
,
.
.
)
;
const
=
{
:
.
,
:
new
DisposableStore
(
)
}
;
appendStylizedStringToContainer
(
,
'content1'
,
[
'class1'
,
'class2'
]
,
,
.
,
undefined
,
undefined
,
undefined
,
undefined
,
0
,
)
;
appendStylizedStringToContainer
(
,
'content2'
,
[
'class2'
,
'class3'
]
,
,
.
,
undefined
,
undefined
,
undefined
,
undefined
,
0
,
)
;
.
strictEqual
(
2
,
.
.
)
;
=
.
!
;
if
(
isHTMLSpanElement
(
)
)
{
.
strictEqual
(
'content1'
,
.
)
;
assert
(
.
.
contains
(
'class1'
)
)
;
assert
(
.
.
contains
(
'class2'
)
)
;
}
else
{
.
fail
(
'Unexpected assertion error'
)
;
}
=
.
!
;
if
(
isHTMLSpanElement
(
)
)
{
.
strictEqual
(
'content2'
,
.
)
;
assert
(
.
.
contains
(
'class2'
)
)
;
assert
(
.
.
contains
(
'class3'
)
)
;
}
else
{
.
fail
(
'Unexpected assertion error'
)
;
}
.
.
dispose
(
)
;
}
)
;
/**
* Apply an ANSI sequence to {@link #getSequenceOutput}.
*
* @paramsequence The ANSI sequence to stylize.
* @returns An {@link HTMLSpanElement} that contains the stylized text.
*/
function
getSequenceOutput
(
:
string
)
:
{
const
=
{
:
.
,
:
new
DisposableStore
(
)
}
;
const
:
=
handleANSIOutput
(
,
,
.
,
[
]
,
)
;
.
strictEqual
(
1
,
.
.
)
;
const
:
=
.
!
;
.
.
dispose
(
)
;
if
(
isHTMLSpanElement
(
)
)
{
return
;
}
else
{
.
fail
(
'Unexpected assertion error'
)
;
}
}
/**
* Assert that a given ANSI sequence maintains added content following the ANSI code, and that
* the provided {@param assertion} passes.
*
* @paramsequence The ANSI sequence to verify. The provided sequence should contain ANSI codes
* only, and should not include actual text content as it is provided by this function.
* @paramassertion The function used to verify the output.
*/
function
assertSingleSequenceElement
(
:
string
,
assertion
:
(
:
)
=>
void
)
:
void
{
const
:
=
getSequenceOutput
(
+
'content'
)
;
.
strictEqual
(
'content'
,
.
)
;
assertion
(
)
;
}
/**
* Assert that a given DOM element has the custom inline CSS style matching
* the color value provided.
* @paramelement The HTML span element to look at.
* @paramcolorType If `foreground`, will check the element's css `color`;
* if `background`, will check the element's css `backgroundColor`.
* if `underline`, will check the elements css `textDecorationColor`.
* @paramcolor RGBA object to compare color to. If `undefined` or not provided,
* will assert that no value is set.
* @parammessage Optional custom message to pass to assertion.
* @paramcolorShouldMatch Optional flag (defaults TO true) which allows caller to indicate that the color SHOULD NOT MATCH
* (for testing changes to theme colors where we need color to have changed but we don't know exact color it should have
* changed to (but we do know the color it should NO LONGER BE))
*/
function
assertInlineColor
(
:
,
:
'background'
|
'foreground'
|
'underline'
,
?
:
RGBA
|
undefined
,
?
:
string
,
:
boolean
=
true
)
:
void
{
if
(
!==
undefined
)
{
const
=
.
.
CSS
.
formatRGB
(
new
Color
(
)
)
;
if
(
===
'background'
)
{
const
=
.
.
;
.
.
=
;
assert
(
(
===
.
.
)
===
,
||
`Incorrect ${colorType} color style found (found color: ${styleBefore}, expected ${cssColor}).`
)
;
}
else
if
(
===
'foreground'
)
{
const
=
.
.
;
.
.
=
;
assert
(
(
===
.
.
)
===
,
||
`Incorrect ${colorType} color style found (found color: ${styleBefore}, expected ${cssColor}).`
)
;
}
else
{
const
=
.
.
;
.
.
=
;
assert
(
(
===
.
.
)
===
,
||
`Incorrect ${colorType} color style found (found color: ${styleBefore}, expected ${cssColor}).`
)
;
}
}
else
{
if
(
===
'background'
)
{
assert
(
!
.
.
,
||
`Defined ${colorType} color style found when it should not have been defined`
)
;
}
else
if
(
===
'foreground'
)
{
assert
(
!
.
.
,
||
`Defined ${colorType} color style found when it should not have been defined`
)
;
}
else
{
assert
(
!
.
.
,
||
`Defined ${colorType} color style found when it should not have been defined`
)
;
}
}
}
test
(
'Expected single sequence operation'
,
(
)
=>
{
// Bold code
assertSingleSequenceElement
(
'\x1b[1m'
,
(
)
=>
{
assert
(
.
.
contains
(
'code-bold'
)
,
'Bold formatting not detected after bold ANSI code.'
)
;
}
)
;
// Italic code
assertSingleSequenceElement
(
'\x1b[3m'
,
(
)
=>
{
assert
(
.
.
contains
(
'code-italic'
)
,
'Italic formatting not detected after italic ANSI code.'
)
;
}
)
;
// Underline code
assertSingleSequenceElement
(
'\x1b[4m'
,
(
)
=>
{
assert
(
.
.
contains
(
'code-underline'
)
,
'Underline formatting not detected after underline ANSI code.'
)
;
}
)
;
for
(
let
=
30
;
<=
37
;
++
)
{
const
:
string
=
'code-foreground-colored'
;
// Foreground colour class
assertSingleSequenceElement
(
'\x1b['
+
+
'm'
,
(
)
=>
{
assert
(
.
.
contains
(
)
,
`Custom foreground class not found on element after foreground ANSI code #${i}.`
)
;
}
)
;
// Cancellation code removes colour class
assertSingleSequenceElement
(
'\x1b['
+
+
';39m'
,
(
)
=>
{
assert
(
.
.
contains
(
)
===
false
,
'Custom foreground class still found after foreground cancellation code.'
)
;
assertInlineColor
(
,
'foreground'
,
undefined
,
'Custom color style still found after foreground cancellation code.'
)
;
}
)
;
}
for
(
let
=
40
;
<=
47
;
++
)
{
const
:
string
=
'code-background-colored'
;
// Foreground colour class
assertSingleSequenceElement
(
'\x1b['
+
+
'm'
,
(
)
=>
{
assert
(
.
.
contains
(
)
,
`Custom background class not found on element after background ANSI code #${i}.`
)
;
}
)
;
// Cancellation code removes colour class
assertSingleSequenceElement
(
'\x1b['
+
+
';49m'
,
(
)
=>
{
assert
(
.
.
contains
(
)
===
false
,
'Custom background class still found after background cancellation code.'
)
;
assertInlineColor
(
,
'foreground'
,
undefined
,
'Custom color style still found after background cancellation code.'
)
;
}
)
;
}
// check all basic colors for underlines (full range is checked elsewhere, here we check cancelation)
for
(
let
=
0
;
<=
255
;
++
)
{
const
:
string
=
'code-underline-colored'
;
// Underline colour class
assertSingleSequenceElement
(
'\x1b[58;5;'
+
+
'm'
,
(
)
=>
{
assert
(
.
.
contains
(
)
,
`Custom underline color class not found on element after underline color ANSI code 58;5;${i}m.`
)
;
}
)
;
// Cancellation underline color code removes colour class
assertSingleSequenceElement
(
'\x1b[58;5;'
+
+
'm\x1b[59m'
,
(
)
=>
{
assert
(
.
.
contains
(
)
===
false
,
'Custom underline color class still found after underline color cancellation code 59m.'
)
;
assertInlineColor
(
,
'underline'
,
undefined
,
'Custom underline color style still found after underline color cancellation code 59m.'
)
;
}
)
;
}
// Different codes do not cancel each other
assertSingleSequenceElement
(
'\x1b[1;3;4;30;41m'
,
(
)
=>
{
.
strictEqual
(
5
,
.
.
,
'Incorrect number of classes found for different ANSI codes.'
)
;
assert
(
.
.
contains
(
'code-bold'
)
)
;
assert
(
.
.
contains
(
'code-italic'
)
,
'Different ANSI codes should not cancel each other.'
)
;
assert
(
.
.
contains
(
'code-underline'
)
,
'Different ANSI codes should not cancel each other.'
)
;
assert
(
.
.
contains
(
'code-foreground-colored'
)
,
'Different ANSI codes should not cancel each other.'
)
;
assert
(
.
.
contains
(
'code-background-colored'
)
,
'Different ANSI codes should not cancel each other.'
)
;
}
)
;
// Different codes do not ACCUMULATE more than one copy of each class
'italic missing Doubles of each Different ANSI codes should not cancel each other or accumulate.'
)
;
assert
(
.
.
contains
(
'code-underline'
)
===
false
,
'underline PRESENT and double underline should have removed it- Doubles of each Different ANSI codes should not cancel each other or accumulate.'
)
;
assert
(
.
.
contains
(
'code-dim'
)
,
'dim missing Doubles of each Different ANSI codes should not cancel each other or accumulate.'
)
;
assert
(
.
.
contains
(
'code-blink'
)
,
'blink missing Doubles of each Different ANSI codes should not cancel each other or accumulate.'
)
;
assert
(
.
.
contains
(
'code-rapid-blink'
)
,
'rapid blink mkssing Doubles of each Different ANSI codes should not cancel each other or accumulate.'
)
;
assert
(
.
.
contains
(
'code-double-underline'
)
,
'double underline missing Doubles of each Different ANSI codes should not cancel each other or accumulate.'
)
;
assert
(
.
.
contains
(
'code-hidden'
)
,
'hidden missing Doubles of each Different ANSI codes should not cancel each other or accumulate.'
)
;
assert
(
.
.
contains
(
'code-strike-through'
)
,
'strike-through missing Doubles of each Different ANSI codes should not cancel each other or accumulate.'
)
;
assert
(
.
.
contains
(
'code-overline'
)
,
'overline missing Doubles of each Different ANSI codes should not cancel each other or accumulate.'
)
;
assert
(
.
.
contains
(
'code-superscript'
)
===
false
,
'superscript PRESENT and subscript should have removed it- Doubles of each Different ANSI codes should not cancel each other or accumulate.'
)
;
assert
(
.
.
contains
(
'code-subscript'
)
,
'subscript missing Doubles of each Different ANSI codes should not cancel each other or accumulate.'
)
;
.
strictEqual
(
10
,
.
.
,
'Incorrect number of classes found for each style code sent twice ANSI codes.'
)
;
}
)
;
// More Different codes do not cancel each other
assertSingleSequenceElement
(
'\x1b[1;2;5;6;21;8;9m'
,
(
)
=>
{
.
strictEqual
(
7
,
.
.
,
'Incorrect number of classes found for different ANSI codes.'
)
;
assert
(
.
.
contains
(
'code-bold'
)
)
;
assert
(
.
.
contains
(
'code-dim'
)
,
'Different ANSI codes should not cancel each other.'
)
;
assert
(
.
.
contains
(
'code-blink'
)
,
'Different ANSI codes should not cancel each other.'
)
;
assert
(
.
.
contains
(
'code-rapid-blink'
)
,
'Different ANSI codes should not cancel each other.'
)
;
assert
(
.
.
contains
(
'code-double-underline'
)
,
'Different ANSI codes should not cancel each other.'
)
;
assert
(
.
.
contains
(
'code-hidden'
)
,
'Different ANSI codes should not cancel each other.'
)
;
assert
(
.
.
contains
(
'code-strike-through'
)
,
'Different ANSI codes should not cancel each other.'
)
;
}
)
;
// New foreground codes don't remove old background codes and vice versa
assertSingleSequenceElement
(
'\x1b[40;31;42;33m'
,
(
)
=>
{
.
strictEqual
(
2
,
.
.
)
;
assert
(
.
.
contains
(
'code-background-colored'
)
,
'New foreground ANSI code should not cancel existing background formatting.'
)
;
assert
(
.
.
contains
(
'code-foreground-colored'
)
,
'New background ANSI code should not cancel existing foreground formatting.'
)
;
}
)
;
// Duplicate codes do not change output
assertSingleSequenceElement
(
'\x1b[1;1;4;1;4;4;1;4m'
,
(
)
=>
{
assert
(
.
.
contains
(
'code-bold'
)
,
'Duplicate formatting codes should have no effect.'
)
;
assert
(
.
.
contains
(
'code-underline'
)
,
'Duplicate formatting codes should have no effect.'
)
;
}
)
;
// Extra terminating semicolon does not change output
assertSingleSequenceElement
(
'\x1b[1;4;m'
,
(
)
=>
{
assert
(
.
.
contains
(
'code-bold'
)
,
'Extra semicolon after ANSI codes should have no effect.'
)
;
assert
(
.
.
contains
(
'code-underline'
)
,
'Extra semicolon after ANSI codes should have no effect.'
)
;
}
)
;
// Cancellation code removes multiple codes
assertSingleSequenceElement
(
'\x1b[1;4;30;41;32;43;34;45;36;47;0m'
,
(
)
=>
{
.
strictEqual
(
0
,
.
.
,
'Cancellation ANSI code should clear ALL formatting.'
)
;
assertInlineColor
(
,
'background'
,
undefined
,
'Cancellation ANSI code should clear ALL formatting.'
)
;
assertInlineColor
(
,
'foreground'
,
undefined
,
'Cancellation ANSI code should clear ALL formatting.'
)
;
}
)
;
}
)
;
test
(
'Expected single 8-bit color sequence operation'
,
(
)
=>
{
// Basic and bright color codes specified with 8-bit color code format
for
(
let
=
0
;
<=
15
;
++
)
{
// As these are controlled by theme, difficult to check actual color value
// Foreground codes should add standard classes
assertSingleSequenceElement
(
'\x1b[38;5;'
+
+
'm'
,
(
)
=>
{
assert
(
.
.
contains
(
'code-foreground-colored'
)
,
`Custom color class not found after foreground 8-bit color code 38;5;${i}`
)
;
}
)
;
// Background codes should add standard classes
assertSingleSequenceElement
(
'\x1b[48;5;'
+
+
'm'
,
(
)
=>
{
assert
(
.
.
contains
(
'code-background-colored'
)
,
`Custom color class not found after background 8-bit color code 48;5;${i}`
)
;
}
)
;
}
// 8-bit advanced colors
for
(
let
=
16
;
<=
255
;
++
)
{
// Foreground codes should add custom class and inline style
assertSingleSequenceElement
(
'\x1b[38;5;'
+
+
'm'
,
(
)
=>
{
assert
(
.
.
contains
(
'code-foreground-colored'
)
,
`Custom color class not found after foreground 8-bit color code 38;5;${i}`
)
;
assertInlineColor
(
,
'foreground'
,
(
calcANSI8bitColor
(
)
as
RGBA
)
,
`Incorrect or no color styling found after foreground 8-bit color code 38;5;${i}`
)
;
}
)
;
// Background codes should add custom class and inline style
assertSingleSequenceElement
(
'\x1b[48;5;'
+
+
'm'
,
(
)
=>
{
assert
(
.
.
contains
(
'code-background-colored'
)
,
`Custom color class not found after background 8-bit color code 48;5;${i}`
)
;
assertInlineColor
(
,
'background'
,
(
calcANSI8bitColor
(
)
as
RGBA
)
,
`Incorrect or no color styling found after background 8-bit color code 48;5;${i}`
)
;
}
)
;
// Color underline codes should add custom class and inline style
assertSingleSequenceElement
(
'\x1b[58;5;'
+
+
'm'
,
(
)
=>
{
assert
(
.
.
contains
(
'code-underline-colored'
)
,
`Custom color class not found after underline 8-bit color code 58;5;${i}`
)
;
assertInlineColor
(
,
'underline'
,
(
calcANSI8bitColor
(
)
as
RGBA
)
,
`Incorrect or no color styling found after underline 8-bit color code 58;5;${i}`
)
;
}
)
;
}
// Bad (nonexistent) color should not render
assertSingleSequenceElement
(
'\x1b[48;5;300m'
,
(
)
=>
{
.
strictEqual
(
0
,
.
.
,
'Bad ANSI color codes should have no effect.'
)
;
}
)
;
// Should ignore any codes after the ones needed to determine color
assertSingleSequenceElement
(
'\x1b[48;5;100;42;77;99;4;24m'
,
(
)
=>
{
assert
(
.
.
contains
(
'code-background-colored'
)
)
;
.
strictEqual
(
1
,
.
.
)
;
assertInlineColor
(
,
'background'
,
(
calcANSI8bitColor
(
100
)
as
RGBA
)
)
;
}
)
;
}
)
;
test
(
'Expected single 24-bit color sequence operation'
,
(
)
=>
{
// 24-bit advanced colors
for
(
let
=
0
;
<=
255
;
+=
64
)
{
for
(
let
=
0
;
<=
255
;
+=
64
)
{
for
(
let
=
0
;
<=
255
;
+=
64
)
{
const
=
new
RGBA
(
,
,
)
;
// Foreground codes should add class and inline style
assertSingleSequenceElement
(
`\x1b[38;2;${r};${g};${b}m`
,
(
)
=>
{
assert
(
.
.
contains
(
'code-foreground-colored'
)
,
'DOM should have "code-foreground-colored" class for advanced ANSI colors.'
)
;
assertInlineColor
(
,
'foreground'
,
)
;
}
)
;
// Background codes should add class and inline style
assertSingleSequenceElement
(
`\x1b[48;2;${r};${g};${b}m`
,
(
)
=>
{
assert
(
.
.
contains
(
'code-background-colored'
)
,
'DOM should have "code-foreground-colored" class for advanced ANSI colors.'
)
;
assertInlineColor
(
,
'background'
,
)
;
}
)
;
// Underline color codes should add class and inline style
assertSingleSequenceElement
(
`\x1b[58;2;${r};${g};${b}m`
,
(
)
=>
{
assert
(
.
.
contains
(
'code-underline-colored'
)
,
'DOM should have "code-underline-colored" class for advanced ANSI colors.'
)
;
assertInlineColor
(
,
'underline'
,
)
;
}
)
;
}
}
}
// Invalid color should not render
assertSingleSequenceElement
(
'\x1b[38;2;4;4m'
,
(
)
=>
{
.
strictEqual
(
0
,
.
.
,
`Invalid color code "38;2;4;4" should not add a class (classes found: ${child.classList}).`
)
;
assert
(
!
.
.
,
`Invalid color code "38;2;4;4" should not add a custom color CSS (found color: ${child.style.color}).`
)
;
}
)
;
// Bad (nonexistent) color should not render
assertSingleSequenceElement
(
'\x1b[48;2;150;300;5m'
,
(
)
=>
{
.
strictEqual
(
0
,
.
.
,
`Nonexistent color code "48;2;150;300;5" should not add a class (classes found: ${child.classList}).`
)
;
}
)
;
// Should ignore any codes after the ones needed to determine color
assertSingleSequenceElement
(
'\x1b[48;2;100;42;77;99;200;75m'
,
(
)
=>
{
assert
(
.
.
contains
(
'code-background-colored'
)
,
`Color code with extra (valid) items "48;2;100;42;77;99;200;75" should still treat initial part as valid code and add class "code-background-custom".`
)
;
.
strictEqual
(
1
,
.
.
,
`Color code with extra items "48;2;100;42;77;99;200;75" should add one and only one class. (classes found: ${child.classList}).`
)
;
assertInlineColor
(
,
'background'
,
new
RGBA
(
100
,
42
,
77
)
,
`Color code "48;2;100;42;77;99;200;75" should style background-color as rgb(100,42,77).`
)
;
}
)
;
}
)
;
/**
* Assert that a given ANSI sequence produces the expected number of {@link HTMLSpanElement} children. For
* each child, run the provided assertion.
*
* @paramsequence The ANSI sequence to verify.
* @paramassertions A set of assertions to run on the resulting children.
*/
function
assertMultipleSequenceElements
(
:
string
,
:
Array
<
(
:
)
=>
void
>
,
?
:
number
)
:
void
{
if
(
===
undefined
)
{
=
.
;
}
const
=
{
:
.
,
:
new
DisposableStore
(
)
}
;
const
:
=
handleANSIOutput
(
,
,
.
,
[
]
,
)
;
.
strictEqual
(
,
.
.
)
;
for
(
let
=
0
;
<
;
++
)
{
const
:
=
.
[
]
;
if
(
isHTMLSpanElement
(
)
)
{
[
]
(
)
;
}
else
{
.
fail
(
'Unexpected assertion error'
)
;
}
}
.
.
dispose
(
)
;
}
test
(
'Expected multiple sequence operation'
,
(
)
=>
{
// Multiple codes affect the same text
assertSingleSequenceElement
(
'\x1b[1m\x1b[3m\x1b[4m\x1b[32m'
,
(
)
=>
{
assert
(
.
.
contains
(
'code-bold'
)
,
'Bold class not found after multiple different ANSI codes.'
)
;
assert
(
.
.
contains
(
'code-italic'
)
,
'Italic class not found after multiple different ANSI codes.'
)
;
assert
(
.
.
contains
(
'code-underline'
)
,
'Underline class not found after multiple different ANSI codes.'
)
;
assert
(
.
.
contains
(
'code-foreground-colored'
)
,
'Foreground color class not found after multiple different ANSI codes.'
'Foreground ANSI color code should add one class.'
)
;
assert
(
.
.
contains
(
'code-foreground-colored'
)
,
'Foreground ANSI color codes should add custom foreground color class.'
)
;
}
,
(
)
=>
{
.
strictEqual
(
1
,
.
.
,
'Multiple foreground ANSI color codes should only add a single class.'
)
;
assert
(
.
.
contains
(
'code-foreground-colored'
)
,
'Foreground ANSI color codes should add custom foreground color class.'
)
;
assertInlineColor
(
,
'foreground'
,
new
RGBA
(
101
,
102
,
103
)
,
'24-bit RGBA ANSI color code (101,102,103) should add matching color inline style.'
)
;
}
,
(
)
=>
{
.
strictEqual
(
1
,
.
.
,
'Multiple foreground ANSI color codes should only add a single class.'
)
;
assert
(
.
.
contains
(
'code-foreground-colored'
)
,
'Foreground ANSI color codes should add custom foreground color class.'
)
;
//color is theme based, so we can't check what it should be but we know it should NOT BE 101,102,103 anymore
assertInlineColor
(
,
'foreground'
,
new
RGBA
(
101
,
102
,
103
)
,
'SHOULD NOT LONGER BE 24-bit RGBA ANSI color code (101,102,103) after simple color change.'
,
false
)
;
}
,
(
)
=>
{
.
strictEqual
(
1
,
.
.
,
'Multiple foreground ANSI color codes should only add a single class.'
)
;
assert
(
.
.
contains
(
'code-foreground-colored'
)
,
'Foreground ANSI color codes should add custom foreground color class.'
)
;
assertInlineColor
(
,
'foreground'
,
new
RGBA
(
104
,
105
,
106
)
,
'24-bit RGBA ANSI color code (104,105,106) should add matching color inline style.'
)
;
}
,
(
)
=>
{
.
strictEqual
(
1
,
.
.
,
'Multiple foreground ANSI color codes should only add a single class.'
)
;
assert
(
.
.
contains
(
'code-foreground-colored'
)
,
'Foreground ANSI color codes should add custom foreground color class.'
)
;
// color should NO LONGER BE 104,105,106
assertInlineColor
(
,
'foreground'
,
new
RGBA
(
104
,
105
,
106
)
,
'SHOULD NOT LONGER BE 24-bit RGBA ANSI color code (104,105,106) after advanced color change.'
,
false
)
;
}
]
,
5
)
;
}
)
;
/**
* Assert that the provided ANSI sequence exactly matches the text content of the resulting
* {@link HTMLSpanElement}.
*
* @paramsequence The ANSI sequence to verify.
*/
function
assertSequencestrictEqualToContent
(
:
string
)
:
void
{
const
:
=
getSequenceOutput
(
)
;
assert
(
.
===
)
;
}
test
(
'Invalid codes treated as regular text'
,
(
)
=>
{
// Individual components of ANSI code start are printed
assertSequencestrictEqualToContent
(
'\x1b'
)
;
assertSequencestrictEqualToContent
(
'['
)
;
// Unsupported sequence prints both characters
assertSequencestrictEqualToContent
(
'\x1b['
)
;
// Random strings are displayed properly
for
(
let
=
0
;
<
50
;
++
)
{
const
:
string
=
generateUuid
(
)
;
assertSequencestrictEqualToContent
(
)
;
}
}
)
;
/**
* Assert that a given ANSI sequence maintains added content following the ANSI code, and that
* the expression itself is thrown away.
*
* @paramsequence The ANSI sequence to verify. The provided sequence should contain ANSI codes
* only, and should not include actual text content as it is provided by this function.
*/
function
assertEmptyOutput
(
:
string
)
{
const
:
=
getSequenceOutput
(
+
'content'
)
;
.
strictEqual
(
'content'
,
.
)
;
.
strictEqual
(
0
,
.
.
)
;
}
test
(
'Empty sequence output'
,
(
)
=>
{
const
:
string
[
]
=
[
// No colour codes
''
,
'\x1b[;m'
,
'\x1b[1;;m'
,
'\x1b[m'
,
'\x1b[99m'
]
;
.
forEach
(
=>
{
assertEmptyOutput
(
)
;
}
)
;
// Check other possible ANSI terminators
const
:
string
[
]
=
'ABCDHIJKfhmpsu'
.
split
(
''
)
;
.
forEach
(
=>
{
assertEmptyOutput
(
'\x1b[content'
+
)
;
}
)
;
}
)
;
test
(
'calcANSI8bitColor'
,
(
)
=>
{
// Invalid values
// Negative (below range), simple range, decimals
for
(
let
=
-
10
;
<=
15
;
+=
0.5
)
{
assert
(
calcANSI8bitColor
(
)
===
undefined
,
'Values less than 16 passed to calcANSI8bitColor should return undefined.'
)
;
}
// In-range range decimals
for
(
let
=
16.5
;
<
254
;
+=
1
)
{
assert
(
calcANSI8bitColor
(
)
===
undefined
,
'Floats passed to calcANSI8bitColor should return undefined.'
)
;
}
// Above range
for
(
let
=
256
;
<
300
;
+=
0.5
)
{
assert
(
calcANSI8bitColor
(
)
===
undefined
,
'Values grather than 255 passed to calcANSI8bitColor should return undefined.'