mirror of
https://github.com/iib0011/omni-tools.git
synced 2025-09-26 01:19:33 +02:00
test: join service
This commit is contained in:
102
.idea/workspace.xml
generated
102
.idea/workspace.xml
generated
@@ -4,7 +4,8 @@
|
|||||||
<option name="autoReloadType" value="SELECTIVE" />
|
<option name="autoReloadType" value="SELECTIVE" />
|
||||||
</component>
|
</component>
|
||||||
<component name="ChangeListManager">
|
<component name="ChangeListManager">
|
||||||
<list default="true" id="b30e2810-c4c1-4aad-b134-794e52cc1c7d" name="Changes" comment="refactor: tool options components">
|
<list default="true" id="b30e2810-c4c1-4aad-b134-794e52cc1c7d" name="Changes" comment="fix: join text service">
|
||||||
|
<change afterPath="$PROJECT_DIR$/src/pages/string/join/string-join.test.ts" afterDir="false" />
|
||||||
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
||||||
<change beforePath="$PROJECT_DIR$/src/pages/string/join/service.ts" beforeDir="false" afterPath="$PROJECT_DIR$/src/pages/string/join/service.ts" afterDir="false" />
|
<change beforePath="$PROJECT_DIR$/src/pages/string/join/service.ts" beforeDir="false" afterPath="$PROJECT_DIR$/src/pages/string/join/service.ts" afterDir="false" />
|
||||||
</list>
|
</list>
|
||||||
@@ -35,32 +36,34 @@
|
|||||||
<option name="hideEmptyMiddlePackages" value="true" />
|
<option name="hideEmptyMiddlePackages" value="true" />
|
||||||
<option name="showLibraryContents" value="true" />
|
<option name="showLibraryContents" value="true" />
|
||||||
</component>
|
</component>
|
||||||
<component name="PropertiesComponent">{
|
<component name="PropertiesComponent"><![CDATA[{
|
||||||
"keyToString": {
|
"keyToString": {
|
||||||
"ASKED_ADD_EXTERNAL_FILES": "true",
|
"ASKED_ADD_EXTERNAL_FILES": "true",
|
||||||
"ASKED_SHARE_PROJECT_CONFIGURATION_FILES": "true",
|
"ASKED_SHARE_PROJECT_CONFIGURATION_FILES": "true",
|
||||||
"RunOnceActivity.OpenProjectViewOnStart": "true",
|
"RunOnceActivity.OpenProjectViewOnStart": "true",
|
||||||
"RunOnceActivity.ShowReadmeOnStart": "true",
|
"RunOnceActivity.ShowReadmeOnStart": "true",
|
||||||
"git-widget-placeholder": "main",
|
"Vitest.mergeText.executor": "Run",
|
||||||
"ignore.virus.scanning.warn.message": "true",
|
"Vitest.mergeText.should merge lines and preserve blank lines when deleteBlankLines is false.executor": "Run",
|
||||||
"kotlin-language-version-configured": "true",
|
"git-widget-placeholder": "main",
|
||||||
"last_opened_file_path": "C:/Users/HP/IdeaProjects/omni-tools/src/pages/string/split",
|
"ignore.virus.scanning.warn.message": "true",
|
||||||
"node.js.detected.package.eslint": "true",
|
"kotlin-language-version-configured": "true",
|
||||||
"node.js.detected.package.tslint": "true",
|
"last_opened_file_path": "C:/Users/HP/IdeaProjects/omni-tools/src/pages/string/split",
|
||||||
"node.js.selected.package.eslint": "(autodetect)",
|
"node.js.detected.package.eslint": "true",
|
||||||
"node.js.selected.package.tslint": "(autodetect)",
|
"node.js.detected.package.tslint": "true",
|
||||||
"nodejs_package_manager_path": "npm",
|
"node.js.selected.package.eslint": "(autodetect)",
|
||||||
"npm.dev.executor": "Run",
|
"node.js.selected.package.tslint": "(autodetect)",
|
||||||
"npm.prebuild.executor": "Run",
|
"nodejs_package_manager_path": "npm",
|
||||||
"prettierjs.PrettierConfiguration.Package": "C:\\Users\\HP\\IdeaProjects\\omni-tools\\node_modules\\prettier",
|
"npm.dev.executor": "Run",
|
||||||
"project.structure.last.edited": "Problems",
|
"npm.prebuild.executor": "Run",
|
||||||
"project.structure.proportion": "0.0",
|
"prettierjs.PrettierConfiguration.Package": "C:\\Users\\HP\\IdeaProjects\\omni-tools\\node_modules\\prettier",
|
||||||
"project.structure.side.proportion": "0.2",
|
"project.structure.last.edited": "Problems",
|
||||||
"settings.editor.selected.configurable": "settings.typescriptcompiler",
|
"project.structure.proportion": "0.0",
|
||||||
"ts.external.directory.path": "C:\\Users\\HP\\IdeaProjects\\omni-tools\\node_modules\\typescript\\lib",
|
"project.structure.side.proportion": "0.2",
|
||||||
"vue.rearranger.settings.migration": "true"
|
"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"
|
||||||
}
|
}
|
||||||
}</component>
|
}]]></component>
|
||||||
<component name="ReactDesignerToolWindowState">
|
<component name="ReactDesignerToolWindowState">
|
||||||
<option name="myId2Visible">
|
<option name="myId2Visible">
|
||||||
<map>
|
<map>
|
||||||
@@ -84,7 +87,34 @@
|
|||||||
<recent name="C:\Users\HP\IdeaProjects\omni-tools\src\tools" />
|
<recent name="C:\Users\HP\IdeaProjects\omni-tools\src\tools" />
|
||||||
</key>
|
</key>
|
||||||
</component>
|
</component>
|
||||||
<component name="RunManager" selected="npm.dev">
|
<component name="RunManager" selected="Vitest.mergeText">
|
||||||
|
<configuration name="mergeText" type="JavaScriptTestRunnerVitest" temporary="true" nameIsGenerated="true">
|
||||||
|
<node-interpreter value="project" />
|
||||||
|
<vitest-package value="$PROJECT_DIR$/node_modules/vitest" />
|
||||||
|
<working-dir value="$PROJECT_DIR$" />
|
||||||
|
<vitest-options value="--run" />
|
||||||
|
<envs />
|
||||||
|
<scope-kind value="SUITE" />
|
||||||
|
<test-file value="$PROJECT_DIR$/src/pages/string/join/string-join.test.ts" />
|
||||||
|
<test-names>
|
||||||
|
<test-name value="mergeText" />
|
||||||
|
</test-names>
|
||||||
|
<method v="2" />
|
||||||
|
</configuration>
|
||||||
|
<configuration name="mergeText.should merge lines and preserve blank lines when deleteBlankLines is false" type="JavaScriptTestRunnerVitest" temporary="true" nameIsGenerated="true">
|
||||||
|
<node-interpreter value="project" />
|
||||||
|
<vitest-package value="$PROJECT_DIR$/node_modules/vitest" />
|
||||||
|
<working-dir value="$PROJECT_DIR$" />
|
||||||
|
<vitest-options value="--run" />
|
||||||
|
<envs />
|
||||||
|
<scope-kind value="TEST" />
|
||||||
|
<test-file value="$PROJECT_DIR$/src/pages/string/join/string-join.test.ts" />
|
||||||
|
<test-names>
|
||||||
|
<test-name value="mergeText" />
|
||||||
|
<test-name value="should merge lines and preserve blank lines when deleteBlankLines is false" />
|
||||||
|
</test-names>
|
||||||
|
<method v="2" />
|
||||||
|
</configuration>
|
||||||
<configuration name="dev" type="js.build_tools.npm" temporary="true" nameIsGenerated="true">
|
<configuration name="dev" type="js.build_tools.npm" temporary="true" nameIsGenerated="true">
|
||||||
<package-json value="$PROJECT_DIR$/package.json" />
|
<package-json value="$PROJECT_DIR$/package.json" />
|
||||||
<command value="run" />
|
<command value="run" />
|
||||||
@@ -107,6 +137,8 @@
|
|||||||
</configuration>
|
</configuration>
|
||||||
<recent_temporary>
|
<recent_temporary>
|
||||||
<list>
|
<list>
|
||||||
|
<item itemvalue="Vitest.mergeText" />
|
||||||
|
<item itemvalue="Vitest.mergeText.should merge lines and preserve blank lines when deleteBlankLines is false" />
|
||||||
<item itemvalue="npm.dev" />
|
<item itemvalue="npm.dev" />
|
||||||
<item itemvalue="npm.prebuild" />
|
<item itemvalue="npm.prebuild" />
|
||||||
</list>
|
</list>
|
||||||
@@ -129,7 +161,7 @@
|
|||||||
<workItem from="1719006951159" duration="2377000" />
|
<workItem from="1719006951159" duration="2377000" />
|
||||||
<workItem from="1719021128819" duration="3239000" />
|
<workItem from="1719021128819" duration="3239000" />
|
||||||
<workItem from="1719083989394" duration="7971000" />
|
<workItem from="1719083989394" duration="7971000" />
|
||||||
<workItem from="1719092003308" duration="12297000" />
|
<workItem from="1719092003308" duration="13183000" />
|
||||||
</task>
|
</task>
|
||||||
<task id="LOCAL-00001" summary="feat: use vite and ts">
|
<task id="LOCAL-00001" summary="feat: use vite and ts">
|
||||||
<option name="closed" value="true" />
|
<option name="closed" value="true" />
|
||||||
@@ -363,7 +395,15 @@
|
|||||||
<option name="project" value="LOCAL" />
|
<option name="project" value="LOCAL" />
|
||||||
<updated>1719152057230</updated>
|
<updated>1719152057230</updated>
|
||||||
</task>
|
</task>
|
||||||
<option name="localTasksCounter" value="30" />
|
<task id="LOCAL-00030" summary="fix: join text service">
|
||||||
|
<option name="closed" value="true" />
|
||||||
|
<created>1719153044395</created>
|
||||||
|
<option name="number" value="00030" />
|
||||||
|
<option name="presentableId" value="LOCAL-00030" />
|
||||||
|
<option name="project" value="LOCAL" />
|
||||||
|
<updated>1719153044395</updated>
|
||||||
|
</task>
|
||||||
|
<option name="localTasksCounter" value="31" />
|
||||||
<servers />
|
<servers />
|
||||||
</component>
|
</component>
|
||||||
<component name="TypeScriptGeneratedFilesManager">
|
<component name="TypeScriptGeneratedFilesManager">
|
||||||
@@ -384,7 +424,6 @@
|
|||||||
<option name="CHECK_CODE_SMELLS_BEFORE_PROJECT_COMMIT" value="false" />
|
<option name="CHECK_CODE_SMELLS_BEFORE_PROJECT_COMMIT" value="false" />
|
||||||
<option name="CHECK_NEW_TODO" value="false" />
|
<option name="CHECK_NEW_TODO" value="false" />
|
||||||
<option name="ADD_EXTERNAL_FILES_SILENTLY" value="true" />
|
<option name="ADD_EXTERNAL_FILES_SILENTLY" value="true" />
|
||||||
<MESSAGE value="feat: use vite and ts" />
|
|
||||||
<MESSAGE value="feat: initial commit" />
|
<MESSAGE value="feat: initial commit" />
|
||||||
<MESSAGE value="feat: example tools" />
|
<MESSAGE value="feat: example tools" />
|
||||||
<MESSAGE value="feat: Split string" />
|
<MESSAGE value="feat: Split string" />
|
||||||
@@ -409,7 +448,8 @@
|
|||||||
<MESSAGE value="chore: tools by category" />
|
<MESSAGE value="chore: tools by category" />
|
||||||
<MESSAGE value="feat: copy and import file" />
|
<MESSAGE value="feat: copy and import file" />
|
||||||
<MESSAGE value="refactor: tool options components" />
|
<MESSAGE value="refactor: tool options components" />
|
||||||
<option name="LAST_COMMIT_MESSAGE" value="refactor: tool options components" />
|
<MESSAGE value="fix: join text service" />
|
||||||
|
<option name="LAST_COMMIT_MESSAGE" value="fix: join text service" />
|
||||||
</component>
|
</component>
|
||||||
<component name="XSLT-Support.FileAssociations.UIState">
|
<component name="XSLT-Support.FileAssociations.UIState">
|
||||||
<expand />
|
<expand />
|
||||||
|
@@ -4,9 +4,7 @@ export function mergeText(
|
|||||||
deleteTrailingSpaces: boolean = true,
|
deleteTrailingSpaces: boolean = true,
|
||||||
joinCharacter: string = ''
|
joinCharacter: string = ''
|
||||||
): string {
|
): string {
|
||||||
const lines = text.split('\n');
|
let processedLines: string[] = text.split('\n');
|
||||||
|
|
||||||
let processedLines: string[] = lines;
|
|
||||||
if (deleteTrailingSpaces) {
|
if (deleteTrailingSpaces) {
|
||||||
processedLines = processedLines.map((line) => line.trimEnd());
|
processedLines = processedLines.map((line) => line.trimEnd());
|
||||||
}
|
}
|
||||||
|
64
src/pages/string/join/string-join.test.ts
Normal file
64
src/pages/string/join/string-join.test.ts
Normal file
@@ -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);
|
||||||
|
});
|
||||||
|
});
|
Reference in New Issue
Block a user