2018-08-27 00:01:18 +00:00
|
|
|
import { tap, expect } from '@pushrocks/tapbundle';
|
2016-11-13 22:11:49 +00:00
|
|
|
|
2018-08-27 00:01:18 +00:00
|
|
|
import * as smartfm from '../ts/index';
|
2016-11-13 22:11:49 +00:00
|
|
|
|
2018-08-27 00:01:18 +00:00
|
|
|
let testSmartfm = new smartfm.Smartfm({ fmType: 'yaml' });
|
2017-05-27 21:02:51 +00:00
|
|
|
tap.test('.parse()', async () => {
|
|
|
|
let testString = `---
|
2016-11-13 22:11:49 +00:00
|
|
|
testKey: testValue
|
|
|
|
testKey2: testValue2
|
|
|
|
---
|
2017-05-27 21:02:51 +00:00
|
|
|
# some markdown
|
2018-08-27 00:01:18 +00:00
|
|
|
`;
|
|
|
|
let parsedString = testSmartfm.parse(testString);
|
|
|
|
expect(parsedString.data).to.have.property('testKey', 'testValue');
|
|
|
|
expect(parsedString.data).to.have.property('testKey2', 'testValue2');
|
|
|
|
expect(parsedString.orig.toString()).to.equal(testString);
|
|
|
|
});
|
2019-09-04 12:13:42 +00:00
|
|
|
tap.test('should stringify data', async () => {
|
2018-08-27 00:01:18 +00:00
|
|
|
let testStringPure = `# some markdown heading\nsome first row`;
|
|
|
|
let testStringCombined = testSmartfm.stringify(testStringPure, { testData: 'hi' });
|
|
|
|
let resultString = '---\ntestData: hi\n---\n# some markdown heading\nsome first row\n';
|
|
|
|
expect(resultString).to.equal(testStringCombined);
|
|
|
|
});
|
2017-05-27 21:02:51 +00:00
|
|
|
|
2019-09-04 12:13:42 +00:00
|
|
|
tap.test('should parse a normal frontmatter file', async () => {
|
2019-09-04 13:45:18 +00:00
|
|
|
const normalFile = `---
|
|
|
|
heythere: awesome
|
|
|
|
---
|
|
|
|
really
|
|
|
|
`;
|
|
|
|
let result = testSmartfm.parse(normalFile);
|
|
|
|
expect(result.data.heythere).to.equal('awesome')
|
|
|
|
});
|
|
|
|
|
|
|
|
tap.test('should parse a commented out frontmatter file', async () => {
|
|
|
|
const commentedFile = `# ---
|
|
|
|
# heythere: awesome
|
|
|
|
# ---
|
|
|
|
really
|
|
|
|
`;
|
|
|
|
let result = testSmartfm.parseFromComments('# ', commentedFile);
|
|
|
|
console.log(result);
|
2019-09-04 12:13:42 +00:00
|
|
|
});
|
|
|
|
|
2018-08-27 00:01:18 +00:00
|
|
|
tap.start();
|