Files
BoosAPI/desktop/libs/markstream-vue/test/normalize-backslash-direct.test.ts
boos e0a5f57793 feat(desktop): embed BoosAPI Desktop client as a subproject
Vendor the rebranded BoosAPI Desktop client (Tauri + Vue) into metapi as
a monorepo subdirectory under desktop/. Source only — node_modules,
dist, Cargo target and the upstream .git history are excluded.

desktop/ keeps its own independent Cargo workspace (desktop/src-tauri
with crates/*); it is not part of the backend boosapi crate, so a
`cargo check` at the metapi root still compiles only the backend. Build
the desktop app from desktop/src-tauri per desktop/README.md.

Note: app icons are still placeholder assets pending the final BoosAPI
logo. The updater signing keys live outside the repo and are not
included.
2026-06-22 11:32:57 +08:00

68 lines
2.6 KiB
TypeScript

import { describe, expect, it } from 'vitest'
import { normalizeStandaloneBackslashT } from '../packages/markdown-parser/src/plugins/math'
describe('normalizeStandaloneBackslashT direct tests', () => {
it('escapes a raw tab to \\t', () => {
const out = normalizeStandaloneBackslashT('A\tB')
expect(out).toBe('A\\tB')
})
it('normalizes a LaTeX math block', () => {
const raw = `
\begin{bmatrix}
2x_2 - 8x_3 = 8 \\
5x_1 - 5x_3 = 10
\end{bmatrix}`
const out = normalizeStandaloneBackslashT(raw)
// should preserve \begin / \end and not split 'in' inside 'begin' to '\\in'
expect(out).toBe(`
\\begin{bmatrix}
2x_2 - 8x_3 = 8 \\\\
5x_1 - 5x_3 = 10
\\end{bmatrix}`)
})
it('no-op for already normalized string', () => {
const out = normalizeStandaloneBackslashT('\text{已知三维列向量}\boldsymbol{alpha },\boldsymbol{\beta }\text{,若}\boldsymbol{alpha }^T\boldsymbol{\beta }=0\text{,这个式子和正交补空间有什么联系吗}')
expect(out).toBe('\\text{已知三维列向量}\\boldsymbol{\\alpha },\\boldsymbol{\\beta }\\text{,若}\\boldsymbol{\\alpha }^T\\boldsymbol{\\beta }=0\\text{,这个式子和正交补空间有什么联系吗}')
})
it('no-op for already normalized string-1', () => {
const out = normalizeStandaloneBackslashT('W^\perp = \{ \mathbf{v} \in \mathbb{R}^3 \mid \mathbf{v} \cdot \mathbf{w} = 0 \text{ 对于所有 } \mathbf{w} \in W \}')
expect(out).toBe('W^\\perp = \{ \\mathbf{v} \\in \\mathbb{R}^3 \\mid \\mathbf{v} \\cdot \\mathbf{w} = 0 \\text{ 对于所有 } \\mathbf{w} \\in W \}')
})
it('no-op for already normalized string-2', () => {
const out = normalizeStandaloneBackslashT(`\[
\text{付费转化率} = \left( \frac{\text{付费用户数}}{\text{月活用户数}} \right) \times 100\%
\]`)
expect(out).toBe(`\[
\\text{付费转化率} = \\left( \\frac{\\text{付费用户数}}{\\text{月活用户数}} \\right) \\times 100\%
\]`)
})
it('normalizes a raw string to \\t', () => {
const out = normalizeStandaloneBackslashT('atb')
expect(out).toMatchInlineSnapshot(`"atb"`)
})
it('escapes exclamation to \\!', () => {
const out = normalizeStandaloneBackslashT('a!b')
expect(out).toBe('a\\!b')
})
it('span to \\{\\}', () => {
const out = normalizeStandaloneBackslashT('operatorname{span}{\boldsymbol{alpha}}')
expect(out).toBe('\\operatorname{span}\\{\\boldsymbol{\\alpha}\\}')
})
it('\n', () => {
const out = normalizeStandaloneBackslashT('\displaystyle \nabla\cdot\mathbf{E}= \frac{\rho}{\varepsilon_{0}}')
expect(out).toMatchInlineSnapshot(`
"\\displaystyle
abla\\mathbf{E}= \\frac{\\rho}{\\varepsilon_{0}}"
`)
})
})