Skip to content

Commit

Permalink
Add test for type inference
Browse files Browse the repository at this point in the history
  • Loading branch information
Shon Feder committed Oct 6, 2023
1 parent f07690c commit 63cb281
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions quint/test/types/inferrer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { TypeInferenceResult, TypeInferrer } from '../../src/types/inferrer'
import { typeSchemeToString } from '../../src/types/printing'
import { errorTreeToString } from '../../src/errorTree'
import { parseMockedModule } from '../util'
import { moduleToString } from '../../src'

Check failure on line 7 in quint/test/types/inferrer.test.ts

View workflow job for this annotation

GitHub Actions / quint-linting

'moduleToString' is defined but never used. Allowed unused vars must match /^_/u

Check failure on line 7 in quint/test/types/inferrer.test.ts

View workflow job for this annotation

GitHub Actions / quint-linting

'moduleToString' is defined but never used

describe('inferTypes', () => {
function inferTypesForDefs(defs: string[]): TypeInferenceResult {
Expand Down Expand Up @@ -134,6 +135,31 @@ describe('inferTypes', () => {
])
})

it('infers types for variants', () => {
const defs = ['type T = A(int) | B', 'val a = variant("A", 3)']

const [errors, types] = inferTypesForDefs(defs)
assert.isEmpty(errors, `Should find no errors, found: ${[...errors.values()].map(errorTreeToString)}`)

const stringTypes = Array.from(types.entries()).map(([id, type]) => [id, typeSchemeToString(type)])
assert.sameDeepMembers(stringTypes, [
[14n, 'str'],
[15n, 'int'],
[16n, '(A(int))'],
[17n, '(A(int))'],
[10n, 'str'],
[11n, '{}'],
[12n, '(B({}))'],
[13n, '(B({}))'],
[5n, 'int'],
[4n, 'str'],
[6n, 'int'],
[7n, '(A(int))'],
[8n, '(int) => (A(int))'],
[9n, '(int) => (A(int))'],
])
})

it('keeps track of free variables in nested scopes (#966)', () => {
const defs = ['def f(a) = a == "x"', 'def g(b) = val nested = (1,2) { f(b) }']

Expand Down

0 comments on commit 63cb281

Please sign in to comment.