Last active

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist

Unit tests for my symbol.patch (https://gist.github.com/phluid61/5105345)

View test_symbol_lookup.rb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
require 'test/unit'
 
class TestSymbolLookup < Test::Unit::TestCase # :nodoc:
def test_success
syms = Hash[ *Symbol.all_symbols.map{|s| [s.to_s, s] }.flatten ]
defined_str = syms.keys.first
defined_sym = syms[defined_str]
undef_str = 'undefined symbol'
# ensure the undefined symbol really is undefined
while syms.has_key? undef_str
undef_str << 'X'
end
 
assert_equal( defined_sym, Symbol[defined_str] )
assert_equal( defined_sym, Symbol[defined_sym] ) # with warning?
assert_nil( Symbol[undef_str] )
end
 
def test_failure
assert_raise(TypeError) { Symbol[1] } # TypeError: 1 is not a symbol
assert_raise(ArgumentError) { Symbol[] } # ArgumentError: wrong number of arguments (0 for 1)
assert_raise(ArgumentError) { Symbol['a','b'] } # ArgumentError: wrong number of arguments (2 for 1)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.