marked-mfm/test/index.test.js

50 lines
1.8 KiB
JavaScript
Raw Normal View History

2022-07-08 08:32:20 +00:00
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 class="_mfm_x2_" >this text is bigger</span></p>\n')
2022-07-08 08:32:20 +00:00
})
2022-07-08 11:46:59 +00:00
test('multiline', () => {
marked.use(markedMfm)
expect(marked('$[x2 line1\nline2]')).toBe('<p><span class="_mfm_x2_" >line1\nline2</span></p>\n')
2022-07-08 11:46:59 +00:00
})
2022-07-08 08:32:20 +00:00
test('nested', () => {
marked.use(markedMfm)
expect(marked('$[x2 x2 $[sparkle sparkle]]')).toBe('<p><span class="_mfm_x2_" >x2 <span class="_mfm_sparkle_" >sparkle</span></span></p>\n')
2022-07-08 08:32:20 +00:00
})
2022-07-08 08:59:00 +00:00
2022-07-08 17:54:26 +00:00
test('lazy matching', () => {
marked.use(markedMfm)
expect(marked('$[x2 one] $[x2 two]')).toBe('<p><span class="_mfm_x2_" >one</span> <span class="_mfm_x2_" >two</span></p>\n')
2022-07-08 17:54:26 +00:00
})
test('nested & lazy matching', () => {
marked.use(markedMfm)
expect(marked('$[x2 one $[x2 two]] $[x2 three]')).toBe('<p><span class="_mfm_x2_" >one <span class="_mfm_x2_" >two</span></span> <span class="_mfm_x2_" >three</span></p>\n')
2022-07-08 17:54:26 +00:00
})
2022-07-08 08:59:00 +00:00
test('invalid', () => {
marked.use(markedMfm)
expect(marked('$[invalid $[x2 test]]')).toBe('<p>$[invalid <span class="_mfm_x2_" >test</span>]</p>\n')
2022-07-08 09:59:28 +00:00
})
test('one option', () => {
marked.use(markedMfm)
expect(marked('$[twitch.speed=2s test]')).toBe('<p><span class="_mfm_twitch_" data-speed="2s">test</span></p>\n')
2022-07-08 09:59:28 +00:00
})
test('multiple options', () => {
marked.use(markedMfm)
expect(marked('$[spin.alternate,speed=0.5s test]')).toBe('<p><span class="_mfm_spin_" data-alternate data-speed="0.5s">test</span></p>\n')
2022-07-08 08:59:00 +00:00
})
2022-07-08 10:33:03 +00:00
test('search', () => {
marked.use(markedMfm)
2022-07-09 11:27:23 +00:00
expect(marked('syuilo thighs search')).toBe('<p><a href="https://google.com/search?q=syuilo thighs" class="_mfm_search_">syuilo thighs search</a></p>\n')
2022-07-08 10:33:03 +00:00
})
2022-07-08 08:32:20 +00:00
})