Skip to content

Commit

Permalink
Implemented __len__ for sets, frozensets and dicts
Browse files Browse the repository at this point in the history
  • Loading branch information
krtk6160 committed May 25, 2017
1 parent eeffcf1 commit 9b9b495
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 4 deletions.
4 changes: 4 additions & 0 deletions batavia/types/Dict.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,10 @@ Dict.prototype.toString = function() {
* Type conversions
**************************************************/

Dict.prototype.__len__ = function() {
return this.size
}

Dict.prototype.__bool__ = function() {
return this.size > 0
}
Expand Down
4 changes: 4 additions & 0 deletions batavia/types/FrozenSet.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ FrozenSet.prototype.toString = function() {
* Type conversions
**************************************************/

FrozenSet.prototype.__len__ = function() {
return this.data.size
}

FrozenSet.prototype.__bool__ = function() {
return this.data.__bool__()
}
Expand Down
4 changes: 4 additions & 0 deletions batavia/types/Set.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ Set.prototype.toString = function() {
* Type conversions
**************************************************/

Set.prototype.__len__ = function() {
return this.data.size
}

Set.prototype.__bool__ = function() {
return this.data.__bool__()
}
Expand Down
3 changes: 0 additions & 3 deletions tests/builtins/test_len.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,4 @@ class BuiltinLenFunctionTests(BuiltinFunctionTestCase, TranspileTestCase):

not_implemented = [
'test_bytearray',
'test_dict',
'test_frozenset',
'test_set',
]
1 change: 0 additions & 1 deletion tests/structures/test_set_comprehension.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@


class SetComprehensionTests(TranspileTestCase):
@unittest.expectedFailure
def test_syntax(self):
self.assertCodeExecution("""
x = [1, 2, 3, 4, 5]
Expand Down

0 comments on commit 9b9b495

Please sign in to comment.