import test from 'ava' ; import parse , { Ast , WordTypeDict , wordTypes } from '../src/parser' ; import { Token } from '../src/tokenizer' ; test ( 'parses an empty list of tokens' , t => { const tokens = [ ] ; const ast = parse ( tokens ) ; const expectedAst = { body : [ ] , type : 'PROGRAM' } ; t . deepEqual ( ast , expectedAst ) ; } ) ; test ( 'has no duplicate words' , t => { const words = Object . keys ( wordTypes ) . reduce ( ( acc , key ) => { acc = [ ... acc , ... wordTypes [ key ] ] ; return acc ; } , [ ] as Array < string > ) ; interface groupedItemsDict { [ word ] : boolean ; } const grouped = words . reduce ( ( acc , item ) => { if ( acc [ item ] ) { t . fail ( ) ; } acc [ item ] = true ; return acc ; } , { } as groupedItemsDict ) ; t . truthy ( grouped ) ; } ) ;