| 1791 | |
| 1792 | |
| 1793 | def test_every_self_pymethod(): |
| 1794 | items = ['Four', 'Three', 'One'] |
| 1795 | |
| 1796 | class Counter: |
| 1797 | def __init__(self): |
| 1798 | self.count = 0 |
| 1799 | |
| 1800 | def increment(self, element, index, array): |
| 1801 | self.count += 1 |
| 1802 | return True |
| 1803 | |
| 1804 | obj = Counter() |
| 1805 | assert obj.count == 0 |
| 1806 | result = pm.eval(""" |
| 1807 | (arr, increment, result) => { |
| 1808 | let jsObj = {count: 0} |
| 1809 | arr.every(increment, jsObj); |
| 1810 | return jsObj.count; |
| 1811 | } |
| 1812 | """)(items, obj.increment) |
| 1813 | assert obj.count == 0 |
| 1814 | assert result == 3 |
| 1815 | |
| 1816 | |
| 1817 | def test_every_self_pyfunction(): |