2021-06-15 03:12:22 +03:00
|
|
|
import { expect } from 'chai'
|
2023-06-05 03:30:48 +03:00
|
|
|
import { describe, it } from 'mocha'
|
|
|
|
|
2023-10-16 19:23:53 +03:00
|
|
|
import { hexDecodeToBuffer, utf8EncodeToBuffer } from '@mtcute/core/utils.js'
|
|
|
|
|
|
|
|
import { isProbablyPlainText } from '../src/utils/file-utils.js'
|
2021-06-15 03:12:22 +03:00
|
|
|
|
|
|
|
describe('isProbablyPlainText', () => {
|
|
|
|
it('should return true for buffers only containing printable ascii', () => {
|
2023-10-16 19:23:53 +03:00
|
|
|
expect(isProbablyPlainText(utf8EncodeToBuffer('hello this is some ascii text'))).to.be.true
|
|
|
|
expect(isProbablyPlainText(utf8EncodeToBuffer('hello this is some ascii text\nwith unix new lines'))).to.be.true
|
|
|
|
expect(isProbablyPlainText(utf8EncodeToBuffer('hello this is some ascii text\r\nwith windows new lines'))).to.be.true
|
|
|
|
expect(isProbablyPlainText(utf8EncodeToBuffer('hello this is some ascii text\n\twith unix new lines and tabs'))).to.be
|
2023-09-24 01:32:22 +03:00
|
|
|
.true
|
2023-10-16 19:23:53 +03:00
|
|
|
expect(isProbablyPlainText(utf8EncodeToBuffer('hello this is some ascii text\r\n\twith windows new lines and tabs')))
|
2023-09-24 01:32:22 +03:00
|
|
|
.to.be.true
|
2021-06-15 03:12:22 +03:00
|
|
|
})
|
|
|
|
|
|
|
|
it('should return false for buffers containing some binary data', () => {
|
2023-10-16 19:23:53 +03:00
|
|
|
expect(isProbablyPlainText(utf8EncodeToBuffer('hello this is cedilla: ç'))).to.be.false
|
|
|
|
expect(isProbablyPlainText(utf8EncodeToBuffer('hello this is some ascii text with emojis 🌸'))).to.be.false
|
2021-06-15 03:12:22 +03:00
|
|
|
|
|
|
|
// random strings of 16 bytes
|
2023-10-16 19:23:53 +03:00
|
|
|
expect(isProbablyPlainText(hexDecodeToBuffer('717f80f08eb9d88c3931712c0e2be32f'))).to.be.false
|
|
|
|
expect(isProbablyPlainText(hexDecodeToBuffer('20e8e218e54254c813b261432b0330d7'))).to.be.false
|
2021-06-15 03:12:22 +03:00
|
|
|
})
|
|
|
|
})
|