![]() Server : Apache/2 System : Linux server-15-235-50-60 5.15.0-164-generic #174-Ubuntu SMP Fri Nov 14 20:25:16 UTC 2025 x86_64 User : gositeme ( 1004) PHP Version : 8.2.29 Disable Function : exec,system,passthru,shell_exec,proc_close,proc_open,dl,popen,show_source,posix_kill,posix_mkfifo,posix_getpwuid,posix_setpgid,posix_setsid,posix_setuid,posix_setgid,posix_seteuid,posix_setegid,posix_uname Directory : /home/gositeme/domains/lavocat.quebec/private_html/node_modules/streamsearch/test/ |
'use strict';
const assert = require('assert');
const StreamSearch = require('../lib/sbmh.js');
[
{
needle: '\r\n',
chunks: [
'foo',
' bar',
'\r',
'\n',
'baz, hello\r',
'\n world.',
'\r\n Node.JS rules!!\r\n\r\n',
],
expect: [
[false, 'foo'],
[false, ' bar'],
[ true, null],
[false, 'baz, hello'],
[ true, null],
[false, ' world.'],
[ true, null],
[ true, ' Node.JS rules!!'],
[ true, ''],
],
},
{
needle: '---foobarbaz',
chunks: [
'---foobarbaz',
'asdf',
'\r\n',
'---foobarba',
'---foobar',
'ba',
'\r\n---foobarbaz--\r\n',
],
expect: [
[ true, null],
[false, 'asdf'],
[false, '\r\n'],
[false, '---foobarba'],
[false, '---foobarba'],
[ true, '\r\n'],
[false, '--\r\n'],
],
},
].forEach((test, i) => {
console.log(`Running test #${i + 1}`);
const { needle, chunks, expect } = test;
const results = [];
const ss = new StreamSearch(Buffer.from(needle),
(isMatch, data, start, end) => {
if (data)
data = data.toString('latin1', start, end);
else
data = null;
results.push([isMatch, data]);
});
for (const chunk of chunks)
ss.push(Buffer.from(chunk));
assert.deepStrictEqual(results, expect);
});