diff options
author | Evgenii Kliuchnikov <eustas@google.com> | 2023-04-26 18:32:46 +0000 |
---|---|---|
committer | Evgenii Kliuchnikov <eustas.ru@gmail.com> | 2023-07-04 07:55:06 +0000 |
commit | 11abde4c96a72a41fbbf48181375527accd4e212 (patch) | |
tree | f714f3329494068b88db77b949aa9af1ece48f5e /js/decode_test.ts | |
parent | efe140adae6e841e80be8796323e73c66d83428b (diff) | |
download | brotli-11abde4c96a72a41fbbf48181375527accd4e212.zip brotli-11abde4c96a72a41fbbf48181375527accd4e212.tar.gz brotli-11abde4c96a72a41fbbf48181375527accd4e212.tar.bz2 |
Add tests for TS brotli decoder
PiperOrigin-RevId: 527326003
Diffstat (limited to 'js/decode_test.ts')
-rw-r--r-- | js/decode_test.ts | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/js/decode_test.ts b/js/decode_test.ts new file mode 100644 index 0000000..aea7369 --- /dev/null +++ b/js/decode_test.ts @@ -0,0 +1,38 @@ +/* Copyright 2023 Google Inc. All Rights Reserved. + + Distributed under MIT license. + See file LICENSE for detail or copy at https://opensource.org/licenses/MIT +*/ + +import 'jasmine'; + +import {brotliDecode} from './decode'; + +function bytesToString(bytes: Int8Array): string { + const chars: number[] = new Uint16Array(bytes) as unknown as number[]; + return String.fromCharCode.apply(null, chars); +} + +function stringToBytes(str: string): Int8Array { + const out = new Int8Array(str.length); + for (let i = 0; i < str.length; ++i) out[i] = str.charCodeAt(i); + return out; +} + +describe('DecodeTest', () => { + it('testMetadata', () => { + expect('').toEqual( + bytesToString(brotliDecode(Int8Array.from([1, 11, 0, 42, 3])))); + }); + + it('testCompoundDictionary', () => { + const txt = 'kot lomom kolol slona\n'; + const dictionary = stringToBytes(txt); + const compressed = + [0xa1, 0xa8, 0x00, 0xc0, 0x2f, 0x01, 0x10, 0xc4, 0x44, 0x09, 0x00]; + expect(txt.length).toEqual(compressed.length * 2); + const options = {'customDictionary': dictionary}; + expect(txt).toEqual( + bytesToString(brotliDecode(Int8Array.from(compressed), options))); + }); +}); |