-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Lexer] Add code, hr lexer unittests.
- Loading branch information
1 parent
6e824c3
commit 6f72512
Showing
5 changed files
with
224 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,5 +17,4 @@ export default class Lexer { | |
return $this.lexer.lex(source); | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,17 @@ | ||
export default class TokenTypes { | ||
SPACE = 'space'; | ||
CODE = 'code'; | ||
HEADING = 'heading'; | ||
TABLE = 'table'; | ||
HR = 'hr'; | ||
BLOCKQUOTE_START = 'blockquote_start'; | ||
BLOCKQUOTE_END = 'blockquote_end'; | ||
LIST_START = 'list_start'; | ||
LOOSE_ITEM_START = 'loose_item_start'; | ||
LIST_ITEM_START = 'list_item_start'; | ||
LIST_ITEM_END = 'list_item_end'; | ||
LIST_END = 'list_end'; | ||
PARAGRAPH = 'paragraph'; | ||
HTML = 'html'; | ||
TEXT = 'text'; | ||
|
||
export default { | ||
SPACE: 'space', | ||
CODE: 'code', | ||
HEADING: 'heading', | ||
TABLE: 'table', | ||
HR: 'hr', | ||
BLOCKQUOTE_START: 'blockquote_start', | ||
BLOCKQUOTE_END: 'blockquote_end', | ||
LIST_START: 'list_start', | ||
LOOSE_ITEM_START: 'loose_item_start', | ||
LIST_ITEM_START: 'list_item_start', | ||
LIST_ITEM_END: 'list_item_end', | ||
LIST_END: 'list_end', | ||
PARAGRAPH: 'paragraph', | ||
HTML: 'html', | ||
TEXT: 'text' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import _ from 'lodash'; | ||
import Lexer from '@/lexer'; | ||
|
||
describe('lexer:code', () => { | ||
|
||
it('should be using 4 space before to setup code blocks', () => { | ||
const mdString = ` This is a code block\n`; | ||
let lexer = new Lexer(); | ||
let tokens = lexer.lex(mdString); | ||
|
||
expect(tokens.length).to.eq(1); | ||
expect(_.head(tokens).type).to.eq('code'); | ||
}); | ||
|
||
it('should be using 1 tab before to setup code blocks', () => { | ||
const mdString = `\tThis is a code block\n`; | ||
let lexer = new Lexer(); | ||
let tokens = lexer.lex(mdString); | ||
|
||
expect(tokens.length).to.eq(1); | ||
expect(_.head(tokens).type).to.eq('code'); | ||
}); | ||
|
||
it('should be using multi-line spaces to setup code blocks', () => { | ||
const mdString = `\ttell application "Foo"\n\t\tbeep\n\tend tell\n`; | ||
let lexer = new Lexer(); | ||
let tokens = lexer.lex(mdString); | ||
|
||
expect(tokens.length).to.eq(1); | ||
expect(_.head(tokens).type).to.eq('code'); | ||
}); | ||
|
||
// TODO: add ```support``` | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import _ from 'lodash'; | ||
import Lexer from '@/lexer'; | ||
|
||
describe('lexer:hr', () => { | ||
|
||
it('should lex spaced * as hr', () => { | ||
const mdString = `* * *`; | ||
let lexer = new Lexer(); | ||
let tokens = lexer.lex(mdString); | ||
|
||
expect(tokens.length).to.eq(1); | ||
expect(_.head(tokens).type).to.eq('hr'); | ||
}); | ||
|
||
it('should lex 3 continuous * as hr', () => { | ||
const mdString = `***`; | ||
let lexer = new Lexer(); | ||
let tokens = lexer.lex(mdString); | ||
|
||
expect(tokens.length).to.eq(1); | ||
expect(_.head(tokens).type).to.eq('hr'); | ||
}); | ||
|
||
it('should lex 5 continuous * as hr', () => { | ||
const mdString = `*****`; | ||
let lexer = new Lexer(); | ||
let tokens = lexer.lex(mdString); | ||
|
||
expect(tokens.length).to.eq(1); | ||
expect(_.head(tokens).type).to.eq('hr'); | ||
}); | ||
|
||
it('should lex spaced - as hr', () => { | ||
const mdString = `- - -`; | ||
let lexer = new Lexer(); | ||
let tokens = lexer.lex(mdString); | ||
|
||
expect(tokens.length).to.eq(1); | ||
expect(_.head(tokens).type).to.eq('hr'); | ||
}); | ||
|
||
it('should lex many continues - as hr', () => { | ||
const mdString = `---------------------------------------`; | ||
let lexer = new Lexer(); | ||
let tokens = lexer.lex(mdString); | ||
|
||
expect(tokens.length).to.eq(1); | ||
expect(_.head(tokens).type).to.eq('hr'); | ||
}); | ||
|
||
|
||
it('should not lex 2 (less than 3) spaced * as hr', () => { | ||
const mdString = `* *`; | ||
let lexer = new Lexer(); | ||
let tokens = lexer.lex(mdString); | ||
|
||
expect(_.head(tokens).type).not.to.eq('hr'); | ||
}); | ||
|
||
it('should not lex 2 (less than 3) continues * as hr', () => { | ||
const mdString = `**`; | ||
let lexer = new Lexer(); | ||
let tokens = lexer.lex(mdString); | ||
|
||
expect(_.head(tokens).type).not.to.eq('hr'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters