scim-docs/node_modules/tiny-matter/test/index.js

53 lines
1.8 KiB
JavaScript
Raw Normal View History

2024-08-29 10:10:19 +00:00
const assert = require('assert');
const matter = require('..');
const test = require('./test');
test('matter#empty', () => {
const x = matter();
assert.ok(x);
assert.strictEqual(typeof x, 'object');
assert.strictEqual(typeof x.content, 'string');
assert.strictEqual(typeof x.data, 'undefined');
});
test('matter#normal', () => {
const x = matter('---\ntitle: Front Matter\n---\nThis is content.');
assert.ok(x);
assert.strictEqual(typeof x, 'object');
assert.strictEqual(typeof x.data, 'object');
assert.strictEqual(typeof x.content, 'string');
assert.strictEqual(x.data.title, 'Front Matter');
assert.strictEqual(x.content, 'This is content.');
});
test('matter#json', () => {
const x = matter('---\n{ "title": "Front Matter" }\n\n\n\n---\nThis is content.', { parser: JSON.parse });
assert.strictEqual(typeof x, 'object');
assert.strictEqual(typeof x.data, 'object');
assert.strictEqual(typeof x.content, 'string');
assert.strictEqual(x.data.title, 'Front Matter');
assert.strictEqual(x.content, 'This is content.');
});
test('matter#delimiters', () => {
const x = matter('@@@@\ntitle: Front Matter\n~~~~\nThis is content.', {
delimiters: ['@@@@', '~~~~'],
});
assert.ok(x);
assert.strictEqual(typeof x, 'object');
assert.strictEqual(typeof x.data, 'object');
assert.strictEqual(typeof x.content, 'string');
assert.strictEqual(x.data.title, 'Front Matter');
assert.strictEqual(x.content, 'This is content.');
});
test('matter#crlf', () => {
const x = matter('---\r\ntitle: Front Matter\r\n---\r\nThis is content.');
assert.ok(x);
assert.strictEqual(typeof x, 'object');
assert.strictEqual(typeof x.data, 'object');
assert.strictEqual(typeof x.content, 'string');
assert.strictEqual(x.data.title, 'Front Matter');
assert.strictEqual(x.content, 'This is content.');
});