struffer
Version:
Struct + Buffer = Struffer
313 lines (277 loc) • 7.4 kB
text/typescript
import { Test, TestCase, TestFixture, Expect } from 'alsatian';
import Struffer from '../src/index';
import {
FactoryTestsBase,
ObjectAPITestsBase,
MapAPITestsBase,
CommonAPITestCase,
BatchAPITestsBase,
MiscellaneousTestsBase,
} from './common';
('Struffer factory tests')
export class FactoryTests extends FactoryTestsBase {
protected get factory() {
return Struffer;
}
protected get defaultSize() {
return 8;
}
({
byteLength: 3,
bitLength: 24,
types: ['i8', 'i16be'],
})
({
byteLength: 6,
bitLength: 48,
types: ['u8', 'i8', 'u32'],
})
({
byteLength: 4,
bitLength: 32,
types: ['i16', 'unsigned int_8 BE', 'uint8'],
})
('Basic generation')
basicGeneration(opts: any) {
super.basicGeneration(opts);
}
('Foobar3000', undefined, ['byte', 'char', 'short', 'int', 'signed short int'])
('MisterTesty', 24, ['uint8be', 'u16', 'i_be'])
('UnaCosa', 1, ['long int', 'long long uint', 'uint', 'i32', 'u16'])
('TypeTesting', undefined, ['signed long uint', 'short i', 'signed long u'])
('Struffer instantiation')
instantiation(name: string, offset: number | null = null, types: string[]) {
super.instantiation(name, offset, types);
}
('Struffer member size invalidity')
memberSizeInvalidity() {
Expect(() => {
const Test = Struffer('Test', [
['u3', 'foobar'],
]);
}).toThrow();
}
}
('Struffer Object API tests')
export class ObjectAPITests extends ObjectAPITestsBase {
protected get factory() {
return Struffer;
}
protected get defaultSize() {
return 8;
}
([4, 254, 224, 0, 0, 0, 255, 255, 0, 0, 12, 195, 255, 255, 255, 131], [
['u8', 4],
['i8', -2],
['uint_be', 7],
['short int BE', -1],
['uint', 3267],
['int', -125],
])
('Object API member retrieval')
retrieval(bufferData: number[], stuff: [string, number][]) {
super.retrieval(bufferData, stuff);
}
([
['u8', 4],
['i8', -2],
['uint_be', 7],
['short int BE', -1],
['uint', 3267],
['int', -125],
])
('Object API member assignment')
assignment(stuff: [string, number][]) {
super.assignment(stuff);
}
('Object API member presence')
presence(...names: string[]) {
super.presence(...names);
}
('Object API member "deletion"')
deletion(...names: string[]) {
super.deletion(...names);
}
('Object API member enumeration')
enumeration(...names: string[]) {
super.enumeration(...names);
}
('Object API member property description')
propertyDescription(...names: string[]) {
super.propertyDescription(...names);
}
}
('Struffer Map API tests')
export class MapAPITests extends MapAPITestsBase {
protected get factory() {
return Struffer;
}
protected get defaultSize() {
return 8;
}
([4, 254, 224, 0, 0, 0, 255, 255, 0, 0, 12, 195, 255, 255, 255, 131], [
['u8', 4],
['i8', -2],
['uint_be', 7],
['short int BE', -1],
['uint', 3267],
['int', -125],
])
('Map API member retrieval')
retrieval(bufferData: number[], stuff: [string, number][]) {
super.retrieval(bufferData, stuff);
}
([
['u8', 4],
['i8', -2],
['uint_be', 7],
['short int BE', -1],
['uint', 3267],
['int', -125],
])
('Map API member assignment')
assignment(stuff: [string, number][]) {
super.assignment(stuff);
}
('Map API member presence')
presence(...names: string[]) {
super.presence(...names);
}
('Map API member "deletion"')
deletion(...names: string[]) {
super.deletion(...names);
}
('Map API member enumeration')
enumeration(...names: string[]) {
super.enumeration(...names);
}
('Map API member clearance')
clearance(...names: string[]) {
super.clearance(...names);
}
(undefined, 'foobar', 'bar', 'foo', 'something', 'UTF-8-Up-Next...', '👍')
({ me: true }, 'foobar', 'bar', 'foo', 'something', 'UTF-8-Up-Next...', '👍')
('Map API member iteration')
iteration(thisArg: any = undefined, ...names: string[]) {
super.iteration(thisArg, ...names);
}
('Map API member value enumeration')
valueEnumeration(...names: string[]) {
super.valueEnumeration(...names);
}
('Map API member entry enumeration')
entryEnumeration(...names: string[]) {
super.entryEnumeration(...names);
}
('Map API member automatic iteration')
automaticIteration(...names: string[]) {
super.automaticIteration(...names);
}
}
('Struffer Batch API tests')
export class BatchAPITests extends BatchAPITestsBase {
protected get factory() {
return Struffer;
}
protected get defaultSize() {
return 8;
}
([4, 254, 224, 0, 0, 0, 255, 255, 0, 0, 12, 195, 255, 255, 255, 131], [
['u8', 4],
['i8', -2],
['uint_be', 7],
['short int BE', -1],
['uint', 3267],
['int', -125],
])
('Batch API member retrieval')
retrieval(bufferData: number[], stuff: [string, number][]) {
super.retrieval(bufferData, stuff);
}
([
['u8', 4],
['i8', -2],
['uint_be', 7],
['short int BE', -1],
['uint', 3267],
['int', -125],
])
('Batch API member assignment')
assignment(stuff: [string, number][]) {
super.assignment(stuff);
}
('Batch API member presence')
presence(...names: string[]) {
super.presence(...names);
}
('Batch API member deletion')
deletion(...names: string[]) {
super.deletion(...names);
}
}
export class MiscellaneousTests extends MiscellaneousTestsBase {
protected get factory() {
return Struffer;
}
protected get defaultSize() {
return 8;
}
('Member bit enumeration')
bitEnumeration(...names: string[]) {
super.bitEnumeration(...names);
}
('Member bit entry enumeration')
bitEntryEnumeration(...names: string[]) {
super.bitEntryEnumeration(...names);
}
('Member bit retrieval')
getBits() {
super.getBits();
}
('Member bit assignment')
setBits() {
super.setBits();
}
('FooStruff', [
['u16', 'foo', 352],
['i8', 'bar', -2],
['unsigned byte BE', 'something', 255],
])
('Accurate toString representation')
toString(name: string, members: [string, string, number][]) {
super.toString(name, members);
}
('FooStruff', [
['u16', 'foo', 352],
['i8', 'bar', -2],
['unsigned byte BE', 'something', 255],
])
('Accurate coercion')
coercion(name: string, members: [string, string, number][]) {
super.coercion(name, members);
}
('FooStruff', [
['u16', 'foo', 352],
['i8', 'bar', -2],
['unsigned byte BE', 'something', 255],
])
('Accurate util.inspect representation')
inspection(name: string, members: [string, string, number][]) {
super.inspection(name, members);
}
}