Skip to content

Commit

Permalink
WIP: noImplicitAny in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
joews committed Mar 12, 2017
1 parent f26c1a7 commit 9a93f50
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 24 deletions.
12 changes: 6 additions & 6 deletions src/__tests__/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,22 @@ import parse from '../parser'
import typeCheck from '../type-checker'
import interpret from '../interpreter'

export function fixture (fileName) {
export function fixture (fileName: string) {
const filePath = join(__dirname, 'fixtures', fileName)
return readFileSync(filePath, 'utf8')
}

export function run (program) {
export function run (source: string) {
const env = getRootEnv()
const typeEnv = getTypeEnv(env)

const ast = parse(program)
const ast = parse(source)
const [typed] = typeCheck(ast, typeEnv)
return interpret(typed, getRootEnv())
}

export function testResult (program, expectedOutput) {
test(program, () => {
expect(run(program)[0]).toEqual(expectedOutput)
export function testResult (source: string, expectedOutput: any) {
test(source, () => {
expect(run(source)[0]).toEqual(expectedOutput)
})
}
8 changes: 4 additions & 4 deletions src/__tests__/parser-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ import { fixture } from './helpers'
// snapshot tests for the parser
//

function testFixture (fixtureName) {
function testFixture (fixtureName: string) {
test(fixtureName, () => {
expect(parse(fixture(fixtureName))).toMatchSnapshot()
})
}

function testParse (peachCode) {
test(peachCode, () => {
expect(parse(peachCode)).toMatchSnapshot()
function testParse (source: string) {
test(source, () => {
expect(parse(source)).toMatchSnapshot()
})
}

Expand Down
27 changes: 14 additions & 13 deletions src/__tests__/type-checker-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import typeCheck from '../type-checker'
import { getRootEnv, getTypeEnv } from '../env'
import { fixture } from './helpers'
import { clone } from '../util'
import { Type } from '../types'
import { TypedNode, AstNode } from '../node-types'

import {
Expand All @@ -14,23 +15,23 @@ import {
BooleanType
} from '../types'

function testTypeCheck (code, env = getTypeEnv(getRootEnv())) {
test(code, () => {
const parsed = parse(code)
function testTypeCheck (source: string, env = getTypeEnv(getRootEnv())) {
test(source, () => {
const parsed = parse(source)
const [lastNode] = typeCheck(parsed, env)
const type = lastNode.exprType.toString()
expect(type).toMatchSnapshot()
})
};

function testFails (code, env = getTypeEnv(getRootEnv())) {
test(code, () => {
const parsed = parse(code)
function testFails (source: string, env = getTypeEnv(getRootEnv())) {
test(source, () => {
const parsed = parse(source)
expect(() => typeCheck(parsed, env)).toThrowErrorMatchingSnapshot()
})
}

function testFixture (fixtureName, env = getTypeEnv(getRootEnv())) {
function testFixture (fixtureName: string, env = getTypeEnv(getRootEnv())) {
test(fixtureName, () => {
const parsed = parse(fixture(fixtureName))
const [lastNode] = typeCheck(parsed, env)
Expand Down Expand Up @@ -86,7 +87,7 @@ testFails(`if (1) 1 else 2`)

// the peach type checker works over nodes with an `exprType` property.
// helper for creating nodes for synthetic type tests
function typed (type): TypedNode {
function typed (type: Type): TypedNode {
return {
exprType: type,
type: 'Str',
Expand All @@ -96,11 +97,11 @@ function typed (type): TypedNode {

// simulate a user-defined type
class PairType extends TypeOperator {
constructor (a, b) {
constructor (a: Type, b: Type) {
super('*', [a, b])
}

static of (name, [a, b]) {
static of (name: string, [a, b]: Type[]) {
return new PairType(a, b)
}

Expand All @@ -109,9 +110,9 @@ class PairType extends TypeOperator {
}
}

const A = typed(new TypeVariable())
const B = typed(new TypeVariable())
const AB = typed(new PairType(A, B))
const A = new TypeVariable()
const B = new TypeVariable()
const AB = new PairType(A, B)

const testEnv = () => ({
// No unit type yet, so all functions take exactly one argument
Expand Down
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"moduleResolution": "node",
"outDir": "./dist",
"target": "es2017",
"sourceMap": true
"sourceMap": true,
"noImplicitAny": true
},
"include": [
"./src/**/*"
Expand Down

0 comments on commit 9a93f50

Please sign in to comment.