Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions src/lib/e-lattice.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// @ts-expect-error Runtime types come from `bun test`, not the app tsconfig.
import { expect, test } from 'bun:test'
import { inSight, SIGHT_LIMIT } from './e-lattice.ts'

test('a lattice point is in sight only when nothing else sits on the ray', () => {
expect(inSight(3, 4)).toBe(true)
expect(inSight(-3, 4)).toBe(true)
expect(inSight(1, 0)).toBe(true)
expect(inSight(2, 4)).toBe(false)
expect(inSight(0, 2)).toBe(false)
expect(inSight(0, 0)).toBe(false)
})

test('the visible-share limit is 6 over pi squared', () => {
expect(SIGHT_LIMIT).toBe(6 / Math.PI ** 2)
})
31 changes: 31 additions & 0 deletions src/lib/token-classes.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// @ts-expect-error Runtime types come from `bun test`, not the app tsconfig.
import { expect, test } from 'bun:test'
import { codeToHtml } from 'shiki'
import { createCssVariablesTheme } from 'shiki/core'
import { tokenClasses } from './token-classes.ts'

// Astro's markdown highlighter, not the bundled theme named `css-variables`.
const theme = createCssVariablesTheme({ variablePrefix: '--astro-code-' })

const highlight = (code: string, lang: string): Promise<string> =>
codeToHtml(code, { lang, theme, transformers: [tokenClasses] })

test('highlighted tokens keep colour as tok-* classes instead of inline style', async () => {
const html = await highlight('const x = "hi"', 'javascript')
expect(html).not.toContain('style=')
expect(html).toContain('class="tok-keyword"')
expect(html).toContain('class="tok-constant"')
expect(html).toContain('class="tok-string-expression"')
})

test('a shell flag that Shiki files as a string is marked tok-flag', async () => {
const html = await highlight('echo -n hi', 'bash')
expect(html).toContain('class="tok-flag"> -n</span>')
expect(html).toContain('class="tok-string"> hi</span>')
})

test('a span whose colour is not a token variable gets no tok class', async () => {
const html = await highlight('echo \\\n -v', 'bash')
expect(html).toContain('<span> \\</span>')
expect(html).toContain('class="tok-flag"> -v</span>')
})
Loading