Skip to content

Commit

Permalink
added tests for handling non-alphanumeric characters and an empty string
Browse files Browse the repository at this point in the history
  • Loading branch information
guy-borderless committed Jul 22, 2024
1 parent 2912aa1 commit 165855d
Showing 1 changed file with 46 additions and 1 deletion.
47 changes: 46 additions & 1 deletion text/_util_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,33 @@
import { assertEquals } from "@std/assert";
import { splitToWords } from "./_util.ts";

Deno.test({
name: "split() returns an empty array for an empty string",
fn() {
const result = splitToWords("");
assertEquals(result.length, 0);
},
});

Deno.test({
name:
"split() returns an empty array when input has no alphanumeric characters",
fn() {
const result = splitToWords("🦕♥️ 🦕♥️ 🦕♥️");
assertEquals(result.length, 0);
},
});

Deno.test({
name: "split() ignores non-alphanumeric characters mixed with words",
fn() {
const result = splitToWords("🦕deno♥️wuv");
const expected = ["deno", "wuv"];

assertEquals(result, expected);
},
});

Deno.test({
name: "split() handles whitespace",
fn() {
Expand All @@ -12,6 +39,15 @@ Deno.test({
},
});

Deno.test({
name: "split() handles whitespace at string end and start",
fn() {
const result = splitToWords(" deno Is AWESOME ");
const expected = ["deno", "Is", "AWESOME"];
assertEquals(result, expected);
},
});

Deno.test({
name: "split() handles mixed delimiters",
fn() {
Expand Down Expand Up @@ -97,7 +133,7 @@ Deno.test({
name: "split() handles acronym followed by a capitalized word",
fn() {
const result = splitToWords("I Love HTMLDivElement");
const expected = ["I", "Love","HTML", "Div", "Element"];
const expected = ["I", "Love", "HTML", "Div", "Element"];
assertEquals(result, expected);
},
});
Expand All @@ -110,3 +146,12 @@ Deno.test({
assertEquals(result, expected);
},
});

Deno.test({
name: "split() handles acronym followed by a capitalized word",
fn() {
const result = splitToWords("I Love HTMLDivElement");
const expected = ["I", "Love", "HTML", "Div", "Element"];
assertEquals(result, expected);
},
});

0 comments on commit 165855d

Please sign in to comment.