Skip to content

Commit

Permalink
refactor(console): format test names (#3756)
Browse files Browse the repository at this point in the history
refactor test names
  • Loading branch information
timreichen authored Nov 1, 2023
1 parent 81dcc77 commit 068502c
Showing 1 changed file with 14 additions and 16 deletions.
30 changes: 14 additions & 16 deletions console/unicode_width_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,40 +3,38 @@
import { unicodeWidth } from "./unicode_width.ts";
import { assertEquals } from "../assert/mod.ts";

Deno.test("unicodeWidth", async (t) => {
await t.step("ASCII", () => {
Deno.test("unicodeWidth()", async (t) => {
await t.step("checks ASCII input", () => {
const lorem =
"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.";

assertEquals(unicodeWidth(lorem), lorem.length);
});

await t.step("CJK", () => {
await t.step("checks CJK input", () => {
const qianZiWen =
"天地玄黃宇宙洪荒日月盈昃辰宿列張寒來暑往秋收冬藏閏餘成歲律呂調陽雲騰致雨露結爲霜金生麗水玉出崑岡劍號巨闕珠稱夜光果珍李柰菜重芥薑海鹹河淡鱗潛羽翔龍師火帝鳥官人皇始制文字乃服衣裳推位讓國有虞陶唐弔民伐罪周發殷湯坐朝問道垂拱平章愛育黎首臣伏戎羌遐邇壹體率賓歸王鳴鳳在樹白駒食場化被草木賴及萬方蓋此身髮四大五常恭惟鞠養豈敢毀傷女慕貞絜男效才良知過必改得能莫忘罔談彼短靡恃己長信使可覆器欲難量墨悲絲淬詩讚羔羊";

assertEquals(unicodeWidth(qianZiWen), qianZiWen.length * 2);
});

await t.step("Unicode normalization", async (t) => {
const str = "á";
const str = "á";

await t.step("NFC", () => {
const nfc = str.normalize("NFC");
await t.step("checks NFC normalized input", () => {
const nfc = str.normalize("NFC");

assertEquals(nfc.length, 1);
assertEquals(unicodeWidth(nfc), 1);
});
assertEquals(nfc.length, 1);
assertEquals(unicodeWidth(nfc), 1);
});

await t.step("NFD", () => {
const nfd = str.normalize("NFD");
await t.step("checks NFD normalized input", () => {
const nfd = str.normalize("NFD");

assertEquals(nfd.length, 2);
assertEquals(unicodeWidth(nfd), 1);
});
assertEquals(nfd.length, 2);
assertEquals(unicodeWidth(nfd), 1);
});

await t.step("Emoji", () => {
await t.step("checks emoji input", () => {
assertEquals(unicodeWidth("👩"), 2); // Woman
assertEquals(unicodeWidth("🔬"), 2); // Microscope
// Note: Returns 4 for the below case, following the upstream crate
Expand Down

0 comments on commit 068502c

Please sign in to comment.