Path: blob/main/extensions/copilot/src/platform/endpoint/test/node/stream.splitChunk.spec.ts
13405 views
/*---------------------------------------------------------------------------------------------1* Copyright (c) Microsoft Corporation. All rights reserved.2* Licensed under the MIT License. See License.txt in the project root for license information.3*--------------------------------------------------------------------------------------------*/45import { assert, suite, test } from 'vitest';6import { splitChunk } from '../../../networking/node/stream';78suite('splitChunk', () => {9test('splits correctly with one newline in between', function () {10const [lines, extra] = splitChunk('foo\nbar');11assert.deepStrictEqual(lines, ['foo']);12assert.strictEqual(extra, 'bar');13});14test('splits correctly with one newline in between and trailing', function () {15const [lines, extra] = splitChunk('foo\nbar\n');16assert.deepStrictEqual(lines, ['foo', 'bar']);17assert.strictEqual(extra, '');18});19test('splits correctly with two newlines in between', function () {20const [lines, extra] = splitChunk('foo\n\nbar');21assert.deepStrictEqual(lines, ['foo']);22assert.strictEqual(extra, 'bar');23});24test('splits correctly with two newlines in between and trailing', function () {25const [lines, extra] = splitChunk('foo\n\nbar\n\n');26assert.deepStrictEqual(lines, ['foo', 'bar']);27assert.strictEqual(extra, '');28});29test('splits correctly with three newlines in between', function () {30const [lines, extra] = splitChunk('foo\n\n\nbar');31assert.deepStrictEqual(lines, ['foo']);32assert.strictEqual(extra, 'bar');33});34test('splits correctly with three newlines in between and trailing', function () {35const [lines, extra] = splitChunk('foo\n\n\nbar\n\n\n');36assert.deepStrictEqual(lines, ['foo', 'bar']);37assert.strictEqual(extra, '');38});39});404142