aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/test/lux/ffi/export.jvm.lux
blob: bb8d092ceab54bab6ce111714a96ddbeac20f960 (plain)
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
(.using
 [library
  [lux "*"
   ["_" test {"+" Test}]
   ["[0]" meta]
   ["[0]" debug]
   ["[0]" static]
   [abstract
    [monad {"+" do}]]
   [data
    ["[0]" bit ("[1]#[0]" equivalence)]
    ["[0]" text ("[1]#[0]" equivalence)
     ["%" format]]]
   [macro
    ["[0]" code]
    ["[0]" template]]
   [math
    ["[0]" random {"+" Random} ("[1]#[0]" monad)]
    [number {"+" hex}
     ["[0]" i64]
     ["[0]" int ("[1]#[0]" equivalence)]
     ["[0]" frac ("[1]#[0]" equivalence)]]]]]
 [\\library
  ["[0]" /
   ["/[1]" //]]])

(def: expected_boolean (//.as_boolean (static.random_bit)))
(def: expected_byte (//.as_byte (static.random_int)))
(def: expected_short (//.as_short (static.random_int)))
(def: expected_int (//.as_int (static.random_int)))
(def: expected_long (//.as_long (static.random_int)))
(def: expected_char (//.as_char (static.random_int)))
(def: expected_float (//.as_float (static.random_frac)))
(def: expected_double (//.as_double (static.random_frac)))
(def: expected_string (//.as_string (static.random code.text (random.lower_case 2))))

(`` (`` (/.export: Primitives
          ... Constants
          (actual_boolean boolean ..expected_boolean)
          (actual_byte byte ..expected_byte)
          (actual_short short ..expected_short)
          (actual_int int ..expected_int)
          (actual_long long ..expected_long)
          (actual_char char ..expected_char)
          (actual_float float ..expected_float)
          (actual_double double ..expected_double)

          ... Methods
          (~~ (template [<type> <+>]
                [(((~~ (template.symbol [<type> "_method"]))
                   [left <type>
                    right <type>])
                  <type>
                  ((~~ (template.symbol [//._] ["as_" <type>]))
                   (<+> ((~~ (template.symbol [//._] ["of_" <type>])) left)
                        ((~~ (template.symbol [//._] ["of_" <type>])) right))))]

                [boolean and]
                [byte int.+]
                [short int.+]
                [int int.+]
                [long int.+]
                [char int.+]
                [float frac.+]
                [double frac.+]
                ))
          )))

(`` (`` (//.import: Primitives
          "[1]::[0]"
          ("static" actual_boolean boolean)
          ("static" actual_byte byte)
          ("static" actual_short short)
          ("static" actual_int int)
          ("static" actual_long long)
          ("static" actual_char char)
          ("static" actual_float float)
          ("static" actual_double double)

          (~~ (template [<type>]
                [("static" (~~ (template.symbol [<type> "_method"])) [<type> <type>] <type>)]

                [boolean]
                [byte]
                [short]
                [int]
                [long]
                [char]
                [float]
                [double]
                ))
          )))

(/.export: Objects
  (actual_string java/lang/String ..expected_string)

  ((string_method [left java/lang/String right java/lang/String])
   java/lang/String
   (//.as_string (%.format (//.of_string left) (//.of_string right))))

  (([a] left [left a right a]) a left)
  (([a] right [left a right a]) a right))

(//.import: Objects
  "[1]::[0]"
  ("static" actual_string java/lang/String)

  ("static" string_method [java/lang/String java/lang/String] java/lang/String)
  
  ("static" [a] left [a a] a)
  ("static" [a] right [a a] a))

(def: tiny_int
  (Random Int)
  (random#each (|>> (i64.and (hex "F")) .int)
               random.nat))

(def: tiny_frac
  (Random Frac)
  (random#each (|>> (i64.and (hex "FFFF"))
                    .int
                    int.frac)
               random.nat))

(`` (`` (def: .public test
          Test
          (<| (_.covering /._)
              (do [! random.monad]
                [(~~ (template [<type> <as> <random>]
                       [(~~ (template.symbol [left_ <type>])) (# ! each (|>> <as>) <random>)
                        (~~ (template.symbol [right_ <type>])) (# ! each (|>> <as>) <random>)]

                       [boolean //.as_boolean random.bit]
                       [byte //.as_byte ..tiny_int]
                       [short //.as_short ..tiny_int]
                       [int //.as_int ..tiny_int]
                       [long //.as_long ..tiny_int]
                       [char //.as_char ..tiny_int]
                       [float //.as_float ..tiny_frac]
                       [double //.as_double ..tiny_frac]
                       [string //.as_string (random.lower_case 1)]
                       ))]
                (all _.and
                     (_.coverage [/.export:]
                       (and (bit#= (//.of_boolean ..expected_boolean) (//.of_boolean (Primitives::actual_boolean)))
                            (int#= (//.of_byte ..expected_byte) (//.of_byte (Primitives::actual_byte)))
                            (int#= (//.of_short ..expected_short) (//.of_short (Primitives::actual_short)))
                            (int#= (//.of_int ..expected_int) (//.of_int (Primitives::actual_int)))
                            (int#= (//.of_long ..expected_long) (//.of_long (Primitives::actual_long)))
                            (int#= (//.of_char ..expected_char) (//.of_char (Primitives::actual_char)))
                            (frac#= (//.of_float ..expected_float) (//.of_float (Primitives::actual_float)))
                            (frac#= (//.of_double ..expected_double) (//.of_double (Primitives::actual_double)))

                            (~~ (template [<=> <+> <type>]
                                  [(with_expansions [<left> (template.symbol ["left_" <type>])
                                                     <right> (template.symbol ["right_" <type>])
                                                     <of> (template.symbol [//._] ["of_" <type>])
                                                     <method> (template.symbol ["Primitives::" <type> "_method"])]
                                     (<=> (<+> (<of> <left>) (<of> <right>))
                                          (<of> (<method> <left> <right>))))]

                                  [bit#= and boolean]
                                  [int#= int.+ byte]
                                  [int#= int.+ short]
                                  [int#= int.+ int]
                                  [int#= int.+ long]
                                  [int#= int.+ char]
                                  [frac#= frac.+ float]
                                  [frac#= frac.+ double]
                                  ))

                            (text#= (//.of_string ..expected_string) (//.of_string (Objects::actual_string)))
                            
                            (text#= (%.format (//.of_string left_string) (//.of_string right_string))
                                    (//.of_string (Objects::string_method left_string right_string)))

                            (text#= (//.of_string left_string)
                                    (//.of_string (Objects::left left_string right_string)))
                            (text#= (//.of_string right_string)
                                    (//.of_string (Objects::right left_string right_string)))
                            (int#= (//.of_long left_long)
                                   (//.of_long (Objects::left left_long right_long)))
                            (int#= (//.of_long right_long)
                                   (//.of_long (Objects::right left_long right_long)))
                            ))
                     ))))))