Skip to content

Commit e821d01

Browse files
committed
fix(string): prevent removing new line
1 parent ddf30fc commit e821d01

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

src/routes/string/+page.svelte

+4-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
result = source.toLowerCase().replace(/(?:^|\s)\S/g, (a) => a.toUpperCase());
1515
}
1616
function onRemovePunctuation() {
17-
result = source.replace(/[^\w\s]|_/g, '').replace(/\s+/g, ' ');
17+
result = source.replace(/[^\w\s\n]|_/g, '');
1818
}
1919
2020
function onSlugify() {
@@ -56,6 +56,7 @@
5656
>
5757
Source
5858
</label><textarea
59+
data-testid="inputData"
5960
id="inputData"
6061
class="h-40 shadow appearance-none border rounded w-full py-2 px-3 text-gray-700 dark:text-gray-400 leading-tight focus:outline-none focus:shadow-outline mb-4"
6162
placeholder="Enter your data here..."
@@ -66,6 +67,7 @@
6667
<button
6768
class="m-1 inline-flex items-center justify-center text-sm ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 h-10 bg-[rgb(16,185,129)] hover:bg-[rgb(5,150,105)] text-white font-bold py-2 px-4 rounded focus:outline-none focus:shadow-outline"
6869
on:click={item.action}
70+
data-testid={item.name}
6971
>
7072
{item.name}</button
7173
>
@@ -77,6 +79,7 @@
7779
>
7880
Result
7981
</label><textarea
82+
data-testid="outputData"
8083
id="outputData"
8184
class="h-40 shadow appearance-none border rounded w-full py-2 px-3 text-gray-700 dark:text-gray-400 leading-tight focus:outline-none focus:shadow-outline"
8285
placeholder="Your result will appear here..."

tests/string.test.ts

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { test, expect } from '@playwright/test';
2+
3+
test('Remove Punctuation', async ({ page }) => {
4+
await page.goto('/tulkit');
5+
await page.getByRole('link', { name: 'String To UPPERCASE,' }).click();
6+
await page.getByTestId('inputData').fill('1.000.000\n2.000.000');
7+
await page.getByTestId('Remove Punctuation').click();
8+
expect(await page.getByTestId('outputData').inputValue()).toBe('1000000\n2000000');
9+
});

0 commit comments

Comments
 (0)