Skip to content

Commit

Permalink
implements "" % other for each of the other types: bytearray, cla…
Browse files Browse the repository at this point in the history
…ss, complex, dict, frozenset, list
  • Loading branch information
fmoor committed Jun 3, 2016
1 parent b6fdf00 commit fd85a49
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion batavia/types/Str.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ String.prototype.__mul__ = function(other) {
};

String.prototype.__mod__ = function(other) {
if (batavia.isinstance(other, [batavia.types.List, batavia.types.Tuple])) {
if (batavia.isinstance(other, batavia.types.Tuple)) {
return batavia._substitute(this, other);
} else {
return batavia._substitute(this, [other]);
Expand Down
8 changes: 7 additions & 1 deletion batavia/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,12 @@ batavia.isinstance = function(obj, type) {
/*************************************************************************
* sprintf() implementation
*************************************************************************/

batavia._substitute = function(format, args) {
var results = [];
var special_case_types = [
batavia.types.List,
batavia.types.Dict,
batavia.types.Bytes];

/* This is the general form regex for a sprintf-like string. */
var re = /\x25(?:([1-9]\d*)\$|\(([^\)]+)\))?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-gijosuxX])/g;
Expand Down Expand Up @@ -97,6 +100,9 @@ batavia._substitute = function(format, args) {
results.push(format.slice(lastIndex, match.index));
lastIndex = re.lastIndex;
results.push(arg);
} else if ( (args.constructor == Array)
&& batavia.isinstance(args[0], special_case_types)) {
return format
} else {
throw new batavia.builtins.TypeError('not all arguments converted during string formatting');
}
Expand Down
6 changes: 0 additions & 6 deletions tests/datatypes/test_str.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,13 +189,7 @@ class BinaryStrOperationTests(BinaryOperationTestCase, TranspileTestCase):
'test_lt_set',
'test_lt_tuple',

'test_modulo_bytearray',
'test_modulo_bytes',
'test_modulo_class',
'test_modulo_complex',
'test_modulo_dict',
'test_modulo_frozenset',
'test_modulo_list',
'test_modulo_set',

'test_multiply_bytearray',
Expand Down

0 comments on commit fd85a49

Please sign in to comment.