Skip to content

Commit

Permalink
tests/*.error.inet
Browse files Browse the repository at this point in the history
  • Loading branch information
xieyuheng committed Aug 4, 2023
1 parent 1fff0d8 commit 970d7e0
Show file tree
Hide file tree
Showing 9 changed files with 58 additions and 57 deletions.
4 changes: 2 additions & 2 deletions TODO.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
[syntax] optional `,` in node definition

# error report

improve error report about type checking

`tests/*.error.inet`

# type

`defn` -- can be a sequence of words that build a net
Expand Down
20 changes: 4 additions & 16 deletions docs/tests/DiffList.inet
Original file line number Diff line number Diff line change
@@ -1,29 +1,17 @@
deftype Trivial 0 end

defnode sole
------
value!: Trivial
end
defnode sole -- value!: Trivial end

deftype List 1 end

defnode null
------
value!: List('a)
end

defnode cons
head: 'a
tail: List('a)
-------
value!: List('a)
end
defnode null -- value!: List('a) end
defnode cons head: 'a tail: List('a) -- value!: List('a) end

deftype DiffList 1 end

defnode diff
front: List('a)
------
-------
back: List('a)
value!: DiffList('a)
end
Expand Down
25 changes: 4 additions & 21 deletions docs/tests/List.inet
Original file line number Diff line number Diff line change
@@ -1,30 +1,13 @@
deftype Trivial 0 end

defnode sole
------
value!: Trivial
end
defnode sole -- value!: Trivial end

deftype List 1 end

defnode null
------
value!: List('a)
end
defnode null -- value!: List('a) end
defnode cons head: 'a tail: List('a) -- value!: List('a) end

defnode cons
head: 'a
tail: List('a)
-------
value!: List('a)
end

defnode append
target!: List('a)
rest: List('a)
------
return: List('a)
end
defnode append target!: List('a) rest: List('a) -- return: List('a) end

defrule null append
(append)-rest
Expand Down
19 changes: 3 additions & 16 deletions docs/tests/Nat.inet
Original file line number Diff line number Diff line change
@@ -1,22 +1,9 @@
deftype Nat 0 end

defnode zero
------
value!: Nat
end

defnode add1
prev: Nat
------
value!: Nat
end
defnode zero -- value!: Nat end
defnode add1 prev: Nat -- value!: Nat end

defnode add
target!: Nat
addend: Nat
-------
return: Nat
end
defnode add target!: Nat addend: Nat -- return: Nat end

defrule zero add
(add)-addend
Expand Down
4 changes: 4 additions & 0 deletions docs/tests/sign-mismatch.error.inet
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
deftype Trivial 0 end
defnode sole -- value!: Trivial end

show sole sole connect end
15 changes: 15 additions & 0 deletions docs/tests/sign-mismatch.error.inet.err
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
left: { t: { kind: 'TypeTerm', name: 'Trivial', args: [] }, sign: 1 },
right: { t: { kind: 'TypeTerm', name: 'Trivial', args: [] }, sign: 1 }
}
Error: [matchSignedTypes] I expect the sign to be opposite
at unifySignedTypes (/home/xyh/cicada-lang/inet/lib/lang/unify/unifySignedTypes.js:29:11)
at Object.cut (/home/xyh/cicada-lang/inet/lib/lang/builtins/connect.js:15:45)
at cutDefinition (/home/xyh/cicada-lang/inet/lib/lang/cut/cutDefinition.js:17:24)
at cut (/home/xyh/cicada-lang/inet/lib/lang/cut/cut.js:19:51)
at cutWords (/home/xyh/cicada-lang/inet/lib/lang/cut/cutWords.js:7:23)
at Show.<anonymous> (/home/xyh/cicada-lang/inet/lib/lang/stmts/Show.js:26:37)
at Generator.next (<anonymous>)
at /home/xyh/cicada-lang/inet/lib/lang/stmts/Show.js:8:71
at new Promise (<anonymous>)
at __awaiter (/home/xyh/cicada-lang/inet/lib/lang/stmts/Show.js:4:12)
8 changes: 8 additions & 0 deletions docs/tests/type-mismatch.error.inet
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
deftype Nat 0 end
defnode zero -- value!: Nat end
defnode add1 prev: Nat -- value!: Nat end

deftype Trivial 0 end
defnode sole -- value!: Trivial end

show sole add1 end
15 changes: 15 additions & 0 deletions docs/tests/type-mismatch.error.inet.err
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
left: { kind: 'TypeTerm', name: 'Trivial', args: [] },
right: { kind: 'TypeTerm', name: 'Nat', args: [] }
}
Error: [unifyTypes] I fail to unify types
at unifyTypes (/home/xyh/cicada-lang/inet/lib/lang/unify/unifyTypes.js:31:11)
at unifySignedTypes (/home/xyh/cicada-lang/inet/lib/lang/unify/unifySignedTypes.js:11:37)
at cutNodeDefinition (/home/xyh/cicada-lang/inet/lib/lang/cut/cutNodeDefinition.js:13:49)
at cutDefinition (/home/xyh/cicada-lang/inet/lib/lang/cut/cutDefinition.js:9:55)
at cut (/home/xyh/cicada-lang/inet/lib/lang/cut/cut.js:19:51)
at cutWords (/home/xyh/cicada-lang/inet/lib/lang/cut/cutWords.js:7:23)
at Show.<anonymous> (/home/xyh/cicada-lang/inet/lib/lang/stmts/Show.js:26:37)
at Generator.next (<anonymous>)
at /home/xyh/cicada-lang/inet/lib/lang/stmts/Show.js:8:71
at new Promise (<anonymous>)
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@
"build": "tsc",
"build:watch": "tsc --watch",
"test:js": "test-runner test node 'lib/**/*.test.js'",
"test:inet": "test-runner snapshot './bin/inet.js run' 'docs/tests/**/*.(inet)'",
"test": "npm run test:js && npm run test:inet",
"test:inet": "test-runner snapshot './bin/inet.js run' 'docs/tests/**/*.inet' --exclude 'docs/tests/**/*.error.inet'",
"test:inet-error": "test-runner snapshot-error './bin/inet.js run' 'docs/tests/**/*.error.inet'",
"test": "npm run test:js && npm run test:inet && npm run test:inet-error",
"format": "prettier src docs --write"
},
"devDependencies": {
Expand Down

0 comments on commit 970d7e0

Please sign in to comment.