-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathtest_serializer_ulkb_variable.py
108 lines (88 loc) · 2.74 KB
/
test_serializer_ulkb_variable.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# Copyright (C) 2023 IBM Corp.
# SPDX-License-Identifier: Apache-2.0
from ulkb import *
from .test_serializer_ulkb import TestSerializerULKB
from .tests import main
class TestSerializerULKB_Variable(TestSerializerULKB):
def test_defaults(self):
x = Variable('x', bool)
self.assert_to_ulkb(
(false,
'⊥ : 𝔹'),
(x@bool,
'x : 𝔹'),
(x@BaseType('int'),
'x : ℤ'),
(x@TypeVariable('t'),
'x : t'),
(Variable('x', type=TypeVariable('t')),
'x : t'))
def test_ensure_ascii(self):
x = Variable('x', bool)
self.assert_to_ulkb(
(Variable('𝜄', FunctionType(bool, bool))(true),
'(\\U0001d704 : bool -> bool) (true : bool) : bool'),
ensure_ascii=True)
def test_show_annotations(self):
x = Variable('x', bool, i=[1, (2, ('3', {4}))])
self.assert_to_ulkb(
(x,
'x : 𝔹'),
(x@{'i': {'a': 1.}},
'x : 𝔹'))
self.assert_to_ulkb(
(x,
"x {i=[1, (2, ('3', {4}))]} : 𝔹"),
(x@{'i': {'a': 1.}},
"x {i={'a': 1.0}} : 𝔹"),
show_annotations=True)
def test_show_parentheses(self):
x = Variable('x', bool)
self.assert_to_ulkb(
(x,
'x : 𝔹'),
(x@BaseType('int'),
'x : ℤ'),
show_parentheses=True)
def test_show_types(self):
x = Variable('x', bool)
self.assert_to_ulkb(
(x@bool,
'x : 𝔹'),
show_types=False)
self.assert_to_ulkb(
(x@bool,
'x : 𝔹'),
show_types=True)
def test_misc(self):
nat = BaseType('nat')
x = Variable('x', type=nat >> nat, k8=8)
self.assert_to_ulkb(
(x,
'x : nat → nat'))
self.assert_to_ulkb(
(x,
'x {k8=8} : nat → nat'),
show_annotations=True)
self.assert_to_ulkb(
(x,
'x {k8=8} : nat -> nat'),
show_annotations=True, ensure_ascii=True)
self.assert_to_ulkb(
(x,
'x {k8=8} : nat → nat'),
omit_annotations=False, omit_parentheses=False)
self.assert_to_ulkb(
(x,
'x {k8=8} : nat → nat'),
omit_types=True, show_annotations=True)
self.assert_to_ulkb(
(x,
'x : nat → nat'),
omit_annotations=True)
self.assert_to_ulkb(
(x,
'x : nat → nat'),
omit_types=True, omit_annotations=True)
if __name__ == '__main__':
main()