aboutsummaryrefslogtreecommitdiff
path: root/lux-jvm/test/test/luxc/lang/translation/jvm.lux
blob: 86c8253e427254917b72996ff7c7be5b4cf90394 (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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
(.module:
  lux
  (lux [io]
       (control pipe
                [monad {"+" [do]}]
                [maybe])
       (data ["e" error]
             [bit]
             [bit "bit/" Eq<Bit>]
             [number "int/" Number<Int> Codec<Text,Int>]
             [text "text/" Eq<Text>]
             text/format
             (coll [list]))
       ["r" math/random "r/" Monad<Random>]
       [macro]
       (macro [code])
       [host]
       test)
  (luxc [lang]
        (lang ["[0]L" host]
              ["ls" synthesis]
              (translation (jvm ["[0]T" expression]
                                ["[0]T" eval]
                                ["[0]T" runtime]))))
  (test/luxc common))

(context: "Conversions [Part 1]"
  (<| (times +100)
      (do @
        [int-sample (|> r.int (:: @ each (i/% 128)))
         #let [frac-sample (int-to-frac int-sample)]]
        (with-expansions [<2step> (template [<step1> <step2> <tag> <sample> <cast> <test>]
                                    [(test (format <step1> " / " <step2>)
                                           (|> (do macro.Monad<Meta>
                                                 [sampleI (expressionT.translate (|> (~ (<tag> <sample>)) <step1> <step2> (`)))]
                                                 (evalT.eval sampleI))
                                               (lang.with-current-module "")
                                               (macro.result (io.run! init-jvm))
                                               (case> {#e.Success valueT}
                                                      (<test> <sample> (:coerce <cast> valueT))

                                                      {#e.Error error}
                                                      #0)))]

                                    ["jvm convert double-to-float" "jvm convert float-to-double" code.frac frac-sample Frac f/=]
                                    ["jvm convert double-to-int"   "jvm convert int-to-double" code.frac frac-sample Frac f/=]
                                    ["jvm convert double-to-long"  "jvm convert long-to-double" code.frac frac-sample Frac f/=]

                                    ["jvm convert long-to-float" "jvm convert float-to-long" code.int int-sample Int i/=]
                                    ["jvm convert long-to-int" "jvm convert int-to-long" code.int int-sample Int i/=]
                                    ["jvm convert long-to-short" "jvm convert short-to-long" code.int int-sample Int i/=]
                                    ["jvm convert long-to-byte" "jvm convert byte-to-long" code.int int-sample Int i/=]
                                    )]
                         ($_ seq
                             <2step>
                             )))))

(context: "Conversions [Part 2]"
  (<| (times +100)
      (do @
        [int-sample (|> r.int (:: @ each (|>> (i/% 128) int/abs)))
         #let [frac-sample (int-to-frac int-sample)]]
        (`` ($_ seq
                (~~ (template [<step1> <step2> <step3> <tag> <sample> <cast> <test>]
                      [(test (format <step1> " / " <step2> " / " <step3>)
                             (|> (do macro.Monad<Meta>
                                   [sampleI (expressionT.translate (|> (~ (<tag> <sample>)) <step1> <step2> <step3> (`)))]
                                   (evalT.eval sampleI))
                                 (lang.with-current-module "")
                                 (macro.result (io.run! init-jvm))
                                 (case> {#e.Success valueT}
                                        (<test> <sample> (:coerce <cast> valueT))

                                        {#e.Error error}
                                        #0)))]

                      ["jvm convert long-to-int"   "jvm convert int-to-char"  "jvm convert char-to-long"  code.int int-sample Int i/=]
                      ["jvm convert long-to-int"   "jvm convert int-to-byte"  "jvm convert byte-to-long"  code.int int-sample Int i/=]
                      ["jvm convert long-to-int"   "jvm convert int-to-short" "jvm convert short-to-long" code.int int-sample Int i/=]
                      ["jvm convert long-to-float" "jvm convert float-to-int" "jvm convert int-to-long"   code.int int-sample Int i/=]
                      ["jvm convert long-to-int"   "jvm convert int-to-float" "jvm convert float-to-long" code.int int-sample Int i/=]
                      ))
                )))))

(context: "Conversions [Part 3]"
  (<| (times +100)
      (do @
        [int-sample (|> r.int (:: @ each (|>> (i/% 128) int/abs)))
         #let [frac-sample (int-to-frac int-sample)]]
        (`` ($_ seq
                (~~ (template [<step1> <step2> <step3> <step4> <tag> <sample> <cast> <test>]
                      [(test (format <step1> " / " <step2> " / " <step3>)
                             (|> (do macro.Monad<Meta>
                                   [sampleI (expressionT.translate (|> (~ (<tag> <sample>)) <step1> <step2> <step3> <step4> (`)))]
                                   (evalT.eval sampleI))
                                 (lang.with-current-module "")
                                 (macro.result (io.run! init-jvm))
                                 (case> {#e.Success valueT}
                                        (<test> <sample> (:coerce <cast> valueT))

                                        {#e.Error error}
                                        #0)))]

                      ["jvm convert long-to-int" "jvm convert int-to-char" "jvm convert char-to-byte" "jvm convert byte-to-long" code.int int-sample Int i/=]
                      ["jvm convert long-to-int" "jvm convert int-to-char" "jvm convert char-to-short" "jvm convert short-to-long" code.int int-sample Int i/=]
                      ["jvm convert long-to-int" "jvm convert int-to-char" "jvm convert char-to-int" "jvm convert int-to-long" code.int int-sample Int i/=]
                      ))
                )))))

(def: gen-nat
  (r.Random Nat)
  (|> r.nat
      (r/each (n/% +128))
      (r.filter (|>> (n/= +0) not))))

(def: gen-int
  (r.Random Int)
  (|> gen-nat (r/each nat-to-int)))

(def: gen-frac
  (r.Random Frac)
  (|> gen-int (r/each int-to-frac)))

(template [<domain> <generator> <tag> <type> <test> <augmentation> <+> <-> <*> </> <%> <pre> <post>]
  [(context: (format "Arithmetic [" <domain> "]")
     (<| (times +100)
         (do @
           [param <generator>
            #let [subject (<augmentation> param)]]
           (with-expansions [<tests> (template [<procedure> <reference>]
                                       [(test <procedure>
                                              (|> (do macro.Monad<Meta>
                                                    [sampleI (expressionT.translate (<post> ((code.text <procedure>)
                                                                                             (<pre> (<tag> subject))
                                                                                             (<pre> (<tag> param)))))]
                                                    (evalT.eval sampleI))
                                                  (lang.with-current-module "")
                                                  (macro.result (io.run! init-jvm))
                                                  (case> {#e.Success valueT}
                                                         (<test> (<reference> param subject)
                                                                 (:coerce <type> valueT))

                                                         {#e.Error error}
                                                         #0)))]

                                       [(format "jvm " <domain> " +") <+>]
                                       [(format "jvm " <domain> " -") <->]
                                       [(format "jvm " <domain> " *") <*>]
                                       [(format "jvm " <domain> " /") </>]
                                       [(format "jvm " <domain> " %") <%>]
                                       )]
                            ($_ seq
                                <tests>
                                )))))]

  ["int" gen-int code.int Int i/= (i/* 10) i/+ i/- i/* i// i/% "jvm convert long-to-int" "jvm convert int-to-long"]
  ["long" gen-int code.int Int i/= (i/* 10) i/+ i/- i/* i// i/% id id]
  ["float" gen-frac code.frac Frac f/= (f/* 10.0) f/+ f/- f/* f// f/% "jvm convert double-to-float" "jvm convert float-to-double"]
  ["double" gen-frac code.frac Frac f/= (f/* 10.0) f/+ f/- f/* f// f/% id id]
  )

(template [<domain> <post> <convert>]
  [(context: (format "Bit-wise [" <domain> "] { Combiners ]")
     (<| (times +100)
         (do @
           [param gen-nat
            subject gen-nat]
           (`` ($_ seq
                   (~~ (template [<procedure> <reference>]
                         [(test <procedure>
                                (|> (do macro.Monad<Meta>
                                      [sampleI (expressionT.translate (<post> ((code.text <procedure>)
                                                                               (<convert> (code.nat subject))
                                                                               (<convert> (code.nat param)))))]
                                      (evalT.eval sampleI))
                                    (lang.with-current-module "")
                                    (macro.result (io.run! init-jvm))
                                    (case> {#e.Success valueT}
                                           (n/= (<reference> param subject)
                                                (:coerce Nat valueT))

                                           {#e.Error error}
                                           #0)))]

                         [(format "jvm " <domain> " and") bit.and]
                         [(format "jvm " <domain> " or") bit.or]
                         [(format "jvm " <domain> " xor") bit.xor]
                         ))
                   )))))]

  ["int" "jvm convert int-to-long" "jvm convert long-to-int"]
  ["long" id id]
  )

(template [<domain> <post> <convert>]
  [(context: (format "Bit-wise [" <domain> "] { Shifters }")
     (<| (times +100)
         (do @
           [param gen-nat
            subject gen-nat
            #let [shift (n/% +10 param)]]
           (`` ($_ seq
                   (~~ (template [<procedure> <reference> <type> <test> <pre-subject> <pre>]
                         [(test <procedure>
                                (|> (do macro.Monad<Meta>
                                      [sampleI (expressionT.translate (<post> ((code.text <procedure>)
                                                                               (<convert> (<pre> subject))
                                                                               ("jvm convert long-to-int" (code.nat shift)))))]
                                      (evalT.eval sampleI))
                                    (lang.with-current-module "")
                                    (macro.result (io.run! init-jvm))
                                    (case> {#e.Success valueT}
                                           (<test> (<reference> shift (<pre-subject> subject))
                                                   (:coerce <type> valueT))

                                           {#e.Error error}
                                           #0)))]

                         [(format "jvm " <domain> " shl") bit.left-shift Nat n/= id code.nat]
                         [(format "jvm " <domain> " shr") bit.arithmetic-right-shift Int i/= nat-to-int (|>> nat-to-int code.int)]
                         [(format "jvm " <domain> " ushr") bit.logical-right-shift Nat n/= id code.nat]
                         ))
                   )))))]

  ["int" "jvm convert int-to-long" "jvm convert long-to-int"]
  ["long" id id]
  )

(template [<domain> <generator> <tag> <=> <<> <pre>]
  [(context: (format "Order [" <domain> "]")
     (<| (times +100)
         (do @
           [param <generator>
            subject <generator>]
           (with-expansions [<tests> (template [<procedure> <reference>]
                                       [(test <procedure>
                                              (|> (do macro.Monad<Meta>
                                                    [sampleI (expressionT.translate ((code.text <procedure>)
                                                                                     (<pre> (<tag> subject))
                                                                                     (<pre> (<tag> param))))]
                                                    (evalT.eval sampleI))
                                                  (lang.with-current-module "")
                                                  (macro.result (io.run! init-jvm))
                                                  (case> {#e.Success valueT}
                                                         (bit/= (<reference> param subject)
                                                                (:coerce Bit valueT))

                                                         {#e.Error error}
                                                         #0)))]

                                       [(format "jvm " <domain> " =") <=>]
                                       [(format "jvm " <domain> " <") <<>]
                                       )]
                            ($_ seq
                                <tests>
                                )))))]

  ["int" gen-int code.int i/= i/< "jvm convert long-to-int"]
  ["long" gen-int code.int i/= i/< id]
  ["float" gen-frac code.frac f/= f/< "jvm convert double-to-float"]
  ["double" gen-frac code.frac f/= f/< id]
  ["char" gen-int code.int i/= i/< "jvm convert long-to-char"]
  )

(def: (jvm//array//new dimension class size)
  (-> Nat Text Nat ls.Synthesis)
  (` ("jvm array new" (~ (code.nat dimension)) (~ (code.text class)) (~ (code.nat size)))))

(def: (jvm//array//write class idx inputS arrayS)
  (-> Text Nat ls.Synthesis ls.Synthesis ls.Synthesis)
  (` ("jvm array write" (~ (code.text class)) (~ (code.nat idx)) (~ inputS) (~ arrayS))))

(def: (jvm//array//read class idx arrayS)
  (-> Text Nat ls.Synthesis ls.Synthesis)
  (` ("jvm array read" (~ (code.text class)) (~ (code.nat idx)) (~ arrayS))))

(context: "Array [Part 1]"
  (<| (times +100)
      (do @
        [size (|> r.nat (:: @ each (|>> (n/% +10) (n/max +1))))
         idx (|> r.nat (:: @ each (n/% size)))
         valueZ r.bit
         valueB gen-int
         valueS gen-int
         valueI gen-int
         valueL r.int
         valueF gen-frac
         valueD r.frac
         valueC gen-int]
        (with-expansions [<array> (template [<class> <type> <value> <test> <input> <post>]
                                    [(test <class>
                                           (|> (do macro.Monad<Meta>
                                                 [sampleI (expressionT.translate (|> (jvm//array//new +0 <class> size)
                                                                                     (jvm//array//write <class> idx <input>)
                                                                                     (jvm//array//read <class> idx)
                                                                                     <post>))]
                                                 (evalT.eval sampleI))
                                               (lang.with-current-module "")
                                               (macro.result (io.run! init-jvm))
                                               (case> {#e.Success outputZ}
                                                      (<test> <value> (:coerce <type> outputZ))

                                                      {#e.Error error}
                                                      #0)))]

                                    ["boolean" Bit valueZ bit/= (code.bit valueZ)
                                     id]
                                    ["byte" Int valueB i/= (|> (code.int valueB) (~) "jvm convert long-to-byte" (`))
                                     "jvm convert byte-to-long"]
                                    ["short" Int valueS i/= (|> (code.int valueS) (~) "jvm convert long-to-short" (`))
                                     "jvm convert short-to-long"]
                                    ["int" Int valueI i/= (|> (code.int valueI) (~) "jvm convert long-to-int" (`))
                                     "jvm convert int-to-long"]
                                    ["long" Int valueL i/= (code.int valueL)
                                     id]
                                    ["float" Frac valueF f/= (|> (code.frac valueF) (~) "jvm convert double-to-float" (`))
                                     "jvm convert float-to-double"]
                                    ["double" Frac valueD f/= (code.frac valueD)
                                     id]
                                    )]
                         ($_ seq
                             <array>
                             )))))

(context: "Array [Part 2]"
  (<| (times +100)
      (do @
        [size (|> r.nat (:: @ each (|>> (n/% +10) (n/max +1))))
         idx (|> r.nat (:: @ each (n/% size)))
         valueZ r.bit
         valueB gen-int
         valueS gen-int
         valueI gen-int
         valueL r.int
         valueF gen-frac
         valueD r.frac
         valueC gen-int]
        (with-expansions [<array> (template [<class> <type> <value> <test> <input> <post>]
                                    [(test <class>
                                           (|> (do macro.Monad<Meta>
                                                 [sampleI (expressionT.translate (|> (jvm//array//new +0 <class> size)
                                                                                     (jvm//array//write <class> idx <input>)
                                                                                     (jvm//array//read <class> idx)
                                                                                     <post>))]
                                                 (evalT.eval sampleI))
                                               (lang.with-current-module "")
                                               (macro.result (io.run! init-jvm))
                                               (case> {#e.Success outputT}
                                                      (<test> <value> (:coerce <type> outputT))

                                                      {#e.Error error}
                                                      #0)))]

                                    ["char" Int valueC i/=
                                     (|> (code.int valueC) (~) "jvm convert long-to-int" "jvm convert int-to-char" (`))
                                     "jvm convert char-to-long"]
                                    ["java.lang.Long" Int valueL i/=
                                     (code.int valueL)
                                     id]
                                    )]
                         ($_ seq
                             <array>
                             (test "java.lang.Double (level 1)"
                                   (|> (do macro.Monad<Meta>
                                         [#let [inner (|> ("jvm array new" +0 "java.lang.Double" (~ (code.nat size)))
                                                          ("jvm array write" "java.lang.Double" (~ (code.nat idx)) (~ (code.frac valueD)))
                                                          (`))]
                                          sampleI (expressionT.translate (|> ("jvm array new" +1 "java.lang.Double" (~ (code.nat size)))
                                                                             ("jvm array write" "#Array" (~ (code.nat idx)) (~ inner))
                                                                             ("jvm array read" "#Array" (~ (code.nat idx)))
                                                                             ("jvm array read" "java.lang.Double" (~ (code.nat idx)))
                                                                             (`)))]
                                         (evalT.eval sampleI))
                                       (lang.with-current-module "")
                                       (macro.result (io.run! init-jvm))
                                       (case> {#e.Success outputT}
                                              (f/= valueD (:coerce Frac outputT))

                                              {#e.Error error}
                                              #0)))
                             (test "jvm array length"
                                   (|> (do macro.Monad<Meta>
                                         [sampleI (expressionT.translate (` ("jvm array length" ("jvm array new" +0 "java.lang.Object" (~ (code.nat size))))))]
                                         (evalT.eval sampleI))
                                       (lang.with-current-module "")
                                       (macro.result (io.run! init-jvm))
                                       (case> {#e.Success outputT}
                                              (n/= size (:coerce Nat outputT))

                                              {#e.Error error}
                                              #0)))
                             )))))

(host.import: java/lang/Class
  (getName [] String))

(def: classes
  (List Text)
  (list "java.lang.Object" "java.lang.Class"
        "java.lang.String" "java.lang.Number"))

(def: instances
  (List [Text (r.Random ls.Synthesis)])
  (let [gen-boolean (|> r.bit (:: r.Functor<Random> each code.bit))
        gen-integer (|> r.int (:: r.Functor<Random> each code.int))
        gen-double (|> r.frac (:: r.Functor<Random> each code.frac))
        gen-string (|> (r.text +5) (:: r.Functor<Random> each code.text))]
    (list ["java.lang.Boolean" gen-boolean]
          ["java.lang.Long" gen-integer]
          ["java.lang.Double" gen-double]
          ["java.lang.String" gen-string]
          ["java.lang.Object" (r.either (r.either gen-boolean
                                                  gen-integer)
                                        (r.either gen-double
                                                  gen-string))])))

(context: "Object."
  (<| (times +100)
      (do @
        [#let [num-classes (list.size classes)]
         #let [num-instances (list.size instances)]
         class-idx (|> r.nat (:: @ each (n/% num-classes)))
         instance-idx (|> r.nat (:: @ each (n/% num-instances)))
         exception-message (r.text +5)
         #let [class (maybe.trusted (list.nth class-idx classes))
               [instance-class instance-gen] (maybe.trusted (list.nth instance-idx instances))
               exception-message$ (` ["java.lang.String" (~ (code.text exception-message))])]
         sample r.int
         monitor r.int
         instance instance-gen]
        ($_ seq
            (test "jvm object null"
                  (|> (do macro.Monad<Meta>
                        [sampleI (expressionT.translate (` ("jvm object null?" ("jvm object null"))))]
                        (evalT.eval sampleI))
                      (lang.with-current-module "")
                      (macro.result (io.run! init-jvm))
                      (case> {#e.Success outputT}
                             (:coerce Bit outputT)

                             {#e.Error error}
                             #0)))
            (test "jvm object null?"
                  (|> (do macro.Monad<Meta>
                        [sampleI (expressionT.translate (` ("jvm object null?" (~ (code.int sample)))))]
                        (evalT.eval sampleI))
                      (lang.with-current-module "")
                      (macro.result (io.run! init-jvm))
                      (case> {#e.Success outputT}
                             (not (:coerce Bit outputT))

                             {#e.Error error}
                             #0)))
            (test "jvm object synchronized"
                  (|> (do macro.Monad<Meta>
                        [sampleI (expressionT.translate (` ("jvm object synchronized" (~ (code.int monitor)) (~ (code.int sample)))))]
                        (evalT.eval sampleI))
                      (lang.with-current-module "")
                      (macro.result (io.run! init-jvm))
                      (case> {#e.Success outputT}
                             (i/= sample (:coerce Int outputT))

                             {#e.Error error}
                             #0)))
            (test "jvm object throw"
                  (|> (do macro.Monad<Meta>
                        [_ runtimeT.translate
                         sampleI (expressionT.translate (` ("lux try" ("lux function" +1 []
                                                                       ("jvm object throw" ("jvm member invoke constructor"
                                                                                            "java.lang.Throwable"
                                                                                            (~ exception-message$)))))))]
                        (evalT.eval sampleI))
                      (lang.with-current-module "")
                      (macro.result (io.run! init-jvm))
                      (case> {#e.Success outputT}
                             (case (:coerce (e.Error Any) outputT)
                               {#e.Error error}
                               (text.contains? exception-message error)

                               {#e.Success outputT}
                               #0)

                             {#e.Error error}
                             #0)))
            (test "jvm object class"
                  (|> (do macro.Monad<Meta>
                        [sampleI (expressionT.translate (` ("jvm object class" (~ (code.text class)))))]
                        (evalT.eval sampleI))
                      (lang.with-current-module "")
                      (macro.result (io.run! init-jvm))
                      (case> {#e.Success outputT}
                             (|> outputT (:coerce Class) (Class::getName []) (text/= class))

                             {#e.Error error}
                             #0)))
            (test "jvm object instance?"
                  (|> (do macro.Monad<Meta>
                        [sampleI (expressionT.translate (` ("jvm object instance?" (~ (code.text instance-class)) (~ instance))))]
                        (evalT.eval sampleI))
                      (lang.with-current-module "")
                      (macro.result (io.run! init-jvm))
                      (case> {#e.Success outputT}
                             (:coerce Bit outputT)

                             {#e.Error error}
                             #0)))
            ))))

(host.import: java/util/GregorianCalendar
  ("static" AD int))

(context: "Member [Field]"
  (<| (times +100)
      (do @
        [sample-short (|> r.int (:: @ each (|>> int/abs (i/% 100))))
         sample-string (r.text +5)
         other-sample-string (r.text +5)
         #let [shortS (` ["short" ("jvm object cast" "java.lang.Short" "short"
                                   ("jvm convert long-to-short" (~ (code.int sample-short))))])
               stringS (` ["java.lang.String" (~ (code.text sample-string))])
               type-codeS (` ["org.omg.CORBA.TypeCode" ("jvm object null")])
               idl-typeS (` ["org.omg.CORBA.IDLType" ("jvm object null")])
               value-memberS (` ("jvm member invoke constructor"
                                 "org.omg.CORBA.ValueMember"
                                 (~ stringS) (~ stringS) (~ stringS) (~ stringS)
                                 (~ type-codeS) (~ idl-typeS) (~ shortS)))]]
        ($_ seq
            (test "jvm member static get"
                  (|> (do macro.Monad<Meta>
                        [sampleI (expressionT.translate (` ("jvm convert int-to-long" ("jvm member static get" "java.util.GregorianCalendar" "AD" "int"))))]
                        (evalT.eval sampleI))
                      (lang.with-current-module "")
                      (macro.result (io.run! init-jvm))
                      (case> {#e.Success outputT}
                             (i/= GregorianCalendar::AD (:coerce Int outputT))

                             {#e.Error error}
                             #0)))
            (test "jvm member static put"
                  (|> (do macro.Monad<Meta>
                        [sampleI (expressionT.translate (` ("jvm member static put" "java.awt.datatransfer.DataFlavor" "allHtmlFlavor" "java.awt.datatransfer.DataFlavor"
                                                            ("jvm member static get" "java.awt.datatransfer.DataFlavor" "allHtmlFlavor" "java.awt.datatransfer.DataFlavor"))))]
                        (evalT.eval sampleI))
                      (lang.with-current-module "")
                      (macro.result (io.run! init-jvm))
                      (case> {#e.Success outputT}
                             (same? hostL.unit (:coerce Text outputT))

                             {#e.Error error}
                             #0)))
            (test "jvm member virtual get"
                  (|> (do macro.Monad<Meta>
                        [sampleI (expressionT.translate (` ("jvm member virtual get" "org.omg.CORBA.ValueMember" "name" "java.lang.String" (~ value-memberS))))]
                        (evalT.eval sampleI))
                      (lang.with-current-module "")
                      (macro.result (io.run! init-jvm))
                      (case> {#e.Success outputT}
                             (text/= sample-string (:coerce Text outputT))

                             {#e.Error error}
                             #0)))
            (test "jvm member virtual put"
                  (|> (do macro.Monad<Meta>
                        [sampleI (expressionT.translate (` ("jvm member virtual get" "org.omg.CORBA.ValueMember" "name" "java.lang.String"
                                                            ("jvm member virtual put" "org.omg.CORBA.ValueMember" "name" "java.lang.String"
                                                             (~ (code.text other-sample-string)) (~ value-memberS)))))]
                        (evalT.eval sampleI))
                      (lang.with-current-module "")
                      (macro.result (io.run! init-jvm))
                      (case> {#e.Success outputT}
                             (text/= other-sample-string (:coerce Text outputT))

                             {#e.Error error}
                             #0)))
            ))))

(host.import: java/lang/Object)

(host.import: (java/util/ArrayList a))

(context: "Member [Method]"
  (<| (times +100)
      (do @
        [sample (|> r.int (:: @ each (|>> int/abs (i/% 100))))
         #let [object-longS (` ["java.lang.Object" (~ (code.int sample))])
               intS (` ["int" ("jvm object cast" "java.lang.Integer" "int"
                               ("jvm convert long-to-int" (~ (code.int sample))))])
               coded-intS (` ["java.lang.String" (~ (code.text (int/encode sample)))])
               array-listS (` ("jvm member invoke constructor" "java.util.ArrayList" (~ intS)))]]
        ($_ seq
            (test "jvm member invoke static"
                  (|> (do macro.Monad<Meta>
                        [sampleI (expressionT.translate (` ("jvm member invoke static" "java.lang.Long"
                                                            "decode" "java.lang.Long"
                                                            (~ coded-intS))))]
                        (evalT.eval sampleI))
                      (lang.with-current-module "")
                      (macro.result (io.run! init-jvm))
                      (case> {#e.Success outputT}
                             (i/= sample (:coerce Int outputT))

                             {#e.Error error}
                             #0)))
            (test "jvm member invoke virtual"
                  (|> (do macro.Monad<Meta>
                        [sampleI (expressionT.translate (` ("jvm object cast" "boolean" "java.lang.Boolean"
                                                            ("jvm member invoke virtual" "java.lang.Object" "equals" "boolean"
                                                             (~ (code.int sample)) (~ object-longS)))))]
                        (evalT.eval sampleI))
                      (lang.with-current-module "")
                      (macro.result (io.run! init-jvm))
                      (case> {#e.Success outputT}
                             (:coerce Bit outputT)

                             {#e.Error error}
                             #0)))
            (test "jvm member invoke interface"
                  (|> (do macro.Monad<Meta>
                        [sampleI (expressionT.translate (` ("jvm object cast" "boolean" "java.lang.Boolean"
                                                            ("jvm member invoke interface" "java.util.Collection" "add" "boolean"
                                                             (~ array-listS) (~ object-longS)))))]
                        (evalT.eval sampleI))
                      (lang.with-current-module "")
                      (macro.result (io.run! init-jvm))
                      (case> {#e.Success outputT}
                             (:coerce Bit outputT)

                             {#e.Error error}
                             #0)))
            (test "jvm member invoke constructor"
                  (|> (do macro.Monad<Meta>
                        [sampleI (expressionT.translate array-listS)]
                        (evalT.eval sampleI))
                      (lang.with-current-module "")
                      (macro.result (io.run! init-jvm))
                      (case> {#e.Success outputT}
                             (host.instance? ArrayList (:coerce Object outputT))

                             {#e.Error error}
                             #0)))
            ))))