summaryrefslogtreecommitdiff
path: root/node_modules/streamsearch/test
diff options
context:
space:
mode:
authorsowgro <tpoke.ferrari@gmail.com>2023-09-02 19:12:47 -0400
committersowgro <tpoke.ferrari@gmail.com>2023-09-02 19:12:47 -0400
commite4450c8417624b71d779cb4f41692538f9165e10 (patch)
treeb70826542223ecdf8a7a259f61b0a1abb8a217d8 /node_modules/streamsearch/test
downloadsowbot3-e4450c8417624b71d779cb4f41692538f9165e10.tar.gz
sowbot3-e4450c8417624b71d779cb4f41692538f9165e10.tar.bz2
sowbot3-e4450c8417624b71d779cb4f41692538f9165e10.zip
first commit
Diffstat (limited to 'node_modules/streamsearch/test')
-rw-r--r--node_modules/streamsearch/test/test.js70
1 files changed, 70 insertions, 0 deletions
diff --git a/node_modules/streamsearch/test/test.js b/node_modules/streamsearch/test/test.js
new file mode 100644
index 0000000..39a04d7
--- /dev/null
+++ b/node_modules/streamsearch/test/test.js
@@ -0,0 +1,70 @@
+'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);
+});