Skip to content

Commit

Permalink
Merge branch 'master' of github.com:topazproject/topaz
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Gaynor committed May 16, 2013
2 parents b604a23 + 2387d27 commit 5041c4e
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 72 deletions.
1 change: 1 addition & 0 deletions AUTHORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,5 @@ Authors
* David Schneider
* Robin Schreiber
* Jan Stępień
* Andrew Thompson
* Jeremy Thurgood
5 changes: 5 additions & 0 deletions lib-topaz/symbol.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ def capitalize
self.to_s.capitalize.to_sym
end

def [](*args)
self.to_s[*args]
end
alias slice []

def swapcase
self.to_s.swapcase.to_sym
end
Expand Down
1 change: 0 additions & 1 deletion spec/tags/core/basicobject/basicobject_tags.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
fails:BasicObject raises NoMethodError for nonexistent methods after #method_missing is removed
fails:BasicObject raises NameError when referencing built-in constants
fails:BasicObject does not define built-in constants (according to defined?)
fails:BasicObject includes itself in its list of constants
Expand Down
37 changes: 0 additions & 37 deletions spec/tags/core/symbol/element_reference_tags.txt
Original file line number Diff line number Diff line change
@@ -1,36 +1,3 @@
fails:Symbol#[] with an Integer index returns the character code of the element at the index
fails:Symbol#[] with an Integer index returns nil if the index starts from the end and is greater than the length
fails:Symbol#[] with an Integer index returns nil if the index is greater than the length
fails:Symbol#[] with an Integer index and length and a positive index and length returns a slice
fails:Symbol#[] with an Integer index and length and a positive index and length returns a blank slice if the length is 0
fails:Symbol#[] with an Integer index and length and a positive index and length returns a slice of all remaining characters if the given length is greater than the actual length
fails:Symbol#[] with an Integer index and length and a positive index and length returns nil if the index is greater than the length
fails:Symbol#[] with an Integer index and length and a positive index and negative length returns nil
fails:Symbol#[] with an Integer index and length and a negative index and positive length returns a slice starting from the end upto the length
fails:Symbol#[] with an Integer index and length and a negative index and positive length returns a blank slice if the length is 0
fails:Symbol#[] with an Integer index and length and a negative index and positive length returns a slice of all remaining characters if the given length is larger than the actual length
fails:Symbol#[] with an Integer index and length and a negative index and positive length returns nil if the index is past the start
fails:Symbol#[] with an Integer index and length and a negative index and negative length returns nil
fails:Symbol#[] with an Integer index and length and a Float length converts the length to an Integer
fails:Symbol#[] with an Integer index and length and a nil length raises a TypeError
fails:Symbol#[] with an Integer index and length and a length that cannot be converted into an Integer raises a TypeError when given an Array
fails:Symbol#[] with an Integer index and length and a length that cannot be converted into an Integer raises a TypeError when given an Hash
fails:Symbol#[] with an Integer index and length and a length that cannot be converted into an Integer raises a TypeError when given an Object
fails:Symbol#[] with a Float index converts the index to a Integer
fails:Symbol#[] with a nil index raises a TypeError
fails:Symbol#[] with an index that cannot be converted into an Integer raises a TypeError when given an Array
fails:Symbol#[] with an index that cannot be converted into an Integer raises a TypeError when given an Hash
fails:Symbol#[] with an index that cannot be converted into an Integer raises a TypeError when given an Object
fails:Symbol#[] with a Range slice that is within bounds returns a slice if both range values begin at the start and are within bounds
fails:Symbol#[] with a Range slice that is within bounds returns a slice if the first range value begins at the start and the last begins at the end
fails:Symbol#[] with a Range slice that is within bounds returns a slice if the first range value begins at the end and the last begins at the end
fails:Symbol#[] with a Range slice that is out of bounds returns nil if the first range value begins past the end
fails:Symbol#[] with a Range slice that is out of bounds returns a blank string if the first range value is within bounds and the last range value is not
fails:Symbol#[] with a Range slice that is out of bounds returns nil if the first range value starts from the end and is within bounds and the last value starts from the end and is greater than the length
fails:Symbol#[] with a Range slice that is out of bounds returns nil if the first range value starts from the end and is out of bounds and the last value starts from the end and is less than the length
fails:Symbol#[] with a Range slice with Float values converts the first value to an Integer
fails:Symbol#[] with a Range slice with Float values converts the last value to an Integer
fails:Symbol#[] with a Range subclass slice returns a slice
fails:Symbol#[] with a Regex slice without a capture index returns a string of the match
fails:Symbol#[] with a Regex slice without a capture index returns nil if the expression does not match
fails:Symbol#[] with a Regex slice without a capture index sets $~ to the MatchData if there is a match
Expand All @@ -39,12 +6,8 @@ fails:Symbol#[] with a Regex slice with a capture index returns a string of the
fails:Symbol#[] with a Regex slice with a capture index returns a string for the matched capture at the given index
fails:Symbol#[] with a Regex slice with a capture index returns nil if there is no capture for the index
fails:Symbol#[] with a Regex slice with a capture index converts the index to an Integer
fails:Symbol#[] with a Regex slice with a capture index raises a TypeError if the index is nil
fails:Symbol#[] with a Regex slice with a capture index sets $~ to the MatchData if there is a match
fails:Symbol#[] with a Regex slice with a capture index does not set $~ to the MatchData if there is not a match
fails:Symbol#[] with a Regex slice with a capture index and an index that cannot be converted to an Integer raises a TypeError when given an Hash
fails:Symbol#[] with a Regex slice with a capture index and an index that cannot be converted to an Integer raises a TypeError when given an Array
fails:Symbol#[] with a Regex slice with a capture index and an index that cannot be converted to an Integer raises a TypeError when given an Object
fails:Symbol#[] with a String slice does not set $~
fails:Symbol#[] with a String slice returns a string if there is match
fails:Symbol#[] with a String slice returns nil if there is not a match
31 changes: 0 additions & 31 deletions spec/tags/core/symbol/slice_tags.txt
Original file line number Diff line number Diff line change
@@ -1,36 +1,9 @@
fails:Symbol#slice with an Integer index returns the character code of the element at the index
fails:Symbol#slice with an Integer index returns nil if the index starts from the end and is greater than the length
fails:Symbol#slice with an Integer index returns nil if the index is greater than the length
fails:Symbol#slice with an Integer index and length and a positive index and length returns a slice
fails:Symbol#slice with an Integer index and length and a positive index and length returns a blank slice if the length is 0
fails:Symbol#slice with an Integer index and length and a positive index and length returns a slice of all remaining characters if the given length is greater than the actual length
fails:Symbol#slice with an Integer index and length and a positive index and length returns nil if the index is greater than the length
fails:Symbol#slice with an Integer index and length and a positive index and negative length returns nil
fails:Symbol#slice with an Integer index and length and a negative index and positive length returns a slice starting from the end upto the length
fails:Symbol#slice with an Integer index and length and a negative index and positive length returns a blank slice if the length is 0
fails:Symbol#slice with an Integer index and length and a negative index and positive length returns a slice of all remaining characters if the given length is larger than the actual length
fails:Symbol#slice with an Integer index and length and a negative index and positive length returns nil if the index is past the start
fails:Symbol#slice with an Integer index and length and a negative index and negative length returns nil
fails:Symbol#slice with an Integer index and length and a Float length converts the length to an Integer
fails:Symbol#slice with an Integer index and length and a nil length raises a TypeError
fails:Symbol#slice with an Integer index and length and a length that cannot be converted into an Integer raises a TypeError when given an Array
fails:Symbol#slice with an Integer index and length and a length that cannot be converted into an Integer raises a TypeError when given an Hash
fails:Symbol#slice with an Integer index and length and a length that cannot be converted into an Integer raises a TypeError when given an Object
fails:Symbol#slice with a Float index converts the index to a Integer
fails:Symbol#slice with a nil index raises a TypeError
fails:Symbol#slice with an index that cannot be converted into an Integer raises a TypeError when given an Array
fails:Symbol#slice with an index that cannot be converted into an Integer raises a TypeError when given an Hash
fails:Symbol#slice with an index that cannot be converted into an Integer raises a TypeError when given an Object
fails:Symbol#slice with a Range slice that is within bounds returns a slice if both range values begin at the start and are within bounds
fails:Symbol#slice with a Range slice that is within bounds returns a slice if the first range value begins at the start and the last begins at the end
fails:Symbol#slice with a Range slice that is within bounds returns a slice if the first range value begins at the end and the last begins at the end
fails:Symbol#slice with a Range slice that is out of bounds returns nil if the first range value begins past the end
fails:Symbol#slice with a Range slice that is out of bounds returns a blank string if the first range value is within bounds and the last range value is not
fails:Symbol#slice with a Range slice that is out of bounds returns nil if the first range value starts from the end and is within bounds and the last value starts from the end and is greater than the length
fails:Symbol#slice with a Range slice that is out of bounds returns nil if the first range value starts from the end and is out of bounds and the last value starts from the end and is less than the length
fails:Symbol#slice with a Range slice with Float values converts the first value to an Integer
fails:Symbol#slice with a Range slice with Float values converts the last value to an Integer
fails:Symbol#slice with a Range subclass slice returns a slice
fails:Symbol#slice with a Regex slice without a capture index returns a string of the match
fails:Symbol#slice with a Regex slice without a capture index returns nil if the expression does not match
fails:Symbol#slice with a Regex slice without a capture index sets $~ to the MatchData if there is a match
Expand All @@ -39,12 +12,8 @@ fails:Symbol#slice with a Regex slice with a capture index returns a string of t
fails:Symbol#slice with a Regex slice with a capture index returns a string for the matched capture at the given index
fails:Symbol#slice with a Regex slice with a capture index returns nil if there is no capture for the index
fails:Symbol#slice with a Regex slice with a capture index converts the index to an Integer
fails:Symbol#slice with a Regex slice with a capture index raises a TypeError if the index is nil
fails:Symbol#slice with a Regex slice with a capture index sets $~ to the MatchData if there is a match
fails:Symbol#slice with a Regex slice with a capture index does not set $~ to the MatchData if there is not a match
fails:Symbol#slice with a Regex slice with a capture index and an index that cannot be converted to an Integer raises a TypeError when given an Hash
fails:Symbol#slice with a Regex slice with a capture index and an index that cannot be converted to an Integer raises a TypeError when given an Array
fails:Symbol#slice with a Regex slice with a capture index and an index that cannot be converted to an Integer raises a TypeError when given an Object
fails:Symbol#slice with a String slice does not set $~
fails:Symbol#slice with a String slice returns a string if there is match
fails:Symbol#slice with a String slice returns nil if there is not a match
1 change: 1 addition & 0 deletions topaz/objects/stringobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,7 @@ def method_hash(self, space):
return space.newint(self.strategy.hash(self.str_storage))

@classdef.method("[]")
@classdef.method("slice")
def method_subscript(self, space, w_idx, w_count=None):
start, end, as_range, nil = space.subscript_access(self.length(), w_idx, w_count=w_count)
if nil:
Expand Down
11 changes: 8 additions & 3 deletions topaz/objspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -585,9 +585,14 @@ def send_super(self, w_cls, w_receiver, name, args_w, block=None):
def _send_raw(self, name, raw_method, w_receiver, w_cls, args_w, block):
if raw_method is None:
method_missing = w_cls.find_method(self, "method_missing")
assert method_missing is not None
args_w.insert(0, self.newsymbol(name))
return method_missing.call(self, w_receiver, args_w, block)
if method_missing is None:
class_name = self.str_w(self.send(w_cls, "to_s"))
raise self.error(self.w_NoMethodError,
"undefined method `%s' for %s" % (name, class_name)
)
else:
args_w.insert(0, self.newsymbol(name))
return method_missing.call(self, w_receiver, args_w, block)
return raw_method.call(self, w_receiver, args_w, block)

def respond_to(self, w_receiver, name):
Expand Down

0 comments on commit 5041c4e

Please sign in to comment.