54 lines
2.1 KiB
TypeScript
54 lines
2.1 KiB
TypeScript
import { assertEquals } from '@std/assert'
|
|
import { rewriteImageUrls } from '../src/core/markdown.ts'
|
|
|
|
Deno.test('rewriteImageUrls: ersetzt  durch Mapping', () => {
|
|
const mapping = new Map([['cat.png', 'https://blossom.example/hash.png']])
|
|
const input = ''
|
|
assertEquals(rewriteImageUrls(input, mapping), '')
|
|
})
|
|
|
|
Deno.test('rewriteImageUrls: absolute URL bleibt unverändert', () => {
|
|
const mapping = new Map([['cat.png', 'https://blossom.example/hash.png']])
|
|
const input = ''
|
|
assertEquals(rewriteImageUrls(input, mapping), input)
|
|
})
|
|
|
|
Deno.test('rewriteImageUrls: entfernt =WxH-Suffix', () => {
|
|
const mapping = new Map([['cat.png', 'https://blossom.example/hash.png']])
|
|
const input = ''
|
|
assertEquals(rewriteImageUrls(input, mapping), '')
|
|
})
|
|
|
|
Deno.test('rewriteImageUrls: bild-in-link [](link)', () => {
|
|
const mapping = new Map([['cat.png', 'https://blossom.example/hash.png']])
|
|
const input = '[](https://target.example.com)'
|
|
assertEquals(
|
|
rewriteImageUrls(input, mapping),
|
|
'[](https://target.example.com)',
|
|
)
|
|
})
|
|
|
|
Deno.test('rewriteImageUrls: mehrere Bilder im Text', () => {
|
|
const mapping = new Map([
|
|
['a.png', 'https://bl/a-hash.png'],
|
|
['b.jpg', 'https://bl/b-hash.jpg'],
|
|
])
|
|
const input = 'Text  more  end'
|
|
assertEquals(
|
|
rewriteImageUrls(input, mapping),
|
|
'Text  more  end',
|
|
)
|
|
})
|
|
|
|
Deno.test('rewriteImageUrls: lässt unbekannte Dateinamen stehen', () => {
|
|
const mapping = new Map([['cat.png', 'https://bl/c.png']])
|
|
const input = ''
|
|
assertEquals(rewriteImageUrls(input, mapping), input)
|
|
})
|
|
|
|
Deno.test('rewriteImageUrls: URL-Dekodierung für Leerzeichen-Namen', () => {
|
|
const mapping = new Map([['file with spaces.png', 'https://bl/hash.png']])
|
|
const input = ''
|
|
assertEquals(rewriteImageUrls(input, mapping), '')
|
|
})
|