mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-03-29 15:30:40 -07:00
refactor(core): Extract thought parsing logic into a dedicated utility (#9503)
This commit is contained in:
80
packages/core/src/utils/thoughtUtils.test.ts
Normal file
80
packages/core/src/utils/thoughtUtils.test.ts
Normal file
@@ -0,0 +1,80 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2025 Google LLC
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
import { describe, it, expect } from 'vitest';
|
||||
import { parseThought } from './thoughtUtils.js';
|
||||
|
||||
describe('parseThought', () => {
|
||||
it.each([
|
||||
{
|
||||
name: 'a standard thought with subject and description',
|
||||
rawText: '**Subject:** This is the description.',
|
||||
expected: {
|
||||
subject: 'Subject:',
|
||||
description: 'This is the description.',
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'leading and trailing whitespace in the raw string',
|
||||
rawText: ' **Subject** description with spaces ',
|
||||
expected: { subject: 'Subject', description: 'description with spaces' },
|
||||
},
|
||||
{
|
||||
name: 'whitespace surrounding the subject content',
|
||||
rawText: '** Subject **',
|
||||
expected: { subject: 'Subject', description: '' },
|
||||
},
|
||||
{
|
||||
name: 'a thought with only a subject',
|
||||
rawText: '**Only Subject**',
|
||||
expected: { subject: 'Only Subject', description: '' },
|
||||
},
|
||||
{
|
||||
name: 'a thought with only a description (no subject)',
|
||||
rawText: 'This is just a description.',
|
||||
expected: { subject: '', description: 'This is just a description.' },
|
||||
},
|
||||
{
|
||||
name: 'an empty string input',
|
||||
rawText: '',
|
||||
expected: { subject: '', description: '' },
|
||||
},
|
||||
{
|
||||
name: 'newlines within the subject and description',
|
||||
rawText:
|
||||
'**Multi-line\nSubject**\nHere is a description\nspread across lines.',
|
||||
expected: {
|
||||
subject: 'Multi-line\nSubject',
|
||||
description: 'Here is a description\nspread across lines.',
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'only the first subject if multiple are present',
|
||||
rawText: '**First** some text **Second**',
|
||||
expected: { subject: 'First', description: 'some text **Second**' },
|
||||
},
|
||||
{
|
||||
name: 'text before and after the subject',
|
||||
rawText: 'Prefix text **Subject** Suffix text.',
|
||||
expected: {
|
||||
subject: 'Subject',
|
||||
description: 'Prefix text Suffix text.',
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'an unclosed subject tag',
|
||||
rawText: 'Text with **an unclosed subject',
|
||||
expected: { subject: '', description: 'Text with **an unclosed subject' },
|
||||
},
|
||||
{
|
||||
name: 'an empty subject tag',
|
||||
rawText: 'A thought with **** in the middle.',
|
||||
expected: { subject: '', description: 'A thought with in the middle.' },
|
||||
},
|
||||
])('should correctly parse $name', ({ rawText, expected }) => {
|
||||
expect(parseThought(rawText)).toEqual(expected);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user