Skip to content

Commit

Permalink
- test: complete coverage for errors
Browse files Browse the repository at this point in the history
  • Loading branch information
brettz9 committed Feb 13, 2022
1 parent 81c9472 commit 44f199d
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions test/Parser.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { expect } from 'chai'
import { Parser } from '../src/Parser'

import { NoParsletFoundError, EarlyEndOfParseError } from '../src/errors'

import { typescriptGrammar } from '../src/grammars/typescriptGrammar'

describe('Parser', () => {
Expand All @@ -16,4 +18,41 @@ describe('Parser', () => {
expect(twoTokens).to.equal(false)
expect(finalTokens).to.equal(true)
})

it('should return token of error with `NoParsletFoundError.getToken`', () => {
const parser = new Parser({
grammar: typescriptGrammar
})

let error
try {
parser.parseText('{')
} catch (err) {
error = err
}

if (error === undefined) {
throw new Error('Failed')
}

const token = (error as NoParsletFoundError).getToken()

expect(token).to.deep.equal({
type: 'EOF',
text: ''
})
})

it('should return token of error with `EarlyEndOfParseError.getToken`', () => {
const error = new EarlyEndOfParseError({
type: 'import',
text: 'import'
})
const token = error.getToken()

expect(token).to.deep.equal({
type: 'import',
text: 'import'
})
})
})

0 comments on commit 44f199d

Please sign in to comment.