2021-04-29 22:30:36 +03:00
|
|
|
import { expect } from 'chai'
|
2023-06-05 03:30:48 +03:00
|
|
|
import { describe, it } from 'mocha'
|
2022-06-30 16:32:56 +03:00
|
|
|
|
2023-10-16 19:23:53 +03:00
|
|
|
import { hexDecodeToBuffer, hexEncode } from '@mtcute/core/utils.js'
|
|
|
|
|
|
|
|
import { telegramRleDecode, telegramRleEncode } from '../src/utils.js'
|
2021-04-29 22:30:36 +03:00
|
|
|
|
|
|
|
describe('telegramRleEncode', () => {
|
|
|
|
it('should not modify input if there are no \\x00', () => {
|
2023-10-16 19:23:53 +03:00
|
|
|
expect(hexEncode(telegramRleEncode(hexDecodeToBuffer('aaeeff')))).eq('aaeeff')
|
2021-04-29 22:30:36 +03:00
|
|
|
})
|
|
|
|
|
|
|
|
it('should collapse consecutive \\x00', () => {
|
2023-10-16 19:23:53 +03:00
|
|
|
expect(hexEncode(telegramRleEncode(hexDecodeToBuffer('00000000aa')))).eq('0004aa')
|
|
|
|
expect(hexEncode(telegramRleEncode(hexDecodeToBuffer('00000000aa000000aa')))).eq('0004aa0003aa')
|
|
|
|
expect(hexEncode(telegramRleEncode(hexDecodeToBuffer('00000000aa0000')))).eq('0004aa0002')
|
|
|
|
expect(hexEncode(telegramRleEncode(hexDecodeToBuffer('00aa00')))).eq('0001aa0001')
|
2021-04-29 22:30:36 +03:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('telegramRleDecode', () => {
|
|
|
|
it('should not mofify input if there are no \\x00', () => {
|
2023-10-16 19:23:53 +03:00
|
|
|
expect(hexEncode(telegramRleDecode(hexDecodeToBuffer('aaeeff')))).eq('aaeeff')
|
2021-04-29 22:30:36 +03:00
|
|
|
})
|
|
|
|
|
|
|
|
it('should expand two-byte sequences starting with \\x00', () => {
|
2023-10-16 19:23:53 +03:00
|
|
|
expect(hexEncode(telegramRleDecode(hexDecodeToBuffer('0004aa')))).eq('00000000aa')
|
|
|
|
expect(hexEncode(telegramRleDecode(hexDecodeToBuffer('0004aa0000')))).eq('00000000aa')
|
|
|
|
expect(hexEncode(telegramRleDecode(hexDecodeToBuffer('0004aa0003aa')))).eq('00000000aa000000aa')
|
|
|
|
expect(hexEncode(telegramRleDecode(hexDecodeToBuffer('0004aa0002')))).eq('00000000aa0000')
|
|
|
|
expect(hexEncode(telegramRleDecode(hexDecodeToBuffer('0001aa0001')))).eq('00aa00')
|
2021-04-29 22:30:36 +03:00
|
|
|
})
|
|
|
|
})
|