54 lines
1.5 KiB
JavaScript
54 lines
1.5 KiB
JavaScript
// The Lucia project.
|
|
// Copyright 2026-2026 DSP, inc. All rights reserved.
|
|
// Authors:
|
|
// imacat.yang@dsp.im (imacat), 2026/03/05
|
|
|
|
import { describe, it, expect } from "vitest";
|
|
import {
|
|
sortNumEngZhtw,
|
|
sortNumEngZhtwForFilter,
|
|
} from "@/module/sortNumEngZhtw.js";
|
|
|
|
describe("sortNumEngZhtw", () => {
|
|
it("sorts numbers in ascending order", () => {
|
|
expect(sortNumEngZhtw(["3", "1", "2"])).toEqual(["1", "2", "3"]);
|
|
});
|
|
|
|
it("places numbers before strings", () => {
|
|
expect(sortNumEngZhtw(["b", "1", "a"])).toEqual(["1", "a", "b"]);
|
|
});
|
|
|
|
it("sorts English strings alphabetically", () => {
|
|
expect(sortNumEngZhtw(["cherry", "apple", "banana"])).toEqual([
|
|
"apple",
|
|
"banana",
|
|
"cherry",
|
|
]);
|
|
});
|
|
|
|
it("sorts mixed numbers and strings", () => {
|
|
const input = ["banana", "10", "apple", "2"];
|
|
const result = sortNumEngZhtw(input);
|
|
expect(result).toEqual(["2", "10", "apple", "banana"]);
|
|
});
|
|
});
|
|
|
|
describe("sortNumEngZhtwForFilter", () => {
|
|
it("returns negative when a < b (numbers)", () => {
|
|
expect(sortNumEngZhtwForFilter("1", "2")).toBeLessThan(0);
|
|
});
|
|
|
|
it("returns positive when a > b (numbers)", () => {
|
|
expect(sortNumEngZhtwForFilter("10", "2")).toBeGreaterThan(0);
|
|
});
|
|
|
|
it("places numbers before strings", () => {
|
|
expect(sortNumEngZhtwForFilter("1", "a")).toBeLessThan(0);
|
|
expect(sortNumEngZhtwForFilter("a", "1")).toBeGreaterThan(0);
|
|
});
|
|
|
|
it("compares strings using locale", () => {
|
|
expect(sortNumEngZhtwForFilter("a", "b")).toBeLessThan(0);
|
|
});
|
|
});
|