diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index 48ecd91..b52b0b7 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -4,7 +4,8 @@
-
+
+
@@ -35,32 +36,34 @@
- {
- "keyToString": {
- "ASKED_ADD_EXTERNAL_FILES": "true",
- "ASKED_SHARE_PROJECT_CONFIGURATION_FILES": "true",
- "RunOnceActivity.OpenProjectViewOnStart": "true",
- "RunOnceActivity.ShowReadmeOnStart": "true",
- "git-widget-placeholder": "main",
- "ignore.virus.scanning.warn.message": "true",
- "kotlin-language-version-configured": "true",
- "last_opened_file_path": "C:/Users/HP/IdeaProjects/omni-tools/src/pages/string/split",
- "node.js.detected.package.eslint": "true",
- "node.js.detected.package.tslint": "true",
- "node.js.selected.package.eslint": "(autodetect)",
- "node.js.selected.package.tslint": "(autodetect)",
- "nodejs_package_manager_path": "npm",
- "npm.dev.executor": "Run",
- "npm.prebuild.executor": "Run",
- "prettierjs.PrettierConfiguration.Package": "C:\\Users\\HP\\IdeaProjects\\omni-tools\\node_modules\\prettier",
- "project.structure.last.edited": "Problems",
- "project.structure.proportion": "0.0",
- "project.structure.side.proportion": "0.2",
- "settings.editor.selected.configurable": "settings.typescriptcompiler",
- "ts.external.directory.path": "C:\\Users\\HP\\IdeaProjects\\omni-tools\\node_modules\\typescript\\lib",
- "vue.rearranger.settings.migration": "true"
+
+}]]>
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -107,6 +137,8 @@
+
+
@@ -129,7 +161,7 @@
-
+
@@ -363,7 +395,15 @@
1719152057230
-
+
+
+ 1719153044395
+
+
+
+ 1719153044395
+
+
@@ -384,7 +424,6 @@
-
@@ -409,7 +448,8 @@
-
+
+
diff --git a/src/pages/string/join/service.ts b/src/pages/string/join/service.ts
index dae3f79..e636238 100644
--- a/src/pages/string/join/service.ts
+++ b/src/pages/string/join/service.ts
@@ -4,9 +4,7 @@ export function mergeText(
deleteTrailingSpaces: boolean = true,
joinCharacter: string = ''
): string {
- const lines = text.split('\n');
-
- let processedLines: string[] = lines;
+ let processedLines: string[] = text.split('\n');
if (deleteTrailingSpaces) {
processedLines = processedLines.map((line) => line.trimEnd());
}
diff --git a/src/pages/string/join/string-join.test.ts b/src/pages/string/join/string-join.test.ts
new file mode 100644
index 0000000..6e17f28
--- /dev/null
+++ b/src/pages/string/join/string-join.test.ts
@@ -0,0 +1,64 @@
+import { describe, it, expect } from 'vitest';
+import { mergeText } from './service';
+
+describe('mergeText', () => {
+ it('should merge lines with default settings (delete blank lines, delete trailing spaces, join with empty string)', () => {
+ const input = 'line1 \n \nline2\nline3 \n\nline4';
+ const expected = 'line1line2line3line4';
+ expect(mergeText(input)).toBe(expected);
+ });
+
+ it('should merge lines and preserve blank lines when deleteBlankLines is false', () => {
+ const input = 'line1 \n \nline2\nline3 \n\nline4';
+ const expected = 'line1line2line3line4';
+ expect(mergeText(input, false, true, '')).toBe(expected);
+ });
+
+ it('should merge lines and preserve trailing spaces when deleteTrailingSpaces is false', () => {
+ const input = 'line1 \n \nline2\nline3 \n\nline4';
+ const expected = 'line1 line2line3 line4';
+ expect(mergeText(input, true, false)).toBe(expected);
+ });
+
+ it('should merge lines, preserve blank lines and trailing spaces when both deleteBlankLines and deleteTrailingSpaces are false', () => {
+ const input = 'line1 \n \nline2\nline3 \n\nline4';
+ const expected = 'line1 line2line3 line4';
+ expect(mergeText(input, false, false)).toBe(expected);
+ });
+
+ it('should merge lines with a specified joinCharacter', () => {
+ const input = 'line1 \n \nline2\nline3 \n\nline4';
+ const expected = 'line1 line2 line3 line4';
+ expect(mergeText(input, true, true, ' ')).toBe(expected);
+ });
+
+ it('should handle empty input', () => {
+ const input = '';
+ const expected = '';
+ expect(mergeText(input)).toBe(expected);
+ });
+
+ it('should handle input with only blank lines', () => {
+ const input = ' \n \n\n';
+ const expected = '';
+ expect(mergeText(input)).toBe(expected);
+ });
+
+ it('should handle input with only trailing spaces', () => {
+ const input = 'line1 \nline2 \nline3 ';
+ const expected = 'line1line2line3';
+ expect(mergeText(input)).toBe(expected);
+ });
+
+ it('should handle single line input', () => {
+ const input = 'single line';
+ const expected = 'single line';
+ expect(mergeText(input)).toBe(expected);
+ });
+
+ it('should join lines with new line character when joinCharacter is set to "\\n"', () => {
+ const input = 'line1 \n \nline2\nline3 \n\nline4';
+ const expected = 'line1\nline2\nline3\nline4';
+ expect(mergeText(input, true, true, '\n')).toBe(expected);
+ });
+});