Skip to content

armgit / dbx

Public Imported from GitHub
0

25 MB lightweight cross-platform database client for 100+ databases, including MySQL, PostgreSQL, SQLite, Redis, MongoDB, DuckDB, SQL Server, and Dameng. Built-in AI, MCP Server, CLI, desktop and Docker. | 轻量级跨平台数据库管理工具,支持 MySQL、PostgreSQL、SQLite、Redis、MongoDB、达梦等 100+ 数据库,提供桌面端、Docker、CLI、内置 AI 助手和 MCP。

1.3 KB
Raw Blame
import { describe, expect, it } from "vitest";
import { createBoundedTextPreview } from "@/lib/common/boundedTextPreview";

describe("createBoundedTextPreview", () => {
  it("keeps short text unchanged", () => {
    const sql = "DROP TABLE IF EXISTS users;\nSELECT 1;";

    expect(createBoundedTextPreview(sql, { maxCharacters: 8192, maxLines: 200 })).toEqual({
      head: sql,
      tail: "",
      truncated: false,
      omittedCharacters: 0,
      omittedLines: 0,
      totalCharacters: sql.length,
      totalLines: 2,
    });
  });

  it("bounds a 40k-line preview by both characters and lines", () => {
    const sql = Array.from({ length: 40_000 }, (_, index) => `INSERT INTO t VALUES (${index});`).join("\n");
    const preview = createBoundedTextPreview(sql, { maxCharacters: 8192, maxLines: 200 });

    expect(preview.truncated).toBe(true);
    expect(preview.head.length + preview.tail.length).toBeLessThanOrEqual(8192);
    expect(preview.head.split("\n").length + preview.tail.split("\n").length).toBeLessThanOrEqual(200);
    expect(preview.head).toContain("VALUES (0)");
    expect(preview.tail).toContain("VALUES (39999)");
    expect(preview.omittedCharacters).toBeGreaterThan(1_000_000);
    expect(preview.omittedLines).toBeGreaterThanOrEqual(39_800);
  });
});