parser-combinator
Version:
Parser combinators
98 lines (70 loc) • 2.47 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
var _textParser = require('../../../lib/standard/markdown/text-parser');
var _textParser2 = _interopRequireDefault(_textParser);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var value = undefined; /**
* Created by Simon on 14/12/2016.
*/
var accepted = undefined;
var parser = null;
function testLine(line) {
var parsing = parser.parse(line);
value = parsing.value;
accepted = parsing.isAccepted();
}
exports.default = {
setUp: function setUp(done) {
parser = _textParser2.default;
done();
},
'test empty text': function testEmptyText(test) {
test.expect(2);
testLine('');
test.ok(!accepted, 'empty line are to be rejected');
testLine(' ');
test.ok(!accepted, 'blank line are to be rejected');
test.done();
},
'test simple text': function testSimpleText(test) {
test.expect(2);
testLine('text');
test.deepEqual(value, { paragraph: [{ text: 'text' }] });
testLine(' text ');
test.deepEqual(value, { paragraph: [{ text: 'text' }] });
test.done();
},
'test italic': function testItalic(test) {
test.expect(1);
testLine('*text*');
test.deepEqual(value, { paragraph: [{ italic: 'text' }] });
test.done();
},
'test bold': function testBold(test) {
test.expect(1);
testLine('**text**');
test.deepEqual(value, { paragraph: [{ bold: 'text' }] });
test.done();
},
'test combined format': function testCombinedFormat(test) {
test.expect(1);
testLine(' *italic* text **then bold** ');
var expected = {
paragraph: [{ italic: 'italic' }, { text: ' text ' }, { bold: 'then bold' }, { text: ' ' }]
};
test.deepEqual(value, expected);
test.done();
},
'single \\n must be translated as space': function singleNMustBeTranslatedAsSpace(test) {
test.expect(1);
testLine(' *italic* text\n**then bold** ');
var expected = {
paragraph: [{ italic: 'italic' }, { text: ' text ' }, { bold: 'then bold' }, { text: ' ' }]
};
test.deepEqual(value, expected);
test.done();
}
};
//# sourceMappingURL=text-parser-test.js.map