From 3f3561a02bfc2e1f9482f9fcb9a5d25731cb6ad5 Mon Sep 17 00:00:00 2001 From: BlakeNeko Date: Thu, 18 Dec 2025 13:14:27 +0800 Subject: [PATCH] test: Add tests for trimSurroundingSpaces functionality in formatPromptText --- tests/js/auto-formatter.test.js | 57 +++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/tests/js/auto-formatter.test.js b/tests/js/auto-formatter.test.js index 02cda10..5e9b71c 100644 --- a/tests/js/auto-formatter.test.js +++ b/tests/js/auto-formatter.test.js @@ -47,15 +47,18 @@ describe('AutoFormatter Functions', () => { describe('formatPromptText', () => { // Store original setting value to restore after tests const originalUseTrailingComma = settingValues.useTrailingComma; + const originalTrimSurroundingSpaces = settingValues.trimSurroundingSpaces; afterEach(() => { // Restore original setting after each test settingValues.useTrailingComma = originalUseTrailingComma; + settingValues.trimSurroundingSpaces = originalTrimSurroundingSpaces; }); describe('with useTrailingComma enabled', () => { beforeEach(() => { settingValues.useTrailingComma = true; + settingValues.trimSurroundingSpaces = false; }); test('should format text by adding comma and space after tags', () => { @@ -101,6 +104,7 @@ describe('AutoFormatter Functions', () => { describe('with useTrailingComma disabled', () => { beforeEach(() => { settingValues.useTrailingComma = false; + settingValues.trimSurroundingSpaces = false; }); test('should format text by adding comma and space after tags without trailing comma', () => { @@ -143,6 +147,59 @@ describe('AutoFormatter Functions', () => { }); }); + describe('with trimSurroundingSpaces enabled', () => { + beforeEach(() => { + settingValues.trimSurroundingSpaces = true; + settingValues.useTrailingComma = false; + }); + + test('should remove trailing newlines and spaces', () => { + const input = 'tag1, tag2\n\n '; + const expected = 'tag1, tag2'; + expect(formatPromptText(input)).toBe(expected); + }); + + test('should remove leading newlines and spaces', () => { + const input = ' \n\ntag1, tag2'; + const expected = 'tag1, tag2'; + expect(formatPromptText(input)).toBe(expected); + }); + + test('should remove both leading and trailing whitespaces but keep middle empty lines', () => { + const input = ' \n\ntag1\n\ntag2\n\n '; + const expected = 'tag1\n\ntag2'; + expect(formatPromptText(input)).toBe(expected); + }); + + test('should return empty string if input is only whitespace', () => { + const input = ' \n '; + expect(formatPromptText(input)).toBe(''); + }); + }); + + describe('with trimSurroundingSpaces disabled', () => { + beforeEach(() => { + settingValues.trimSurroundingSpaces = false; + settingValues.useTrailingComma = false; + }); + + test('should preserve trailing newlines', () => { + const input = 'tag1, tag2\n\n'; + const expected = 'tag1, tag2\n\n'; + expect(formatPromptText(input)).toBe(expected); + }); + + test('should preserve leading spaces (as first line content)', () => { + const input = ' \ntag1'; + const expected = '\ntag1'; + expect(formatPromptText(input)).toBe(expected); + }); + + test('should handle input with only spaces', () => { + expect(formatPromptText(' ')).toBe(' '); + }); + }); + test('should handle empty input', () => { expect(formatPromptText('')).toBe(''); expect(formatPromptText(null)).toBe(null);