ahk 0.6.2

The ahk language: a lexer, an AST, a parser and an interpreter for AutoHotkey-style scripts
Documentation
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
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
//! The base object, and the class value that is the class of the dialect.
//!
//! Measured on the binary of v2.0.19: the base of an object
//! is the prototype of its class, the base of a class is the class that it
//! extends, the copy of a class is a class of its own, and the call of a
//! class value makes an object of the class.

use ahk::desktop::{
    Clipboard, Com, Desktop, Dialogs, Files, Hotkeys, Keyboard, Machine, Native, Network, Pictures,
    Pointer, Processes, Screen, Sound, Timers, Windows,
};
use ahk::parse;
use ahk::runtime::{Report, Runtime};
use std::time::Duration;

/// A desktop that does nothing.
#[derive(Debug, Default)]
struct Fake;

impl Desktop for Fake {}
impl Pictures for Fake {}
impl Network for Fake {}
impl Sound for Fake {}
impl Machine for Fake {}
impl Dialogs for Fake {}

impl Files for Fake {}

impl Clipboard for Fake {}

impl Timers for Fake {}

impl Hotkeys for Fake {}

impl Keyboard for Fake {
    fn type_text(&mut self, _text: &str) -> Result<String, String> {
        Ok(String::new())
    }
    fn press_key(&mut self, _name: &str, _modifiers: &[String]) -> Result<String, String> {
        Ok(String::new())
    }
}

impl Pointer for Fake {
    fn click(&mut self, _x: i64, _y: i64, _button: &str, _count: u32) -> Result<String, String> {
        Ok(String::new())
    }
}

impl Screen for Fake {
    fn capture(
        &mut self,
        _x: i64,
        _y: i64,
        _width: i64,
        _height: i64,
        _filename: &str,
    ) -> Result<String, String> {
        Ok(String::new())
    }
    fn pixel(&mut self, _x: i64, _y: i64) -> Result<String, String> {
        Ok("#000000".into())
    }
}

impl Windows for Fake {}

impl Processes for Fake {
    fn run(&mut self, _command: &str, _window: &str) -> Result<(i32, String, String), String> {
        Ok((0, String::new(), String::new()))
    }
}

impl Native for Fake {}
impl Com for Fake {}

/// A script, and the report of it.
fn run(source: &str) -> Report {
    let mut desktop = Fake;
    let statements = parse(source).expect("parses");
    Runtime::new(&mut desktop, Duration::from_secs(10)).run(&statements)
}

/// The value that a script leaves behind.
fn the_answer_of(source: &str) -> String {
    let report = run(source);
    assert!(report.ok, "{:?}", report.error);
    report.output.first().cloned().unwrap_or_default()
}

/// The failure of a script: the message, the `What` and the `Extra`.
fn the_failure_of(source: &str) -> String {
    let report = run(&format!(
        "try {{\n    {source}\n}} catch Any as e {{\n    MsgBox e.Message \" | \" e.What \" | \" e.Extra\n}}\n"
    ));
    assert!(report.ok, "{:?}", report.error);
    report
        .output
        .first()
        .cloned()
        .unwrap_or_default()
        .trim()
        .to_string()
}

/// The failure of the load of a script: the message of it.
///
/// A load error is not catchable, and it is not a failure of the run: it
/// is the refusal of the script itself.
fn the_load_failure_of(source: &str) -> String {
    parse(source).expect_err("does not parse").message
}

#[test]
fn the_base_of_an_object_is_the_prototype_of_its_class() {
    // Measured on the binary of v2.0.19.
    assert_eq!(
        the_answer_of("o := Object()\nMsgBox o.Base.__Class"),
        "Object"
    );
    assert_eq!(
        the_answer_of("c := Map\nMsgBox c.Prototype.Base.__Class"),
        "Object"
    );
}

#[test]
fn the_base_of_a_class_is_the_class_that_it_extends() {
    // Measured on the binary of v2.0.19: the base of the
    // `Map` is the `Object`, and the base of the `Object` is the `Any`.
    assert_eq!(the_answer_of("c := Map\nMsgBox c.Base.__Class"), "Class");
    assert_eq!(the_answer_of("c := Object\nMsgBox c.Base.__Class"), "Class");
}

#[test]
fn the_copy_of_an_object_carries_the_state_of_it() {
    // Measured on the binary of v2.0.19.
    assert_eq!(
        the_answer_of("o := Object()\no.x := 1\nMsgBox o.Clone().x"),
        "1"
    );
}

#[test]
fn the_copy_of_a_class_is_a_class() {
    // Measured on the binary of v2.0.19: the copy of a
    // class is a class, and not an object of it.
    assert_eq!(the_answer_of("c := Map\nMsgBox c.Clone().__Class"), "Class");
}

#[test]
fn the_call_of_a_class_value_makes_an_object() {
    // Measured on the binary of v2.0.19: `c.Call()` makes
    // an object of the class, the way `c()` does.
    assert_eq!(the_answer_of("c := Map\nMsgBox c.Call().__Class"), "Map");
    assert_eq!(
        the_answer_of("c := Error\nMsgBox c.Call().__Class"),
        "Error"
    );
}

#[test]
fn the_static_methods_of_a_class_are_handed_over_as_values() {
    // Measured on the binary of v2.0.19: every class has
    // the methods of the base object as static ones, and the call of the
    // class is one of them.
    assert_eq!(
        the_answer_of("c := Map\nf := c.GetMethod(\"HasProp\")\nMsgBox f.Name"),
        "HasProp"
    );
    assert_eq!(
        the_answer_of("c := Map\nf := c.GetMethod(\"OwnProps\")\nMsgBox f.Name"),
        "Object.Prototype.OwnProps"
    );
    assert_eq!(
        the_answer_of("c := Map\nf := c.GetMethod(\"Call\")\nMsgBox f.Name"),
        "Map.Call"
    );
    // The object is one of the arguments of the call.
    assert_eq!(
        the_answer_of(
            "c := Map\nf := c.GetMethod(\"HasProp\")\nMsgBox f.MinParams \" \" f.MaxParams"
        ),
        "2 2"
    );
    assert_eq!(
        the_answer_of("c := Map\nf := c.GetMethod(\"HasProp\")\nMsgBox f(Map(), \"x\")"),
        "0"
    );
    assert_eq!(
        the_answer_of("c := Map\nf := c.GetMethod(\"Call\")\nMsgBox f(c).__Class"),
        "Map"
    );
    assert_eq!(
        the_answer_of("c := Map\nf := c.GetMethod(\"Clone\")\nMsgBox f(Object()).__Class"),
        "Object"
    );
}

#[test]
fn the_method_a_class_does_not_have_is_refused_with_the_words_of_the_dialect() {
    // Measured on the binary of v2.0.19.
    assert_eq!(
        the_failure_of("c := Map\nf := c.GetMethod(\"Get\")"),
        "This value of type \"Class\" has no method named \"Get\". | GetMethod |"
    );
}

#[test]
fn the_copy_of_the_base_object_refuses_a_class_that_has_a_copy_of_its_own() {
    // Measured on the binary of v2.0.19: the type of the
    // argument is not the one that is wanted.
    assert_eq!(
        the_failure_of("c := Map\nf := c.GetMethod(\"Clone\")\nf(Map())"),
        "Type mismatch. | Object.Prototype.Clone |"
    );
}

#[test]
fn a_class_value_has_no_name() {
    // Measured on the binary of v2.0.19: a class value has
    // no property named `Name`, and the read of it is refused with the
    // words of the dialect.
    assert_eq!(
        the_failure_of("c := Map\nx := c.Name"),
        "This value of type \"Class\" has no property named \"Name\". |  |"
    );
    assert_eq!(
        the_failure_of("class C {\n}\nx := C.Name"),
        "This value of type \"Class\" has no property named \"Name\". |  |"
    );
}

#[test]
fn a_name_that_a_script_writes_is_a_property_of_the_class_value() {
    // Measured on the binary of v2.0.19: the write makes an
    // own property of the class value, and the class keeps its identity.
    assert_eq!(
        the_answer_of("c := Map\nc.Name := \"x\"\nMsgBox c.Name"),
        "x"
    );
    assert_eq!(
        the_answer_of("c := Map\nc.Name := \"x\"\nMsgBox c.HasOwnProp(\"Name\")"),
        "1"
    );
    assert_eq!(
        the_answer_of("c := Map\nMsgBox c.HasOwnProp(\"Name\")"),
        "0"
    );
    assert_eq!(
        the_answer_of("c := Map\nc.Name := \"x\"\nMsgBox c.__Class"),
        "Class"
    );
    assert_eq!(
        the_answer_of("c := Map\nc.Name := \"x\"\nMsgBox c.Base.__Class"),
        "Class"
    );
    assert_eq!(
        the_answer_of("c := Map\nc.Name := \"x\"\nMsgBox c.Prototype.__Class"),
        "Map"
    );
}

#[test]
fn a_prototype_has_no_name() {
    // Measured on the binary of v2.0.19: the prototype of a
    // class has no name either, and the write of one is a property of the
    // prototype.
    assert_eq!(
        the_failure_of("c := Map\nx := c.Prototype.Name"),
        "This value of type \"Prototype\" has no property named \"Name\". |  |"
    );
    assert_eq!(
        the_answer_of("c := Map\nc.Prototype.Name := \"x\"\nMsgBox c.Prototype.Name"),
        "x"
    );
    assert_eq!(
        the_answer_of("c := Map\nc.Prototype.Name := \"x\"\nMsgBox c.Prototype.__Class"),
        "Map"
    );
}

#[test]
fn the_base_of_a_class_is_written_the_way_objsetbase_writes_it() {
    // Measured on the binary of v2.0.19: the value has to be
    // an object, and the base of the class becomes it.
    assert_eq!(
        the_failure_of("c := Map\nc.Base := 1"),
        "Expected an Object but got an Integer. | ObjSetBase | 1"
    );
    assert_eq!(
        the_failure_of("class C {\n}\nC.Base := 1"),
        "Expected an Object but got an Integer. | ObjSetBase | 1"
    );
    assert_eq!(
        the_answer_of("c := Map\nc.Base := Object()\nMsgBox c.Base.__Class"),
        "Object"
    );
    assert_eq!(
        the_answer_of("c := Map\nc.Base := Object()\nMsgBox c.HasBase(Object)"),
        "0"
    );
}

#[test]
fn the_prototype_of_a_class_is_written_by_a_script() {
    // Measured on the binary of v2.0.19: the prototype of a
    // class is a property that a script may write.
    assert_eq!(
        the_answer_of("c := Map\nc.Prototype := 1\nMsgBox c.Prototype"),
        "1"
    );
    assert_eq!(
        the_answer_of("class C {\n}\nC.Prototype := 1\nMsgBox C.Prototype"),
        "1"
    );
}

#[test]
fn the_static_methods_of_a_class_are_read_only() {
    // Measured on the binary of v2.0.19: the static methods
    // of a class are read-only, and the name that is written is in the
    // `Extra` of the failure.
    assert_eq!(
        the_failure_of("c := Map\nc.HasProp := 1"),
        "Property is read-only. |  | HasProp"
    );
}

#[test]
fn the_properties_of_a_class_do_not_answer_a_class_value() {
    // Measured on the binary of v2.0.19: a class value is not
    // an instance of its class, and the properties of the class do not
    // answer it.
    assert_eq!(
        the_failure_of("c := Map\nx := c.Count"),
        "This value of type \"Class\" has no property named \"Count\". |  |"
    );
    assert_eq!(
        the_failure_of("c := Map\nx := c.Clear"),
        "This value of type \"Class\" has no property named \"Clear\". |  |"
    );
}

#[test]
fn the_base_of_a_class_of_the_script_is_the_class_that_it_extends() {
    // Measured on the binary of v2.0.19: the base of a class
    // of the script is the class that it extends, and the chain of the
    // bases of a class is the chain of the classes it extends.
    assert_eq!(
        the_answer_of("class D {\n}\nclass C extends D {\n}\nx := (C.Base == D)\nMsgBox x"),
        "1"
    );
    assert_eq!(
        the_answer_of("class C {\n}\nMsgBox C.Base.__Class"),
        "Class"
    );
    assert_eq!(
        the_answer_of("class D {\n}\nclass C extends D {\n}\nMsgBox C.HasBase(D)"),
        "1"
    );
    assert_eq!(the_answer_of("class C {\n}\nMsgBox C.HasBase(Object)"), "1");
    assert_eq!(
        the_answer_of(
            "class D {\n}\nclass C extends D {\n}\nC.Base := Object()\nMsgBox C.HasBase(D)"
        ),
        "0"
    );
}

#[test]
fn two_objects_are_the_same_object_and_nothing_else() {
    // Measured on the binary of v2.0.19: the objects are
    // compared by their identity, and an object is never equal to a value
    // that is not an object.
    assert_eq!(
        the_answer_of("m1 := Map()\nm2 := Map()\nMsgBox m1 == m2"),
        "0"
    );
    assert_eq!(the_answer_of("m1 := Map()\nMsgBox m1 == m1"), "1");
    assert_eq!(the_answer_of("m := Map()\nMsgBox m == Map"), "0");
    assert_eq!(the_answer_of("c := Map\nMsgBox c == Map"), "1");
    assert_eq!(the_answer_of("m := Map()\nMsgBox m == \"map\""), "0");
    assert_eq!(
        the_answer_of("m1 := Map()\nm2 := Map()\nMsgBox m1 != m2"),
        "1"
    );
}

#[test]
fn the_static_methods_of_a_class_value_are_handed_over_as_values() {
    // Measured on the binary of v2.0.19: the static methods
    // of a class are its own properties, and v2 hands them over as
    // functions.
    assert_eq!(
        the_answer_of("c := Map\nx := c.Call\nMsgBox x.Name"),
        "Map.Call"
    );
    assert_eq!(
        the_answer_of("c := Map\nx := c.HasProp\nMsgBox x.Name"),
        "HasProp"
    );
    assert_eq!(
        the_answer_of("class C {\n    static Say() {\n    }\n}\nx := C.Say\nMsgBox x.Name"),
        "C.Say"
    );
    // The methods of the instances are not the methods of the class.
    assert_eq!(
        the_failure_of("c := Map\nx := c.Clear"),
        "This value of type \"Class\" has no property named \"Clear\". |  |"
    );
}

#[test]
fn a_class_value_has_the_static_methods_and_not_the_others() {
    // Measured on the binary of v2.0.19: the methods of the
    // instances of a class do not answer a class value, and the static
    // methods of a class of the script are its own.
    assert_eq!(
        the_answer_of("c := Map\nMsgBox c.HasMethod(\"Clear\")"),
        "0"
    );
    assert_eq!(
        the_answer_of("c := Map\nMsgBox c.HasMethod(\"HasProp\")"),
        "1"
    );
    assert_eq!(the_answer_of("c := Map\nMsgBox c.HasMethod(\"Call\")"), "1");
    assert_eq!(
        the_answer_of("class C {\n    static Say() {\n    }\n}\nMsgBox C.HasMethod(\"Say\")"),
        "1"
    );
    assert_eq!(
        the_answer_of("class C {\n    Say() {\n    }\n}\nMsgBox C.HasMethod(\"Say\")"),
        "0"
    );
    // The static methods are properties of the class as well.
    assert_eq!(the_answer_of("c := Map\nMsgBox c.HasProp(\"Call\")"), "1");
    assert_eq!(
        the_answer_of("c := Map\nMsgBox c.HasProp(\"HasProp\")"),
        "1"
    );
    assert_eq!(the_answer_of("c := Map\nMsgBox c.HasProp(\"Base\")"), "1");
    assert_eq!(the_answer_of("c := Map\nMsgBox c.HasProp(\"Clear\")"), "0");
}

#[test]
fn the_own_properties_of_a_class_value_are_the_call_and_the_prototype() {
    // Measured on the binary of v2.0.19: the call of a class
    // is its own property, and the methods of the base object are
    // inherited and not own.
    assert_eq!(
        the_answer_of("c := Map\nMsgBox c.HasOwnProp(\"Call\")"),
        "1"
    );
    assert_eq!(
        the_answer_of("c := Map\nMsgBox c.HasOwnProp(\"HasProp\")"),
        "0"
    );
    assert_eq!(
        the_answer_of("c := Map\nMsgBox c.HasOwnProp(\"Prototype\")"),
        "1"
    );
    assert_eq!(
        the_answer_of("class C {\n    static Say() {\n    }\n}\nMsgBox C.HasOwnProp(\"Say\")"),
        "1"
    );
}

#[test]
fn the_write_of_a_static_method_of_a_class_is_refused() {
    // Measured on the binary of v2.0.19: the static methods
    // of a class are read-only.
    assert_eq!(
        the_failure_of("class C {\n    static Say() {\n    }\n}\nC.Say := 1"),
        "Property is read-only. |  | Say"
    );
    // The methods of the instances are not the methods of the class, and a
    // script may write a property with that name.
    assert_eq!(
        the_answer_of("class C {\n    Say() {\n    }\n}\nC.Say := 1\nMsgBox C.Say"),
        "1"
    );
}

#[test]
fn the_methods_of_the_instances_do_not_answer_a_class_value() {
    // Measured on the binary of v2.0.19: a class value is
    // not an instance of its class.
    assert_eq!(
        the_failure_of("c := Map\nc.Get(\"a\")"),
        "This value of type \"Class\" has no method named \"Get\". |  |"
    );
    assert_eq!(
        the_failure_of("c := Map\nc.Clear()"),
        "This value of type \"Class\" has no method named \"Clear\". |  |"
    );
    assert_eq!(
        the_failure_of("class C {\n    Say() {\n    }\n}\nC.Say()"),
        "This value of type \"Class\" has no method named \"Say\". |  |"
    );
}

#[test]
fn every_class_has_an_initialiser_and_it_is_a_member_of_the_class_value() {
    // Measured on the binary of v2.0.19: the initialiser of a
    // class is a member of the class value, and the name of it is empty for
    // a class of the runtime and "C.__Init" for a class of the script.
    assert_eq!(the_answer_of("x := Map\ny := x.__Init\nMsgBox y.Name"), "");
    assert_eq!(
        the_answer_of("x := Map\ny := x.__Init\nMsgBox y.MinParams"),
        "1"
    );
    assert_eq!(
        the_answer_of("x := Map\ny := x.__Init\nMsgBox y.MaxParams"),
        "1"
    );
    assert_eq!(
        the_answer_of("x := Map\ny := x.__Init\nMsgBox y.IsBuiltin"),
        "1"
    );
    assert_eq!(
        the_answer_of("class C {\n}\ny := C.__Init\nMsgBox y.Name"),
        "C.__Init"
    );
    assert_eq!(
        the_answer_of("class C {\n}\ny := C.__Init\nMsgBox y.IsBuiltin"),
        "0"
    );
}

#[test]
fn the_own_properties_of_a_class_value_are_the_ones_of_v2() {
    // Measured on the binary of v2.0.19: the class value of a
    // class of the runtime owns the call of the class and the prototype, and
    // the class value of a class of the script owns the initialiser of the
    // class, the prototype and the static methods that the class declares.
    assert_eq!(
        the_answer_of("c := Map\ns := \"\"\nfor p in c.OwnProps()\n    s .= p\nMsgBox s"),
        "CallPrototype"
    );
    assert_eq!(
        the_answer_of(
            "class C {\n    static Say() {\n    }\n}\ns := \"\"\nfor p in C.OwnProps()\n    s .= p\nMsgBox s"
        ),
        "__InitPrototypeSay"
    );
    assert_eq!(
        the_answer_of("class C {\n}\ns := \"\"\nfor p in C.OwnProps()\n    s .= p\nMsgBox s"),
        "__InitPrototype"
    );
    // The methods of the instances are not the ones of the class.
    assert_eq!(
        the_answer_of(
            "class C {\n    Say() {\n    }\n}\ns := \"\"\nfor p in C.OwnProps()\n    s .= p\nMsgBox s"
        ),
        "__InitPrototype"
    );
}

#[test]
fn the_methods_of_the_base_object_are_inherited_and_not_own() {
    // Measured on the binary of v2.0.19: the call of a class
    // of the script is not own, and the initialiser of a class of the
    // runtime is not own either.
    assert_eq!(
        the_answer_of("c := Map\nMsgBox c.HasOwnProp(\"Call\")"),
        "1"
    );
    assert_eq!(
        the_answer_of("c := Map\nMsgBox c.HasOwnProp(\"__Init\")"),
        "0"
    );
    assert_eq!(
        the_answer_of("c := Map\nMsgBox c.HasOwnProp(\"Prototype\")"),
        "1"
    );
    assert_eq!(
        the_answer_of("class C {\n}\nMsgBox C.HasOwnProp(\"Call\")"),
        "0"
    );
    assert_eq!(
        the_answer_of("class C {\n}\nMsgBox C.HasOwnProp(\"__Init\")"),
        "1"
    );
    assert_eq!(
        the_answer_of("class C {\n    Say() {\n    }\n}\nMsgBox C.HasOwnProp(\"Say\")"),
        "0"
    );
    assert_eq!(
        the_answer_of("class C {\n    static Say() {\n    }\n}\nMsgBox C.HasOwnProp(\"Say\")"),
        "1"
    );
}

#[test]
fn the_properties_of_a_class_are_assigned_after_the_body_of_its_init() {
    // Measured on the binary of v2.0.19: the properties of a
    // class that has an `__Init` of its own are assigned after the body of
    // it, and not before it -- the body may write them, and the assignment
    // of the class is the one that is left.
    assert_eq!(
        the_answer_of(
            "class C {\n    __Init() {\n        this.value := 2\n    }\n    value := 1\n}\nobj := C()\nMsgBox obj.value"
        ),
        "1"
    );
    // The properties that come before the `__Init` are a duplicate of it,
    // and the ones that come after it are taken.
    assert_eq!(
        the_answer_of(
            "class C {\n    __Init() {\n    }\n    value := 1\n}\nobj := C()\nMsgBox obj.value"
        ),
        "1"
    );
    // The properties of the base are not assigned when the derived has an
    // `__Init` of its own.
    assert_eq!(
        the_answer_of(
            "class D {\n    dvalue := 1\n}\nclass C extends D {\n    __Init() {\n    }\n    cvalue := 2\n}\nobj := C()\nMsgBox obj.cvalue"
        ),
        "2"
    );
}

#[test]
fn the_names_of_the_own_properties_are_the_ones_that_the_script_wrote() {
    // Measured on the binary of v2.0.19: the name of an own
    // property is the name as the script wrote it.
    assert_eq!(
        the_answer_of(
            "o := Object()\no.X := 1\ns := \"\"\nfor p in o.OwnProps()\n    s .= p\nMsgBox s"
        ),
        "X"
    );
    assert_eq!(
        the_answer_of("o := {X: 1}\ns := \"\"\nfor p in o.OwnProps()\n    s .= p\nMsgBox s"),
        "X"
    );
    assert_eq!(
        the_answer_of(
            "m := Map()\nm.X := 1\ns := \"\"\nfor p in m.OwnProps()\n    s .= p\nMsgBox s"
        ),
        "X"
    );
    assert_eq!(
        the_answer_of(
            "class C {\n}\nobj := C()\nobj.X := 1\ns := \"\"\nfor p in obj.OwnProps()\n    s .= p\nMsgBox s"
        ),
        "X"
    );
}

#[test]
fn the_first_write_of_a_property_is_the_one_that_fixes_the_case_of_it() {
    // Measured on the binary of v2.0.19: the names of a class
    // are the names in lower case, and the first write is the one that fixes
    // the case of the name.
    assert_eq!(
        the_answer_of(
            "o := Object()\no.X := 1\no.x := 2\ns := \"\"\nfor p in o.OwnProps()\n    s .= p\nMsgBox s"
        ),
        "X"
    );
    assert_eq!(
        the_answer_of(
            "o := Object()\no.x := 1\no.X := 2\ns := \"\"\nfor p in o.OwnProps()\n    s .= p\nMsgBox s"
        ),
        "x"
    );
    // The value of the property is the one that was written last.
    assert_eq!(
        the_answer_of("o := Object()\no.X := 1\no.x := 2\nMsgBox o.X"),
        "2"
    );
}

#[test]
fn the_names_of_the_own_properties_are_in_the_order_of_v2() {
    // Measured on the binary of v2.0.19: the names are sorted
    // and the case of them does not count.
    assert_eq!(
        the_answer_of(
            "o := Object()\no.Zebra := 1\no.apple := 2\no.Mango := 3\ns := \"\"\nfor p in o.OwnProps()\n    s .= p . \" \"\nMsgBox s"
        ),
        "apple Mango Zebra "
    );
}

#[test]
fn the_get_method_of_the_prototype_fails_with_the_words_of_the_prototype() {
    // Measured on the binary of v2.0.19: the prototype of a
    // class is a property of it, and the `GetMethod` of it fails with the
    // words of the prototype.
    assert_eq!(
        the_failure_of("c := Map\nc.GetMethod(\"Prototype\")"),
        "This value of type \"Prototype\" has no method named \"Call\". | GetMethod |"
    );
    assert_eq!(
        the_failure_of("class C {\n}\nC.GetMethod(\"Prototype\")"),
        "This value of type \"Prototype\" has no method named \"Call\". | GetMethod |"
    );
}

#[test]
fn the_own_properties_of_a_prototype_are_the_members_of_the_class() {
    // Measured on the binary of v2.0.19: the prototype of a
    // class owns the class of the value and the members that the class
    // declares -- the methods of it and the properties of it.
    assert_eq!(
        the_answer_of("s := \"\"\nfor p in Map.Prototype.OwnProps()\n    s .= p\nMsgBox s"),
        "__Class__Enum__Item__NewCapacityCaseSenseClearCloneCountDeleteGetHasSet"
    );
    assert_eq!(
        the_answer_of("s := \"\"\nfor p in Array.Prototype.OwnProps()\n    s .= p\nMsgBox s"),
        "__Class__Enum__Item__NewCapacityCloneDeleteGetHasInsertAtLengthPopPushRemoveAt"
    );
    assert_eq!(
        the_answer_of("s := \"\"\nfor p in Buffer.Prototype.OwnProps()\n    s .= p\nMsgBox s"),
        "__Class__NewPtrSize"
    );
    assert_eq!(
        the_answer_of("s := \"\"\nfor p in Error.Prototype.OwnProps()\n    s .= p\nMsgBox s"),
        "__Class__New"
    );
    assert_eq!(
        the_answer_of("s := \"\"\nfor p in Object.Prototype.OwnProps()\n    s .= p\nMsgBox s"),
        "__ClassCloneDefinePropDeletePropGetOwnPropDescHasOwnPropOwnProps"
    );
    assert_eq!(
        the_answer_of("s := \"\"\nfor p in Abs.Base.OwnProps()\n    s .= p\nMsgBox s"),
        "__ClassBindCallIsBuiltInIsByRefIsOptionalIsVariadicMaxParamsMinParamsName"
    );
    assert_eq!(
        the_answer_of("s := \"\"\nfor p in Enumerator.Prototype.OwnProps()\n    s .= p\nMsgBox s"),
        "__Class"
    );
    assert_eq!(
        the_answer_of(
            "s := \"\"\nfor p in ClipboardAll.Prototype.OwnProps()\n    s .= p\nMsgBox s"
        ),
        "__Class__New"
    );
}

#[test]
fn the_own_properties_of_the_prototype_of_a_class_of_the_script_are_its_methods() {
    // Measured on the binary of v2.0.19: the prototype of a
    // class of the script owns the methods that the class declares itself,
    // and the ones that it inherits are not its own.
    assert_eq!(
        the_answer_of(
            "class C {\n    __Init() {\n    }\n    Say() {\n    }\n    static Shout() {\n    }\n}\ns := \"\"\nfor p in C.Prototype.OwnProps()\n    s .= p\nMsgBox s"
        ),
        "__Class__InitSay"
    );
    assert_eq!(
        the_answer_of(
            "class C {\n    Say() {\n    }\n}\nclass D extends C {\n    Other() {\n    }\n}\ns := \"\"\nfor p in D.Prototype.OwnProps()\n    s .= p\nMsgBox s"
        ),
        "__ClassOther"
    );
}

#[test]
fn the_prototype_answers_the_questions_about_the_class_of_it() {
    // Measured on the binary of v2.0.19.
    assert_eq!(the_answer_of("MsgBox Map.Prototype.__Class"), "Map");
    assert_eq!(the_answer_of("MsgBox ObjOwnPropCount(Map.Prototype)"), "13");
    assert_eq!(
        the_answer_of("MsgBox Map.Prototype.HasOwnProp(\"__Class\")"),
        "1"
    );
    assert_eq!(
        the_answer_of("MsgBox Map.Prototype.HasOwnProp(\"Count\")"),
        "1"
    );
    assert_eq!(
        the_answer_of("MsgBox Map.Prototype.HasOwnProp(\"Nope\")"),
        "0"
    );
    assert_eq!(
        the_answer_of("MsgBox Map.Prototype.HasProp(\"Count\")"),
        "1"
    );
    assert_eq!(
        the_answer_of("MsgBox Map.Prototype.HasMethod(\"Get\")"),
        "1"
    );
    assert_eq!(
        the_answer_of("MsgBox Map.Prototype.HasMethod(\"Count\")"),
        "0"
    );
    assert_eq!(
        the_answer_of("MsgBox Map.Prototype.Get.Name"),
        "Map.Prototype.Get"
    );
    assert_eq!(
        the_answer_of("MsgBox Map.Prototype.GetMethod(\"Get\").Name"),
        "Map.Prototype.Get"
    );
    assert_eq!(
        the_answer_of("MsgBox Object.Prototype.GetMethod(\"Clone\").Name"),
        "Object.Prototype.Clone"
    );
}

#[test]
fn the_property_of_a_prototype_is_refused_with_the_kind_of_the_class() {
    // Measured on the binary of v2.0.19: the prototype is not
    // an instance of the class, and the property of the class cannot be read
    // on it.
    assert_eq!(
        the_failure_of("MsgBox Map.Prototype.Count"),
        "Expected a Map but got a Prototype. | Map.Prototype.Count.Get |"
    );
    assert_eq!(
        the_failure_of("MsgBox File.Prototype.Pos"),
        "Expected a File but got a Prototype. | File.Prototype.Pos.Get |"
    );
    assert_eq!(
        the_failure_of("MsgBox Abs.Base.Name"),
        "Expected a Func but got a Prototype. | Func.Prototype.Name.Get |"
    );
}

#[test]
fn the_call_of_a_method_of_a_prototype_is_refused() {
    // Measured on the binary of v2.0.19: the method of a class
    // cannot be called on the prototype of it, and the copy of a prototype is
    // refused as well.
    assert_eq!(
        the_failure_of("Map.Prototype.Get(\"a\")"),
        "Expected a Map but got a Prototype. | Map.Prototype.Get |"
    );
    assert_eq!(
        the_failure_of("Object.Prototype.Clone()"),
        "Type mismatch. | Object.Prototype.Clone |"
    );
}

#[test]
fn the_members_of_a_prototype_are_read_only() {
    // Measured on the binary of v2.0.19: the members of the
    // prototype of a class are read-only, and a name that the prototype does
    // not own is written.
    assert_eq!(
        the_failure_of("Map.Prototype.Count := 5"),
        "Property is read-only. |  | Count"
    );
    assert_eq!(
        the_failure_of("Map.Prototype.Get := 5"),
        "Property is read-only. |  | Get"
    );
    assert_eq!(
        the_answer_of("Map.Prototype.Nope := 5\nMsgBox \"ok\""),
        "ok"
    );
    // The base of a prototype is written the way the base of an object is.
    assert_eq!(
        the_answer_of("Map.Prototype.Base := Object()\nMsgBox \"ok\""),
        "ok"
    );
}

#[test]
fn the_methods_are_values() {
    // Measured on the binary of v2.0.19: a method is handed
    // over as a function, and the name of it is the name of the member.
    assert_eq!(
        the_answer_of("o := Object()\nMsgBox o.Clone.Name"),
        "Object.Prototype.Clone"
    );
    assert_eq!(
        the_answer_of("o := Object()\nMsgBox o.OwnProps.Name"),
        "Object.Prototype.OwnProps"
    );
    // The four that the script asks about every day keep the name they
    // have.
    assert_eq!(
        the_answer_of("o := Object()\nMsgBox o.HasProp.Name"),
        "HasProp"
    );
    assert_eq!(
        the_answer_of("m := Map()\nMsgBox m.Get.Name"),
        "Map.Prototype.Get"
    );
    assert_eq!(
        the_answer_of("f := Abs\nMsgBox f.Call.Name"),
        "Func.Prototype.Call"
    );
}

#[test]
fn the_get_method_of_a_value_hands_the_method_over() {
    // Measured on the binary of v2.0.19.
    assert_eq!(
        the_answer_of("o := Object()\nMsgBox o.GetMethod(\"Clone\").Name"),
        "Object.Prototype.Clone"
    );
    assert_eq!(
        the_answer_of("m := Map()\nMsgBox m.GetMethod(\"Get\").Name"),
        "Map.Prototype.Get"
    );
    assert_eq!(
        the_answer_of("a := [1]\nMsgBox a.GetMethod(\"Push\").Name"),
        "Array.Prototype.Push"
    );
    assert_eq!(
        the_answer_of("f := Abs\nMsgBox f.GetMethod(\"Call\").Name"),
        "Func.Prototype.Call"
    );
    assert_eq!(
        the_answer_of("o := Error(\"x\")\nMsgBox o.GetMethod(\"Clone\").Name"),
        "Object.Prototype.Clone"
    );
    assert_eq!(
        the_answer_of(
            "class Thing {\n    Say() {\n        return 1\n    }\n}\nobj := Thing()\nMsgBox obj.GetMethod(\"Say\").Name"
        ),
        "Thing.Prototype.Say"
    );
    // The method that is not there is refused with the words of the value.
    assert_eq!(
        the_failure_of("m := Map()\nm.GetMethod(\"Nope\")"),
        "This value of type \"Map\" has no method named \"Nope\". | GetMethod |"
    );
}

#[test]
fn the_number_of_the_arguments_of_a_method_is_the_one_of_the_value() {
    // Measured on the binary of v2.0.19: the object is one of
    // the arguments of the call.
    assert_eq!(the_answer_of("m := Map()\nMsgBox m.Get.MinParams"), "2");
    assert_eq!(the_answer_of("m := Map()\nMsgBox m.Get.MaxParams"), "3");
    assert_eq!(
        the_answer_of("o := Object()\nMsgBox o.Clone.MinParams"),
        "1"
    );
    assert_eq!(
        the_answer_of("o := Object()\nMsgBox o.Clone.MaxParams"),
        "1"
    );
    assert_eq!(
        the_answer_of("o := Object()\nMsgBox o.DefineProp.MaxParams"),
        "3"
    );
}

#[test]
fn the_prototype_of_an_any_has_no_method_at_all() {
    // Measured on the binary of v2.0.19: the prototype of an
    // `Any`, of a `ComObject` and of a `ComValue` is not a prototype: it has
    // no method at all.
    assert_eq!(
        the_failure_of("Any.Prototype.OwnProps()"),
        "This value of type \"Prototype\" has no method named \"OwnProps\". |  |"
    );
    assert_eq!(
        the_failure_of("ComValue.Prototype.OwnProps()"),
        "This value of type \"Prototype\" has no method named \"OwnProps\". |  |"
    );
}

#[test]
fn a_static_method_is_not_a_member_of_an_instance() {
    // Measured on the binary of v2.0.19: a static method
    // belongs to the class and not to its instances.
    assert_eq!(
        the_failure_of(
            "class C {\n    static Say() {\n        return 1\n    }\n}\nobj := C()\nobj.Say()"
        ),
        "This value of type \"C\" has no method named \"Say\". |  |"
    );
    assert_eq!(
        the_failure_of(
            "class C {\n    static Say() {\n        return 1\n    }\n}\nobj := C()\nMsgBox obj.Say"
        ),
        "This value of type \"C\" has no property named \"Say\". |  |"
    );
    assert_eq!(
        the_answer_of(
            "class C {\n    static Say() {\n        return 1\n    }\n}\nobj := C()\nMsgBox obj.HasMethod(\"Say\")"
        ),
        "0"
    );
    assert_eq!(
        the_failure_of(
            "class C {\n    static Say() {\n        return 1\n    }\n}\nobj := C()\nobj.GetMethod(\"Say\")"
        ),
        "This value of type \"C\" has no method named \"Say\". | GetMethod |"
    );
}

#[test]
fn a_static_method_is_not_a_member_of_the_prototype() {
    // Measured on the binary of v2.0.19: the prototype of a
    // class carries the methods of the class, and not the static ones.
    assert_eq!(
        the_failure_of(
            "class C {\n    static Say() {\n        return 1\n    }\n}\nMsgBox C.Prototype.Say"
        ),
        "This value of type \"Prototype\" has no property named \"Say\". |  |"
    );
    assert_eq!(
        the_failure_of(
            "class C {\n    static Say() {\n        return 1\n    }\n}\nC.Prototype.Say()"
        ),
        "This value of type \"Prototype\" has no method named \"Say\". |  |"
    );
    assert_eq!(
        the_answer_of(
            "class C {\n    static Say() {\n        return 1\n    }\n}\nMsgBox C.Prototype.HasMethod(\"Say\")"
        ),
        "0"
    );
    assert_eq!(
        the_failure_of(
            "class C {\n    static Say() {\n        return 1\n    }\n}\nC.Prototype.GetMethod(\"Say\")"
        ),
        "This value of type \"Prototype\" has no method named \"Say\". | GetMethod |"
    );
}

#[test]
fn a_static_method_does_not_hide_the_instance_method_of_the_base() {
    // Measured on the binary of v2.0.19: the instance still
    // has the instance method of its base.
    assert_eq!(
        the_answer_of(
            "class D {\n    Say() {\n        return 1\n    }\n}\nclass C extends D {\n    static Say() {\n        return 2\n    }\n}\nobj := C()\nMsgBox obj.Say()"
        ),
        "1"
    );
    assert_eq!(
        the_answer_of(
            "class D {\n    Say() {\n        return 1\n    }\n}\nclass C extends D {\n    static Say() {\n        return 2\n    }\n}\nobj := C()\nMsgBox obj.Say.Name"
        ),
        "D.Prototype.Say"
    );
}

#[test]
fn a_class_value_has_the_static_methods_of_the_class() {
    // Measured on the binary of v2.0.19: the static methods
    // are the own properties of the class value.
    assert_eq!(
        the_answer_of(
            "class C {\n    static Say() {\n        return 1\n    }\n}\nMsgBox C.Say.Name"
        ),
        "C.Say"
    );
    assert_eq!(
        the_answer_of(
            "class C {\n    static Say() {\n        return 1\n    }\n}\nMsgBox C.GetMethod(\"Say\").Name"
        ),
        "C.Say"
    );
    assert_eq!(
        the_answer_of(
            "class C {\n    static Say() {\n        return 1\n    }\n}\nMsgBox C.HasMethod(\"Say\")"
        ),
        "1"
    );
    assert_eq!(
        the_answer_of(
            "class C {\n    static Say() {\n        return 1\n    }\n}\nMsgBox C.HasProp(\"Say\")"
        ),
        "1"
    );
}

#[test]
fn the_prototype_has_the_methods_of_the_class_and_of_the_base() {
    // Measured on the binary of v2.0.19: the prototype of a
    // class carries the methods of the class and the ones of its base.
    assert_eq!(
        the_answer_of(
            "class D {\n    Say() {\n        return 1\n    }\n}\nclass C extends D {\n}\nMsgBox C.Prototype.HasMethod(\"Say\")"
        ),
        "1"
    );
    assert_eq!(
        the_answer_of(
            "class D {\n    Say() {\n        return 1\n    }\n}\nclass C extends D {\n}\nMsgBox C.Prototype.HasProp(\"Say\")"
        ),
        "1"
    );
    assert_eq!(
        the_answer_of(
            "class D {\n    Say() {\n        return 1\n    }\n}\nclass C extends D {\n}\nMsgBox C.Prototype.Say.Name"
        ),
        "D.Prototype.Say"
    );
    assert_eq!(
        the_answer_of(
            "class D {\n    Say() {\n        return 1\n    }\n}\nclass C extends D {\n}\nMsgBox C.Prototype.GetMethod(\"Say\").Name"
        ),
        "D.Prototype.Say"
    );
}

#[test]
fn the_method_of_a_class_runs_on_the_prototype_of_it() {
    // Measured on the binary of v2.0.19: v2 calls the method
    // of a class of the script on the prototype, and `this` is the
    // prototype.
    assert_eq!(
        the_answer_of(
            "class C {\n    Say() {\n        return 1\n    }\n}\nMsgBox C.Prototype.Say()"
        ),
        "1"
    );
    assert_eq!(
        the_answer_of(
            "class C {\n    Say() {\n        return this\n    }\n}\nMsgBox C.Prototype.Say().__Class"
        ),
        "C"
    );
}

#[test]
fn the_methods_of_a_class_are_the_properties_of_an_instance() {
    // Measured on the binary of v2.0.19: the `HasProp` of a
    // method of the class answers 1, and so do the initialiser and the base.
    assert_eq!(
        the_answer_of(
            "class C {\n    Say() {\n        return 1\n    }\n}\nobj := C()\nMsgBox obj.HasProp(\"Say\")"
        ),
        "1"
    );
    assert_eq!(
        the_answer_of("class C {\n}\nobj := C()\nMsgBox obj.HasProp(\"__Init\")"),
        "1"
    );
    assert_eq!(
        the_answer_of("class C {\n}\nobj := C()\nMsgBox obj.HasProp(\"Base\")"),
        "1"
    );
    assert_eq!(
        the_answer_of("class C {\n}\nobj := C()\nMsgBox obj.HasProp(\"Nope\")"),
        "0"
    );
    assert_eq!(the_answer_of("m := Map()\nMsgBox m.HasProp(\"Get\")"), "1");
    assert_eq!(
        the_answer_of("m := Map()\nMsgBox m.HasMethod(\"__Init\")"),
        "1"
    );
}

#[test]
fn a_static_variable_is_not_a_member_of_an_instance() {
    // Measured on the binary of v2.0.19: a static variable
    // belongs to the class and not to its instances.
    assert_eq!(
        the_answer_of(
            "class C {\n    static value := 1\n}\nobj := C()\nMsgBox obj.HasProp(\"value\")"
        ),
        "0"
    );
    assert_eq!(
        the_failure_of("class C {\n    static value := 1\n}\nobj := C()\nMsgBox obj.value"),
        "This value of type \"C\" has no property named \"value\". |  |"
    );
    assert_eq!(
        the_answer_of("class C {\n    static value := 1\n}\nMsgBox C.value"),
        "1"
    );
}

#[test]
fn the_prototype_owns_the_automatic_init_of_the_class() {
    // Measured on the binary of v2.0.19: the automatic
    // `__Init` is own of the prototype when the class has variables of its
    // own: it is the one that carries them.
    assert_eq!(
        the_answer_of(
            "class C {\n    value := 1\n}\ns := \"\"\nfor p in C.Prototype.OwnProps()\n    s .= p\nMsgBox s"
        ),
        "__Class__Init"
    );
    assert_eq!(
        the_answer_of(
            "class C {\n    __Init() {\n    }\n}\ns := \"\"\nfor p in C.Prototype.OwnProps()\n    s .= p\nMsgBox s"
        ),
        "__Class__Init"
    );
    assert_eq!(
        the_answer_of(
            "class C {\n}\ns := \"\"\nfor p in C.Prototype.OwnProps()\n    s .= p\nMsgBox s"
        ),
        "__Class"
    );
}

#[test]
fn a_class_inside_a_class_is_an_own_property_of_the_class() {
    // Measured on the binary of v2.0.19: the class inside a
    // class is an own property of the class value of the class that holds
    // it, and it is not a member of an instance of it.
    assert_eq!(
        the_answer_of("class Outer {\n    class Inner {\n    }\n}\nMsgBox Outer.Inner.__Class"),
        "Class"
    );
    assert_eq!(
        the_answer_of(
            "class Outer {\n    class Inner {\n    }\n}\ns := \"\"\nfor p in Outer.OwnProps()\n    s .= p\nMsgBox s"
        ),
        "__InitInnerPrototype"
    );
    assert_eq!(
        the_answer_of(
            "class Outer {\n    class Inner {\n    }\n}\ns := \"\"\nfor p in Outer.Prototype.OwnProps()\n    s .= p\nMsgBox s"
        ),
        "__Class"
    );
    assert_eq!(
        the_failure_of(
            "class Outer {\n    class Inner {\n    }\n}\nobj := Outer()\nMsgBox obj.Inner"
        ),
        "This value of type \"Outer\" has no property named \"Inner\". |  |"
    );
}

#[test]
fn the_name_of_the_class_inside_a_class_is_the_name_of_the_class_that_holds_it() {
    // Measured on the binary of v2.0.19: the class inside
    // `Outer` is "Outer.Inner".
    assert_eq!(
        the_answer_of(
            "class Outer {\n    class Inner {\n    }\n}\nobj := Outer.Inner()\nMsgBox obj.__Class"
        ),
        "Outer.Inner"
    );
    assert_eq!(
        the_answer_of(
            "class Outer {\n    class Middle {\n        class Inner {\n        }\n    }\n}\nobj := Outer.Middle.Inner()\nMsgBox obj.__Class"
        ),
        "Outer.Middle.Inner"
    );
    // The class of the top level and the class inside a class are two
    // classes, and their names are different.
    assert_eq!(
        the_answer_of(
            "class Inner {\n}\nclass Outer {\n    class Inner {\n    }\n}\nobj := Outer.Inner()\nMsgBox obj.__Class"
        ),
        "Outer.Inner"
    );
}

#[test]
fn the_call_of_a_class_inside_a_class_makes_an_object_of_it() {
    // Measured on the binary of v2.0.19: `Outer.Inner()` is
    // an object of the class inside `Outer`.
    assert_eq!(
        the_answer_of(
            "class Outer {\n    class Inner {\n        Say() {\n            return 1\n        }\n    }\n}\nMsgBox Outer.Inner().Say()"
        ),
        "1"
    );
    assert_eq!(
        the_answer_of(
            "class Base {\n    Say() {\n        return 1\n    }\n}\nclass Outer {\n    class Inner extends Base {\n        Other() {\n            return super.Say()\n        }\n    }\n}\nMsgBox Outer.Inner().Other()"
        ),
        "1"
    );
}

#[test]
fn the_duplicate_of_a_class_inside_a_class_is_refused() {
    // Measured on the binary of v2.0.19: the name of the
    // class is a name of the class that holds it, and the duplicate of it
    // is refused the way the duplicate of a property is.
    assert_eq!(
        the_load_failure_of("class Outer {\n    class Inner {\n    }\n    class Inner {\n    }\n}"),
        "Duplicate declaration.\n     Specifically: Inner"
    );
    assert_eq!(
        the_load_failure_of("class Outer {\n    static Inner := 1\n    class Inner {\n    }\n}"),
        "Duplicate declaration.\n     Specifically: Inner"
    );
}

#[test]
fn a_class_inside_a_class_may_not_be_static() {
    // Measured on the binary of v2.0.19: v2 names the whole
    // of the definition, and not the line of it.
    assert_eq!(
        the_load_failure_of("class Outer {\n    static class Inner {\n    }\n}"),
        "Not a valid method, class or property definition.\n     Specifically: static class Inner { }"
    );
}

#[test]
fn a_property_of_a_class_may_have_a_getter_and_a_setter() {
    // Measured on the binary of v2.0.19: the read of the
    // property is the value of the getter, and the write of it calls the
    // setter.
    assert_eq!(
        the_answer_of(
            "class C {\n    value {\n        get => 1\n    }\n}\nobj := C()\nMsgBox obj.value"
        ),
        "1"
    );
    assert_eq!(
        the_answer_of(
            "class C {\n    value {\n        set => this.stored := value\n    }\n}\nobj := C()\nobj.value := 5\nMsgBox obj.stored"
        ),
        "5"
    );
    // A property that has no getter is not read.
    assert_eq!(
        the_failure_of(
            "class C {\n    value {\n        set => this.stored := value\n    }\n}\nobj := C()\nMsgBox obj.value"
        ),
        "This value of type \"C\" has no property named \"value\". |  |"
    );
    // A property that has no setter is not written.
    assert_eq!(
        the_failure_of(
            "class C {\n    value {\n        get => 1\n    }\n}\nobj := C()\nobj.value := 5"
        ),
        "Property is read-only. |  | value"
    );
    // The property is own of the prototype, and it is not a method.
    assert_eq!(
        the_answer_of(
            "class C {\n    value {\n        get => 1\n    }\n}\ns := \"\"\nfor p in C.Prototype.OwnProps()\n    s .= p\nMsgBox s"
        ),
        "__Classvalue"
    );
    assert_eq!(
        the_answer_of(
            "class C {\n    value {\n        get => 1\n    }\n}\nobj := C()\nMsgBox obj.HasProp(\"value\")"
        ),
        "1"
    );
    assert_eq!(
        the_answer_of(
            "class C {\n    value {\n        get => 1\n    }\n}\nobj := C()\nMsgBox obj.HasMethod(\"value\")"
        ),
        "0"
    );
    assert_eq!(
        the_answer_of(
            "class C {\n    value {\n        get => 1\n    }\n}\nobj := C()\nMsgBox obj.HasOwnProp(\"value\")"
        ),
        "0"
    );
    // The getter of the prototype runs on the prototype.
    assert_eq!(
        the_answer_of(
            "class C {\n    value {\n        get => 1\n    }\n}\nMsgBox C.Prototype.value"
        ),
        "1"
    );
    // The property of an instance is not a method, and the property of the
    // class is not own of the class value.
    assert_eq!(
        the_failure_of(
            "class C {\n    value {\n        get => 1\n    }\n}\nobj := C()\nMsgBox obj.value()"
        ),
        "This value of type \"C\" has no method named \"value\". |  |"
    );
    assert_eq!(
        the_failure_of("class C {\n    value {\n        get => 1\n    }\n}\nMsgBox C.value"),
        "This value of type \"Class\" has no property named \"value\". |  |"
    );
}

#[test]
fn the_property_of_a_class_is_inherited() {
    // Measured on the binary of v2.0.19: the properties of
    // the base are the ones of the instances too.
    assert_eq!(
        the_answer_of(
            "class D {\n    value {\n        get => 1\n    }\n}\nclass C extends D {\n}\nobj := C()\nMsgBox obj.value"
        ),
        "1"
    );
    assert_eq!(
        the_answer_of(
            "class D {\n    value {\n        set => this.stored := value\n    }\n}\nclass C extends D {\n}\nobj := C()\nobj.value := 5\nMsgBox obj.stored"
        ),
        "5"
    );
    assert_eq!(
        the_answer_of(
            "class D {\n    value {\n        get => 1\n    }\n}\nclass C extends D {\n}\nobj := C()\nMsgBox obj.HasProp(\"value\")"
        ),
        "1"
    );
}

#[test]
fn a_static_property_of_a_class_may_have_a_getter() {
    // Measured on the binary of v2.0.19: the static property
    // is own of the class value, and the getter of it runs on the class.
    assert_eq!(
        the_answer_of("class C {\n    static value {\n        get => 1\n    }\n}\nMsgBox C.value"),
        "1"
    );
    assert_eq!(
        the_failure_of(
            "class C {\n    static value {\n        get => 1\n    }\n}\nobj := C()\nMsgBox obj.value"
        ),
        "This value of type \"C\" has no property named \"value\". |  |"
    );
    assert_eq!(
        the_answer_of(
            "class C {\n    static value {\n        get => 1\n    }\n}\ns := \"\"\nfor p in C.OwnProps()\n    s .= p\nMsgBox s"
        ),
        "__InitPrototypevalue"
    );
    assert_eq!(
        the_answer_of(
            "class C {\n    static value {\n        get => 1\n    }\n}\ns := \"\"\nfor p in C.Prototype.OwnProps()\n    s .= p\nMsgBox s"
        ),
        "__Class"
    );
}

#[test]
fn the_initialiser_of_a_variable_of_an_instance_has_this() {
    // Measured on the binary of v2.0.19: the initialiser of a
    // variable of an instance runs with `this` bound to the instance, and the
    // variables that were assigned before it are there for it to read: the
    // `x := 123` and the `y := this.x` of one class answer 123 and 123.
    let report = run(concat!(
        "class C {\n",
        "    x := 123\n",
        "    y := this.x\n",
        "}\n",
        "o := C()\n",
        "MsgBox o.x \"|\" o.y\n",
    ));
    assert!(report.ok, "{:?}", report.error);
    assert_eq!(report.output, vec!["123|123"]);
}

#[test]
fn the_item_of_a_class_is_written_through_its_setter() {
    // Measured on the binary of v2.0.19: `obj[1] := "ONE"`
    // runs the setter of the `__Item` with the index and the value, and the
    // getter answers the value that the setter wrote.
    assert_eq!(
        the_answer_of(
            "class C {\n    __New() {\n        this.inner := [\"zero\", \"one\"]\n    }\n    __Item[key] {\n        get {\n            return this.inner[key]\n        }\n        set {\n            this.inner[key] := value\n        }\n    }\n}\nobj := C()\nobj[1] := \"ONE\"\nMsgBox obj[1] \"|\" obj[2]"
        ),
        "ONE|one"
    );
}

#[test]
fn the_item_of_a_class_is_the_property_that_is_named_item() {
    // Measured on the binary of v2.0.19: the item of an
    // object of a class of the script is the property `__Item` of it, and
    // the getter of it takes the index.
    assert_eq!(
        the_answer_of(
            "class C {\n    __Item[key] {\n        get => key\n    }\n}\nobj := C()\nMsgBox obj[\"a\"]"
        ),
        "a"
    );
    // A property that takes no parameter forwards the index to the `__Item`
    // of the value that it answers.
    assert_eq!(
        the_failure_of(
            "class C {\n    __Item {\n        get => 7\n    }\n}\nobj := C()\nMsgBox obj[\"a\"]"
        ),
        "This value of type \"Integer\" has no property named \"__Item\". |  |"
    );
    // A method of that name is not the item: the item is the method itself.
    assert_eq!(
        the_answer_of(
            "class C {\n    __Item(key) {\n        return key\n    }\n}\nobj := C()\nx := obj[3]\nMsgBox x.Name"
        ),
        "C.Prototype.__Item"
    );
}

#[test]
fn a_variable_of_a_class_that_has_a_getter_is_one_name_and_not_two() {
    // Measured on the binary of v2.0.19: the construction of
    // the class is refused with "Property is read-only." when the property
    // has no setter.
    assert_eq!(
        the_failure_of(
            "class C {\n    value := 1\n    value {\n        get => 2\n    }\n}\nobj := C()"
        ),
        "Property is read-only. |  | value"
    );
}

#[test]
fn the_failure_of_a_method_of_the_base_object_names_the_method() {
    // Measured on the binary of v2.0.19: the failure of a
    // method of the base object carries the name of the method in the
    // `What`.
    assert_eq!(
        the_failure_of("o := Object()\no.GetOwnPropDesc(\"x\")"),
        "This value of type \"Object\" has no property named \"x\". | Object.Prototype.GetOwnPropDesc |"
    );
    assert_eq!(
        the_failure_of("o := Object()\no.DefineProp(\"x\", 1)"),
        "Parameter #2 of Object.Prototype.DefineProp is invalid. | Object.Prototype.DefineProp | 1"
    );
}

#[test]
fn the_name_of_a_property_may_be_a_number() {
    // Measured on the binary of v2.0.19: the name of a
    // property may be a number, and the property "123" is a name of its
    // own.
    assert_eq!(
        the_answer_of("class C {\n    123 := 1\n}\no := C()\nMsgBox o.HasProp(\"123\")"),
        "1"
    );
    assert_eq!(
        the_answer_of("class C {\n    static 123 := 1\n}\nMsgBox C.HasProp(\"123\")"),
        "1"
    );
}

#[test]
fn a_number_alone_in_a_class_is_refused() {
    // Measured on the binary of v2.0.19: a member that is a
    // name and nothing else is a line with no action.
    assert_eq!(
        the_load_failure_of("class C {\n    123\n}"),
        "This line does not contain a recognized action.\n     Specifically: 123"
    );
}

#[test]
fn the_name_of_a_method_may_not_begin_with_a_number() {
    assert_eq!(
        the_load_failure_of("class C {\n    123() {\n    }\n}"),
        "This method name starts with a number, which is not allowed:\n\"123\""
    );
}

#[test]
fn the_name_of_a_class_may_not_begin_with_a_number() {
    // Measured on the binary of v2.0.19: the whole of the
    // number is named, and not the part before the point.
    assert_eq!(
        the_load_failure_of("class 123 {\n}"),
        "This class name starts with a number, which is not allowed:\n\"123\""
    );
    assert_eq!(
        the_load_failure_of("class C {\n    class 123 {\n    }\n}"),
        "This class name starts with a number, which is not allowed:\n\"123\""
    );
    assert_eq!(
        the_load_failure_of("class 1.5 {\n}"),
        "This class name starts with a number, which is not allowed:\n\"1.5\""
    );
}

#[test]
fn a_reserved_word_is_not_the_name_of_a_class() {
    assert_eq!(
        the_load_failure_of("class C {\n    class if {\n    }\n}"),
        "The following reserved word must not be used as a class name:\n\"if\""
    );
}

#[test]
fn a_brace_in_a_class_is_refused() {
    // Measured on the binary of v2.0.19: a brace in a class
    // is a token that cannot be there, and the line of it is named.
    assert_eq!(
        the_load_failure_of("class C {\n    {\n}"),
        "Unexpected \"{\"\n     Specifically: {"
    );
}

#[test]
fn the_class_with_no_name_is_read_and_dropped() {
    // Measured on the binary of v2.0.19: v2 reads the class
    // and drops it, and the class that holds it does not own it.
    assert_eq!(
        the_answer_of(
            "class C {\n    class {\n    }\n}\ns := \"\"\nfor p in ObjOwnProps(C)\n    s .= \"[\" p \"]\"\nMsgBox s"
        ),
        "[__Init][Prototype]"
    );
}

#[test]
fn the_float_is_not_the_name_of_a_property() {
    // Measured on the binary of v2.0.19: the number that is
    // a float is not a name, and the assignment of one is refused.
    assert_eq!(
        the_load_failure_of("class C {\n    1.5 := 1\n}"),
        "Unknown class var.\n     Specifically: 1.5 := 1"
    );
}

#[test]
fn the_base_of_a_class_that_is_not_there_is_refused() {
    // Measured on the binary of v2.0.19: the base of a class
    // is a class, and the one that is not there is refused at the load.
    assert_eq!(
        the_load_failure_of("class C extends Nope {\n}"),
        "Unknown class.\n     Specifically: Nope"
    );
    assert_eq!(
        the_load_failure_of("class C extends 123 {\n}"),
        "Unknown class.\n     Specifically: 123"
    );
    assert_eq!(
        the_load_failure_of("class C extends \"Nope\" {\n}"),
        "Unknown class.\n     Specifically: \"Nope\""
    );
    // The name of a function is not the name of a class.
    assert_eq!(
        the_load_failure_of("class C extends Hotkey {\n}"),
        "Unknown class.\n     Specifically: Hotkey"
    );
}

#[test]
fn the_class_value_of_a_class_of_the_runtime_owns_the_call_and_the_prototype() {
    // Measured on the binary of v2.0.19: the class value of
    // the `Map` owns the call and the prototype, and not the table that
    // the tree keeps.
    assert_eq!(
        the_answer_of("s := \"\"\nfor p in ObjOwnProps(Map)\n    s .= \"[\" p \"]\"\nMsgBox s"),
        "[Call][Prototype]"
    );
    assert_eq!(
        the_answer_of("s := \"\"\nfor p in ObjOwnProps(Object)\n    s .= \"[\" p \"]\"\nMsgBox s"),
        "[Call][Prototype]"
    );
}

#[test]
fn the_class_value_of_an_error_owns_the_prototype_alone() {
    // Measured on the binary of v2.0.19: the class value of
    // the `Error` owns the prototype alone, and the call of it is
    // inherited.
    assert_eq!(
        the_answer_of("s := \"\"\nfor p in ObjOwnProps(Error)\n    s .= \"[\" p \"]\"\nMsgBox s"),
        "[Prototype]"
    );
    assert_eq!(
        the_answer_of("FileAppend Error.HasOwnProp(\"Call\"), \"*\""),
        "0"
    );
    assert_eq!(
        the_answer_of("FileAppend Error.HasProp(\"Call\"), \"*\""),
        "1"
    );
}

#[test]
fn the_name_of_the_class_is_not_an_own_property_of_it() {
    // Measured on the binary of v2.0.19: the tree keeps the
    // name of the class under a key of its own, and the key is not a
    // property of the class value.
    assert_eq!(
        the_answer_of("FileAppend Map.HasOwnProp(\"class name\"), \"*\""),
        "0"
    );
}

#[test]
fn the_base_of_a_class_may_be_declared_after_it() {
    assert_eq!(
        the_answer_of("class C extends D {\n}\nclass D {\n}\nMsgBox C.Prototype.__Class"),
        "C"
    );
    assert_eq!(
        the_answer_of("class C extends Map {\n}\nMsgBox C.Prototype.__Class"),
        "C"
    );
}