@@ -649,6 +649,30 @@ def test_includes():
649
649
pm .eval ("(result, arr) => {result[0] = arr.includes(1)}" )(result , items )
650
650
assert result [0 ] == True
651
651
652
+ def test_includes_start_index ():
653
+ items = [1 ,2 ,3 ]
654
+ result = [None ]
655
+ pm .eval ("(result, arr) => {result[0] = arr.includes(1, 1)}" )(result , items )
656
+ assert result [0 ] == False
657
+
658
+ def test_includes_start_index_negative ():
659
+ items = [1 ,2 ,3 ]
660
+ result = [None ]
661
+ pm .eval ("(result, arr) => {result[0] = arr.includes(1, -1)}" )(result , items )
662
+ assert result [0 ] == False
663
+
664
+ def test_includes_start_index_negative_large ():
665
+ items = [1 ,2 ,3 ]
666
+ result = [None ]
667
+ pm .eval ("(result, arr) => {result[0] = arr.includes(1, -10)}" )(result , items )
668
+ assert result [0 ] == True
669
+
670
+ def test_includes_start_index_large ():
671
+ items = [1 ,2 ,3 ]
672
+ result = [None ]
673
+ pm .eval ("(result, arr) => {result[0] = arr.includes(1, 10)}" )(result , items )
674
+ assert result [0 ] == False
675
+
652
676
def test_includes_other_type ():
653
677
items = [1 ,2 ,'Hi' ]
654
678
result = [None ]
@@ -844,7 +868,25 @@ def test_forEach_check_this_arg_wrong_type():
844
868
# returnResult = [0]
845
869
# pm.eval("(returnResult, arr, func) => {returnResult[0] = arr.forEach(func)}")(returnResult, items, func)
846
870
# assert items == ['to each his own', 'to each his own', 'to each his own']
847
- # assert returnResult == [None]
871
+ # assert returnResult == [None]
872
+
873
+ #def test_forEach_self():
874
+ # items = ['Four', 'Three', 'One']
875
+ # class Counter:
876
+ # def __init__(self):
877
+ # self.count = 0
878
+ # def increment(self):
879
+ # self.count += 1
880
+
881
+ # obj = Counter()
882
+ # result = pm.eval("""
883
+ # (arr, increment, result) => {
884
+ # let jsObj = {count: 0}
885
+ # arr.forEach(increment, jsObj);
886
+ # return jsObj.count;
887
+ # }
888
+ # """)(items, obj.increment)
889
+ # assert result == 3
848
890
849
891
850
892
# TODO should not pass
@@ -936,6 +978,24 @@ def test_map_check_array_mutation():
936
978
pm .eval ("(result, arr) => {arr.map((element, index, array) => {array[0] = 'Ten'; result[0] = array})}" )(result , items )
937
979
assert result [0 ] == ['Ten' , 'Three' , 'One' ]
938
980
assert items == ['Ten' , 'Three' , 'One' ]
981
+
982
+ #def test_map_self():
983
+ # items = ['Four', 'Three', 'One']
984
+ # class Counter:
985
+ # def __init__(self):
986
+ # self.count = 0
987
+ # def increment(self):
988
+ # self.count += 1
989
+
990
+ # obj = Counter()
991
+ # result = pm.eval("""
992
+ # (arr, increment, result) => {
993
+ # let jsObj = {count: 0}
994
+ # arr.map(increment, jsObj);
995
+ # return jsObj.count;
996
+ # }
997
+ # """)(items, obj.increment)
998
+ # assert result == 3
939
999
940
1000
#filter
941
1001
def test_filter ():
@@ -989,7 +1049,25 @@ def test_filter_too_few_args():
989
1049
assert (False )
990
1050
except Exception as e :
991
1051
assert str (type (e )) == "<class 'pythonmonkey.SpiderMonkeyError'>"
992
- assert str (e ).__contains__ ("TypeError: filter: At least 1 argument required, but only 0 passed" )
1052
+ assert str (e ).__contains__ ("TypeError: filter: At least 1 argument required, but only 0 passed" )
1053
+
1054
+ #def test_filter_self():
1055
+ # items = ['Four', 'Three', 'One']
1056
+ # class Counter:
1057
+ # def __init__(self):
1058
+ # self.count = 0
1059
+ # def increment(self):
1060
+ # self.count += 1
1061
+
1062
+ # obj = Counter()
1063
+ # result = pm.eval("""
1064
+ # (arr, increment, result) => {
1065
+ # let jsObj = {count: 0}
1066
+ # arr.filter(increment, jsObj);
1067
+ # return jsObj.count;
1068
+ # }
1069
+ # """)(items, obj.increment)
1070
+ # assert result == 3
993
1071
994
1072
#reduce
995
1073
def test_reduce ():
@@ -1164,6 +1242,24 @@ def test_some_truthy_conversion():
1164
1242
""" )(result )
1165
1243
assert result [0 ] == True
1166
1244
1245
+ #def test_some_self():
1246
+ # items = ['Four', 'Three', 'One']
1247
+ # class Counter:
1248
+ # def __init__(self):
1249
+ # self.count = 0
1250
+ # def increment(self):
1251
+ # self.count += 1
1252
+
1253
+ # obj = Counter()
1254
+ # result = pm.eval("""
1255
+ # (arr, increment, result) => {
1256
+ # let jsObj = {count: 0}
1257
+ # arr.some(increment, jsObj);
1258
+ # return jsObj.count;
1259
+ # }
1260
+ # """)(items, obj.increment)
1261
+ # assert result == 3
1262
+
1167
1263
#every
1168
1264
def test_every_true ():
1169
1265
items = [2 ,4 ,6 ]
@@ -1213,7 +1309,25 @@ class Counter {
1213
1309
}
1214
1310
"""
1215
1311
)(result , items )
1216
- assert result == [1 ]
1312
+ assert result == [1 ]
1313
+
1314
+ #def test_every_self():
1315
+ # items = ['Four', 'Three', 'One']
1316
+ # class Counter:
1317
+ # def __init__(self):
1318
+ # self.count = 0
1319
+ # def increment(self):
1320
+ # self.count += 1
1321
+
1322
+ # obj = Counter()
1323
+ # result = pm.eval("""
1324
+ # (arr, increment, result) => {
1325
+ # let jsObj = {count: 0}
1326
+ # arr.every(increment, jsObj);
1327
+ # return jsObj.count;
1328
+ # }
1329
+ # """)(items, obj.increment)
1330
+ # assert result == 3
1217
1331
1218
1332
#find
1219
1333
def test_find_found_once ():
@@ -1270,7 +1384,25 @@ class Counter {
1270
1384
}
1271
1385
"""
1272
1386
)(result , items )
1273
- assert result == [3 ]
1387
+ assert result == [3 ]
1388
+
1389
+ #def test_find_self():
1390
+ # items = ['Four', 'Three', 'One']
1391
+ # class Counter:
1392
+ # def __init__(self):
1393
+ # self.count = 0
1394
+ # def increment(self):
1395
+ # self.count += 1
1396
+
1397
+ # obj = Counter()
1398
+ # result = pm.eval("""
1399
+ # (arr, increment, result) => {
1400
+ # let jsObj = {count: 0}
1401
+ # arr.find(increment, jsObj);
1402
+ # return jsObj.count;
1403
+ # }
1404
+ # """)(items, obj.increment)
1405
+ # assert result == 3
1274
1406
1275
1407
#findIndex
1276
1408
def test_findIndex_found_once ():
@@ -1327,7 +1459,25 @@ class Counter {
1327
1459
}
1328
1460
"""
1329
1461
)(result , items )
1330
- assert result == [3 ]
1462
+ assert result == [3 ]
1463
+
1464
+ #def test_findIndex_self():
1465
+ # items = ['Four', 'Three', 'One']
1466
+ # class Counter:
1467
+ # def __init__(self):
1468
+ # self.count = 0
1469
+ # def increment(self):
1470
+ # self.count += 1
1471
+
1472
+ # obj = Counter()
1473
+ # result = pm.eval("""
1474
+ # (arr, increment, result) => {
1475
+ # let jsObj = {count: 0}
1476
+ # arr.findIndex(increment, jsObj);
1477
+ # return jsObj.count;
1478
+ # }
1479
+ # """)(items, obj.increment)
1480
+ # assert result == 3
1331
1481
1332
1482
#flat
1333
1483
def test_flat ():
@@ -1442,7 +1592,25 @@ class Counter {
1442
1592
}
1443
1593
"""
1444
1594
)(result , items )
1445
- assert result == [3 ]
1595
+ assert result == [3 ]
1596
+
1597
+ #def test_flatMap_self():
1598
+ # items = ['Four', 'Three', 'One']
1599
+ # class Counter:
1600
+ # def __init__(self):
1601
+ # self.count = 0
1602
+ # def increment(self):
1603
+ # self.count += 1
1604
+
1605
+ # obj = Counter()
1606
+ # result = pm.eval("""
1607
+ # (arr, increment, result) => {
1608
+ # let jsObj = {count: 0}
1609
+ # arr.flatMap(increment, jsObj);
1610
+ # return jsObj.count;
1611
+ # }
1612
+ # """)(items, obj.increment)
1613
+ # assert result == 3
1446
1614
1447
1615
#valueOf
1448
1616
def test_valueOf ():
0 commit comments