Skip to content

Commit

Permalink
Add test for IRPrinting
Browse files Browse the repository at this point in the history
  • Loading branch information
Shon Feder committed Aug 2, 2023
1 parent 94acf24 commit 0dd0d29
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
4 changes: 2 additions & 2 deletions quint/src/IRprinting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,9 +195,9 @@ export function sumToString(s: QuintSumType): string {
return s.fields.fields
.map((f: RowField) => {
if (isTheUnit(f.fieldType)) {
;`| ${f.fieldName}`
return `| ${f.fieldName}`
} else {
;`| ${f.fieldName}(${f.fieldType})`
return `| ${f.fieldName}(${typeToString(f.fieldType)})`
}
})
.join('\n')
Expand Down
17 changes: 17 additions & 0 deletions quint/test/IRprinting.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { assert } from 'chai'
import { buildDef, buildExpression, buildModuleWithDefs, buildType } from './builders/ir'
import { definitionToString, expressionToString, moduleToString, typeToString } from '../src/IRprinting'
import { toScheme } from '../src/types/base'
import { QuintSumType, unitValue } from '../src'

describe('moduleToString', () => {
const quintModule = buildModuleWithDefs(['var S: Set[int]', 'val f = S.filter(x => x + 1)'])
Expand Down Expand Up @@ -219,6 +220,22 @@ describe('typeToString', () => {
assert.deepEqual(typeToString(type), expectedType)
})

it('pretty prints sum types', () => {
const type: QuintSumType = {
kind: 'sum',
fields: {
kind: 'row',
fields: [
{ fieldName: 'A', fieldType: { kind: 'int', id: 0n } },
{ fieldName: 'B', fieldType: unitValue(0n) },
],
other: { kind: 'empty' },
},
}
const expectedType = '| A(int)\n| B'
assert.deepEqual(typeToString(type), expectedType)
})

it('pretty prints union types', () => {
const type = buildType('| { tag: "A", a: int } | { tag: "B", b: str }')
const expectedType = '| { tag: "A", a: int }\n| { tag: "B", b: str }'
Expand Down

0 comments on commit 0dd0d29

Please sign in to comment.