interfaces, add test for clone

This commit is contained in:
Jörg Breitbart
2019-06-17 21:17:56 +02:00
parent 24c39f664d
commit cec1aa3f33
3 changed files with 39 additions and 30 deletions
+4
View File
@@ -113,6 +113,10 @@ describe('Params', () => {
data = [38, [2, 50, 100, 150], 5, [], 6];
assert.deepEqual(Params.fromArray(data).toArray(), [38, [2, 50, 100, 150], 5, 6]);
});
it('clone', () => {
const params = Params.fromArray([38, [2, 50, 100, 150], 5, [], 6, 1, [2, 3], 12345, [-1]]);
assert.deepEqual(params.clone(), params);
});
it('hasSubParams / getSubParams', () => {
const params = Params.fromArray([38, [2, 50, 100, 150], 5, [], 6]);
assert.equal(params.hasSubParams(0), true);
+1 -30
View File
@@ -2,36 +2,7 @@
* Copyright (c) 2019 The xterm.js authors. All rights reserved.
* @license MIT
*/
// TODO: move to Types
interface IParamsConstructor {
new(maxLength: number, maxSubParamsLength: number): IParams;
fromArray(values: (number | number[])[]): IParams;
}
interface IParams {
/** from ctor */
maxLength: number;
maxSubParamsLength: number;
/** param values and its length */
params: Int16Array;
length: number;
/** sub params and its length */
subParams: Int16Array;
subParamsLength: number;
/** methods */
clone(): IParams;
toArray(): (number | number[])[];
reset(): void;
addParam(value: number): void;
addSubParam(value: number): void;
hasSubParams(idx: number): boolean;
getSubParams(idx: number): Int16Array | null;
getSubParamsAll(): {[idx: number]: Int16Array};
}
import { IParams } from 'common/parser/Types';
/**
* Params storage class.
+34
View File
@@ -6,6 +6,40 @@
import { IDisposable } from 'common/Types';
import { ParserState } from 'common/parser/Constants';
/**
* Params types.
*/
export interface IParamsConstructor {
new(maxLength: number, maxSubParamsLength: number): IParams;
/** create params object from array like [1, [2, 3]] */
fromArray(values: (number | number[])[]): IParams;
}
export interface IParams {
/** from ctor */
maxLength: number;
maxSubParamsLength: number;
/** param values and its length */
params: Int16Array;
length: number;
/** sub params and its length */
subParams: Int16Array;
subParamsLength: number;
/** methods */
clone(): IParams;
toArray(): (number | number[])[];
reset(): void;
addParam(value: number): void;
addSubParam(value: number): void;
hasSubParams(idx: number): boolean;
getSubParams(idx: number): Int16Array | null;
getSubParamsAll(): {[idx: number]: Int16Array};
}
/**
* Internal state of EscapeSequenceParser.
* Used as argument of the error handler to allow