Skip to content

Commit

Permalink
[Lexer] Add code, hr lexer unittests.
Browse files Browse the repository at this point in the history
  • Loading branch information
aquariuslt committed Oct 1, 2017
1 parent 6f72512 commit e6cb716
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 11 deletions.
1 change: 0 additions & 1 deletion package.json
Expand Up @@ -16,7 +16,6 @@
},
"devDependencies": {
"@types/chai": "^4.0.4",
"@types/marked": "^0.3.0",
"@types/mocha": "^2.2.43",
"@types/node": "^8.0.28",
"@types/webpack": "^3.0.10",
Expand Down
18 changes: 18 additions & 0 deletions src/lexer/inline-lexer.ts
@@ -0,0 +1,18 @@
import * as marked from 'marked';
import Lexer from './index';

export default class InlineLexer {
private lexer;
private inlineLexer;

constructor(links: object, options?: LexerOptions) {
let $this = this;
$this.lexer = new Lexer();
$this.inlineLexer = new marked.InlineLexer(links);
}

output(source: string): string {
let $this = this;
return $this.inlineLexer.output($this.lexer.lex(source));
}
};
12 changes: 9 additions & 3 deletions src/parser/index.ts
@@ -1,11 +1,17 @@
import * as marked from 'marked';
import {TokensList} from '../shared/token';


export default class Parser {
constructor(src: TokensList, options?: ParserOptions) {
private parser;

constructor(src: TokensList, options?: ParserOptions) {
let $this = this;
$this.parser = new marked.Parser();
}

parse(src: TokensList, options?: ParserOptions): string {
return '';
parse(tokens: TokensList, options?: ParserOptions): string {
let $this = this;
return $this.parser.parse(tokens);
}
}
16 changes: 16 additions & 0 deletions test/unit/specs/inline-lexer-code.spec.js
@@ -0,0 +1,16 @@
import _ from 'lodash';

import InlineLexer from '@/lexer/inline-lexer';

describe('inline-lexer:code', () => {
let inlineLexer;

before(() => {
});

it('should compile inline code blocks', () => {
const mdString = `[This link](http://example.net/) has no title attribute.`;


});
});
11 changes: 10 additions & 1 deletion test/unit/specs/lexer-code.spec.js
Expand Up @@ -30,5 +30,14 @@ describe('lexer:code', () => {
expect(_.head(tokens).type).to.eq('code');
});

// TODO: add ```support```
it('should be using broken-line block to setup code blocks',()=>{
const mdString =`\`\`\`\ntell application "Foo"\n\t\tbeep\n\tend tell\n\`\`\`\n`;

let lexer = new Lexer();
let tokens = lexer.lex(mdString);

expect(tokens.length).to.eq(1);
expect(_.head(tokens).type).to.eq('code');
});

});
6 changes: 0 additions & 6 deletions test/unit/specs/marki.spec.js

This file was deleted.

18 changes: 18 additions & 0 deletions test/unit/specs/parser.spec.js
@@ -1,5 +1,23 @@
import _ from 'lodash';
import Lexer from '@/lexer';
import Parser from '@/parser';

describe('parser', () => {
let lexer;
let parser;

before(() => {
let $this = this;
lexer = new Lexer();
parser = new Parser();
});

it('parser base function', () => {
let $this = this;
const mdString = `[This link](http://example.net/) has no title attribute.`;

let tokens = lexer.lex(mdString);
let ret = parser.parse(tokens);

});

Expand Down

0 comments on commit e6cb716

Please sign in to comment.