-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ddea266
commit ffb37fc
Showing
7 changed files
with
435 additions
and
76 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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
let main = (): Unit { | ||
fn main(): Unit { | ||
print("Hello, World!") | ||
} |
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
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
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
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
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,4 +1,30 @@ | ||
import { compactNode, parseModule, Parser } from './parser' | ||
import { tokenize } from '../lexer/lexer' | ||
import { expect } from '@jest/globals' | ||
|
||
describe('parser', () => { | ||
it('buildTree', () => { | ||
|
||
const parse = (code) => { | ||
const p = new Parser(tokenize(code)) | ||
parseModule(p) | ||
const tree = p.buildTree() | ||
return { tree: compactNode(tree), errors: p.errors } | ||
} | ||
|
||
it('parse fn-def empty', () => { | ||
const { tree, errors } = parse('fn main() {}') | ||
expect(errors.length).toEqual(0) | ||
expect(tree).toEqual({ | ||
'module': [{ | ||
'statement': [{ | ||
'fn-def': [ | ||
{ 'fn-keyword': 'fn' }, | ||
{ 'identifier': 'main' }, | ||
{ 'o-paren': '(' }, { 'c-paren': ')' }, | ||
{ 'block': [{ 'o-brace': '{' }, { 'c-brace': '}' }] } | ||
] | ||
}] | ||
}] | ||
}) | ||
}) | ||
}) |
Oops, something went wrong.