marked-mfm/test/index.test.js

50 lines
2.2 KiB
JavaScript

import { marked } from 'marked'
import markedMfm from '../src/index.js'
describe('marked-mfm', () => {
test('inline', () => {
marked.use(markedMfm)
expect(marked('$[x2 this text is bigger]')).toBe('<p><span style="display: inline-block;" class="_mfm_x2_">this text is bigger</span></p>\n')
})
test('multiline', () => {
marked.use(markedMfm)
expect(marked('$[x2 line1\nline2]')).toBe('<p><span style="display: inline-block;" class="_mfm_x2_">line1\nline2</span></p>\n')
})
test('nested', () => {
marked.use(markedMfm)
expect(marked('$[x2 x2 $[sparkle sparkle]]')).toBe('<p><span style="display: inline-block;" class="_mfm_x2_">x2 <span style="display: inline-block;" class="_mfm_sparkle_">sparkle</span></span></p>\n')
})
test('lazy matching', () => {
marked.use(markedMfm)
expect(marked('$[x2 one] $[x2 two]')).toBe('<p><span style="display: inline-block;" class="_mfm_x2_">one</span> <span style="display: inline-block;" class="_mfm_x2_">two</span></p>\n')
})
test('nested & lazy matching', () => {
marked.use(markedMfm)
expect(marked('$[x2 one $[x2 two]] $[x2 three]')).toBe('<p><span style="display: inline-block;" class="_mfm_x2_">one <span style="display: inline-block;" class="_mfm_x2_">two</span></span> <span style="display: inline-block;" class="_mfm_x2_">three</span></p>\n')
})
test('invalid', () => {
marked.use(markedMfm)
expect(marked('$[invalid $[x2 test]]')).toBe('<p>$[invalid <span style="display: inline-block;" class="_mfm_x2_">test</span>]</p>\n')
})
test('one option', () => {
marked.use(markedMfm)
expect(marked('$[twitch.speed=2s test]')).toBe('<p><span style="display: inline-block; animation: mfm-twitch 2s ease infinite;" class="_mfm_twitch_">test</span></p>\n')
})
test('multiple options', () => {
marked.use(markedMfm)
expect(marked('$[spin.alternate,speed=0.5s test]')).toBe('<p><span style="display: inline-block; animation: mfm-spin 0.5s linear infinite; animation-direction: alternate;" class="_mfm_spin_">test</span></p>\n')
})
test('search', () => {
marked.use(markedMfm)
expect(marked('syuilo thighs search')).toBe('<a href="https://google.com/search?q=syuilo thighs" class="_mfm_search_">syuilo thighs search</a>')
})
})