61 lines
1.8 KiB
JavaScript
61 lines
1.8 KiB
JavaScript
import assert from 'node:assert/strict'
|
|
import test from 'node:test'
|
|
import {
|
|
formatQuoteLine,
|
|
getQuoteContentStartLine,
|
|
getQuoteLineBody,
|
|
getQuoteLineEntries,
|
|
isQuoteMarkerLine,
|
|
normalizeQuoteEditableValue,
|
|
parseQuoteOptions
|
|
} from '../lib/markdown-quote.js'
|
|
|
|
test('인용 마커 줄과 본문을 판별한다', () => {
|
|
assert.equal(isQuoteMarkerLine('>'), true)
|
|
assert.equal(isQuoteMarkerLine('> 본문'), true)
|
|
assert.equal(isQuoteMarkerLine('본문'), false)
|
|
assert.equal(getQuoteLineBody('> 본문'), '본문')
|
|
})
|
|
|
|
test('인용 옵션은 대괄호와 중괄호 선언을 모두 파싱한다', () => {
|
|
assert.deepEqual(parseQuoteOptions('[!bg=blue]'), { quoteBackground: 'blue' })
|
|
assert.deepEqual(parseQuoteOptions('{bg=purple}'), { quoteBackground: 'purple' })
|
|
assert.equal(parseQuoteOptions('{bg=unknown}'), null)
|
|
})
|
|
|
|
test('인용 줄 직렬화는 원문 모드와 편집 모드를 구분한다', () => {
|
|
assert.equal(formatQuoteLine('본문', false), '> 본문')
|
|
assert.equal(formatQuoteLine('', false), '> ')
|
|
assert.equal(formatQuoteLine('> 원문', true), '> 원문')
|
|
assert.equal(formatQuoteLine('원문', true), '원문')
|
|
})
|
|
|
|
test('인용 블록 본문 줄 위치를 옵션 줄 이후로 계산한다', () => {
|
|
const block = {
|
|
text: '첫 줄\n둘째 줄',
|
|
meta: {
|
|
startLine: 10,
|
|
endLine: 12,
|
|
quoteContentStartLine: 11
|
|
}
|
|
}
|
|
|
|
assert.equal(getQuoteContentStartLine(block), 11)
|
|
assert.deepEqual(getQuoteLineEntries(block), [
|
|
{
|
|
text: '첫 줄',
|
|
sourceLine: 11,
|
|
sourceIndex: 1
|
|
},
|
|
{
|
|
text: '둘째 줄',
|
|
sourceLine: 12,
|
|
sourceIndex: 2
|
|
}
|
|
])
|
|
})
|
|
|
|
test('인용 편집 중 브라우저가 만든 >. 접두를 정리한다', () => {
|
|
assert.equal(normalizeQuoteEditableValue('>. 발타자르\n> 정상'), '발타자르\n> 정상')
|
|
})
|