1
0
Fork 0
mirror of https://github.com/demostf/demo.js synced 2026-06-04 00:54:14 +02:00

encode for setConVar

This commit is contained in:
Robin Appelman 2017-08-12 15:36:23 +02:00
commit 3d0aee619e
5 changed files with 40 additions and 6 deletions

View file

@ -4,7 +4,7 @@ import {Packet} from '../../../../Data/Packet';
import {Encoder, Parser} from '../../../../Parser/Packet/Parser';
export function getStream(data: string) {
const buffer = new Buffer(data);
const buffer = new Buffer(data + '\0remaining dummy data');
return new BitStream(buffer);
}

View file

@ -24,7 +24,7 @@ suite('Parser generator', () => {
});
test('Null terminated string', () => {
assertGeneratedParser('foo{s}', getStream('dummy'), {foo: 'dummy'}, 5 * 8);
assertGeneratedParser('foo{s}', getStream('dummy\0'), {foo: 'dummy'}, 6 * 8);
});
test('Boolean', () => {

View file

@ -0,0 +1,25 @@
import {BitStream} from 'bit-buffer';
import {assertEncoder, assertParser, getStream} from './PacketTest';
import {EncodeSetConVar, ParseSetConVar} from '../../../../Parser/Packet/SetConVar';
suite('SetConVar', () => {
test('Parse setConVar', () => {
assertParser(ParseSetConVar, getStream(String.fromCharCode(2) + 'foo\0bar\0second\0value\0'), {
packetType: 'setConVar',
vars: {
foo: 'bar',
second: 'value'
}
}, 8 + ('foo\0bar\0second\0value\0'.length * 8));
});
test('Encode setConVar', () => {
assertEncoder(ParseSetConVar, EncodeSetConVar, {
packetType: 'setConVar',
vars: {
foo: 'bar',
second: 'value'
}
}, 8 + ('foo\0bar\0second\0value\0'.length * 8));
});
});