2024-09-05 03:34:13 +03:00
|
|
|
import { hex } from '@fuman/utils'
|
2024-12-03 09:55:37 +03:00
|
|
|
import { describe, expect, it } from 'vitest'
|
2023-10-16 19:23:53 +03:00
|
|
|
|
2023-11-09 00:20:43 +03:00
|
|
|
import { telegramRleDecode, telegramRleEncode } from './utils.js'
|
2021-04-29 22:30:36 +03:00
|
|
|
|
|
|
|
describe('telegramRleEncode', () => {
|
|
|
|
it('should not modify input if there are no \\x00', () => {
|
2024-09-05 03:34:13 +03:00
|
|
|
expect(hex.encode(telegramRleEncode(hex.decode('aaeeff')))).eq('aaeeff')
|
2021-04-29 22:30:36 +03:00
|
|
|
})
|
|
|
|
|
|
|
|
it('should collapse consecutive \\x00', () => {
|
2024-09-05 03:34:13 +03:00
|
|
|
expect(hex.encode(telegramRleEncode(hex.decode('00000000aa')))).eq('0004aa')
|
|
|
|
expect(hex.encode(telegramRleEncode(hex.decode('00000000aa000000aa')))).eq('0004aa0003aa')
|
|
|
|
expect(hex.encode(telegramRleEncode(hex.decode('00000000aa0000')))).eq('0004aa0002')
|
|
|
|
expect(hex.encode(telegramRleEncode(hex.decode('00aa00')))).eq('0001aa0001')
|
2021-04-29 22:30:36 +03:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('telegramRleDecode', () => {
|
|
|
|
it('should not mofify input if there are no \\x00', () => {
|
2024-09-05 03:34:13 +03:00
|
|
|
expect(hex.encode(telegramRleDecode(hex.decode('aaeeff')))).eq('aaeeff')
|
2021-04-29 22:30:36 +03:00
|
|
|
})
|
|
|
|
|
|
|
|
it('should expand two-byte sequences starting with \\x00', () => {
|
2024-09-05 03:34:13 +03:00
|
|
|
expect(hex.encode(telegramRleDecode(hex.decode('0004aa')))).eq('00000000aa')
|
|
|
|
expect(hex.encode(telegramRleDecode(hex.decode('0004aa0000')))).eq('00000000aa')
|
|
|
|
expect(hex.encode(telegramRleDecode(hex.decode('0004aa0003aa')))).eq('00000000aa000000aa')
|
|
|
|
expect(hex.encode(telegramRleDecode(hex.decode('0004aa0002')))).eq('00000000aa0000')
|
|
|
|
expect(hex.encode(telegramRleDecode(hex.decode('0001aa0001')))).eq('00aa00')
|
2021-04-29 22:30:36 +03:00
|
|
|
})
|
|
|
|
})
|