lik/test/test.stringmap.both.ts

89 lines
3.0 KiB
TypeScript
Raw Normal View History

2017-07-05 12:29:08 +00:00
// import test framework
2018-07-15 14:04:27 +00:00
import { expect, tap } from '@pushrocks/tapbundle';
import * as events from 'events';
2018-08-31 15:24:35 +00:00
import * as smartpromise from '@pushrocks/smartpromise';
2017-07-05 12:29:08 +00:00
// import the module
2018-07-15 14:04:27 +00:00
import * as lik from '../ts/index';
2017-07-05 12:29:08 +00:00
// testData
2018-07-15 14:04:27 +00:00
let testStringmap: lik.Stringmap;
let testString1 = 'testString1';
let testString2 = 'testString2';
let testString3 = 'testString3';
let testString4 = 'testString4';
let testString5 = 'testString5';
let testString6 = 'testString6';
2017-07-05 12:29:08 +00:00
// tests
tap.test('new lik.Objectmap() -> should create an instance of Stringmap', async () => {
2018-07-15 14:04:27 +00:00
testStringmap = new lik.Stringmap();
2022-01-24 04:22:49 +00:00
expect(testStringmap).toBeInstanceOf(lik.Stringmap);
2018-07-15 14:04:27 +00:00
});
2017-07-05 12:29:08 +00:00
2018-07-15 14:04:27 +00:00
tap.test(
'lik.Stringmap.checkString -> should return false for an string not in Stringmap',
async () => {
// tslint:disable-next-line:no-unused-expression
2022-01-24 04:22:49 +00:00
expect(testStringmap.checkString(testString1)).toBeFalse();
2018-07-15 14:04:27 +00:00
}
);
2017-07-05 12:29:08 +00:00
tap.test('lik.Stringmap.addString -> should add an string to Stringmap', async () => {
2018-07-15 14:04:27 +00:00
testStringmap.addString(testString1);
testStringmap.addString(testString2);
testStringmap.addString(testString3);
2017-07-05 12:29:08 +00:00
// tslint:disable-next-line:no-unused-expression
2022-01-24 04:22:49 +00:00
expect(testStringmap.checkString(testString1)).toBeTrue();
2017-07-05 12:29:08 +00:00
// tslint:disable-next-line:no-unused-expression
2022-01-24 04:22:49 +00:00
expect(testStringmap.checkString(testString2)).toBeTrue();
2017-07-05 12:29:08 +00:00
// tslint:disable-next-line:no-unused-expression
2022-01-24 04:22:49 +00:00
expect(testStringmap.checkString(testString3)).toBeTrue();
2017-07-05 12:29:08 +00:00
// tslint:disable-next-line:no-unused-expression
2022-01-24 04:22:49 +00:00
expect(testStringmap.checkMinimatch('*String1')).toBeTrue();
2017-07-05 12:29:08 +00:00
// tslint:disable-next-line:no-unused-expression
2022-01-24 04:22:49 +00:00
expect(testStringmap.checkMinimatch('*String2')).toBeTrue();
2017-07-05 12:29:08 +00:00
// tslint:disable-next-line:no-unused-expression
2022-01-24 04:22:49 +00:00
expect(testStringmap.checkMinimatch('*String4')).toBeFalse();
2018-07-15 14:04:27 +00:00
});
2017-07-05 12:29:08 +00:00
tap.test('lik.Stringmap.addStringArray -> should add an array of strings', async () => {
2018-07-15 14:04:27 +00:00
testStringmap.addStringArray([testString4, testString5, testString6]);
2017-07-05 12:29:08 +00:00
// tslint:disable-next-line:no-unused-expression
2022-01-24 04:22:49 +00:00
expect(testStringmap.checkMinimatch('*String4')).toBeTrue();
2018-07-15 14:04:27 +00:00
});
2017-07-05 12:29:08 +00:00
tap.test('lik.Stringmap.removeString -> should remove a string from Stringmap', async () => {
2018-07-15 14:04:27 +00:00
testStringmap.removeString(testString2);
2017-07-05 12:29:08 +00:00
// tslint:disable-next-line:no-unused-expression
2022-01-24 04:22:49 +00:00
expect(testStringmap.checkString(testString2)).toBeFalse();
2018-07-15 14:04:27 +00:00
});
2017-07-05 12:29:08 +00:00
tap.test('lik.Stringmap.getStringArray() -> should return a copy of stringArray', async () => {
2018-07-15 14:04:27 +00:00
let clonedArray = testStringmap.getStringArray();
2017-07-05 12:29:08 +00:00
// tslint:disable-next-line:no-unused-expression
2022-01-24 04:22:49 +00:00
expect(clonedArray[0] === 'testString1').toBeTrue();
2017-07-05 12:29:08 +00:00
// tslint:disable-next-line:no-unused-expression
2022-01-24 04:22:49 +00:00
expect(clonedArray[0] === testString1).toBeTrue();
2018-07-15 14:04:27 +00:00
});
2017-07-05 12:29:08 +00:00
2018-07-15 14:04:27 +00:00
tap.test(
'lik.Stringmap.checkIsEmpty() -> should register a function to trigger when empty',
async () => {
testStringmap.registerUntilTrue(
() => {
return testStringmap.checkIsEmpty();
},
() => {
console.log('Stringmap now is empty');
}
);
}
);
2017-07-05 12:29:08 +00:00
tap.test('lik.Stringmap.empty() -> should remove wipe and then notify', async () => {
2018-07-15 14:04:27 +00:00
testStringmap.wipe();
});
2017-07-05 12:29:08 +00:00
2018-07-15 14:04:27 +00:00
tap.start();