-
Notifications
You must be signed in to change notification settings - Fork 123
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1269 from GaloisInc/rpc/record-bug
[RPC] Fix bug in Cryptol JSON -> Python for records, add test
- Loading branch information
Showing
5 changed files
with
74 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
cryptol-remote-api/python/tests/cryptol/test-files/Types.cry
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
module Types where | ||
|
||
b : Bit | ||
b = True | ||
|
||
w : [16] | ||
w = 42 | ||
|
||
z : Integer | ||
z = 420000 | ||
|
||
m : Z 12 | ||
m = 6 | ||
|
||
q : Rational | ||
q = ratio 5 4 | ||
|
||
t : (Bit, Integer) | ||
t = (False, 7) | ||
|
||
s : [3][3][8] | ||
s = [[1, 2, 3], [4, 5, 6], [7, 8, 9]] | ||
|
||
r : {xCoord : [32], yCoord : [32]} | ||
r = {xCoord = 12 : [32], yCoord = 21 : [32]} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import unittest | ||
from pathlib import Path | ||
import unittest | ||
import cryptol | ||
from cryptol.opaque import OpaqueValue | ||
from cryptol.bitvector import BV | ||
|
||
|
||
class CryptolTypeTests(unittest.TestCase): | ||
def test_types(self): | ||
c = cryptol.connect(verify=False) | ||
c.load_file(str(Path('tests','cryptol','test-files','Types.cry'))) | ||
|
||
# Bits | ||
self.assertEqual(c.eval('b').result(), True) | ||
|
||
# Words | ||
self.assertEqual(c.eval('w').result(), BV(size=16, value=42)) | ||
|
||
# Integers | ||
self.assertEqual(c.eval('z').result(), 420000) | ||
|
||
# Modular integers - not supported at all | ||
with self.assertRaises(ValueError): | ||
c.eval('m').result() | ||
|
||
# Rationals - supported only as opaque values | ||
self.assertIsInstance(c.eval('q').result(), OpaqueValue) | ||
|
||
# Tuples | ||
self.assertEqual(c.eval('t').result(), (False, 7)) | ||
|
||
# Sequences | ||
self.assertEqual(c.eval('s').result(), | ||
[[BV(size=8, value=1), BV(size=8, value=2), BV(size=8, value=3)], | ||
[BV(size=8, value=4), BV(size=8, value=5), BV(size=8, value=6)], | ||
[BV(size=8, value=7), BV(size=8, value=8), BV(size=8, value=9)]]) | ||
|
||
# Records | ||
self.assertEqual(c.eval('r').result(), | ||
{'xCoord': BV(size=32, value=12), | ||
'yCoord': BV(size=32, value=21)}) | ||
|
||
if __name__ == "__main__": | ||
unittest.main() |