Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Cannot retrieve contributors at this time

75 lines (59 sloc) 1.604 kb
require 'test/unit'
require 'parse_tree_oh'
require 'activesupport'
class ParseTreeOrderedHashTest < Test::Unit::TestCase
class OrderedHash < ActiveSupport::OrderedHash
def inspect
super =~ /\A.+?(\{.+\})[^}]+\Z/
$1
end
end
def test_locals
a = 5
h = H{{ a => :hi }}
assert_equal({5 => :hi}, h)
h = H{{ :hi => a }}
assert_equal({:hi => 5}, h)
end
def meth(*a)
if a.empty?
:meth
else
:"meth#{a.inspect}"
end
end
def hash(*hashes)
hashes.map {|h| h.keys*',' }*','
end
def test_methods
h = H{{ meth => :hi }}
assert_equal({:meth => :hi}, h)
h = H{{ :hi => meth }}
assert_equal({:hi => :meth}, h)
h = H{{ :hi => meth(1,2,3) }}
assert_equal({:hi => :"meth[1, 2, 3]"}, h)
h = H{{ :hi => meth(1=>2) }}
assert_equal({:hi => :"meth[{1=>2}]"}, h)
h = H{{ :hi => meth(*[1, 2, 3]) }}
assert_equal({:hi => :"meth[1, 2, 3]"}, h)
end
def test_methods_with_hash_params
h = H{{ hash(1=>2, 3=>4) => hash(3=>4, 1=>2) }}
assert_equal({ '1,3' => '3,1'}, h)
h = H{{ 0 => hash({1=>2, 3=>4}, {5=>6, 7=>8}) }}
assert_equal({ 0 => '1,3,5,7'}, h)
end
def test_plain
h = H{{ 1 => :two, 'three' => 4, :five => :six }}
assert_equal({1=>:two, 'three'=>4, :five => :six}, h)
end
def test_nested_objects
h = H{{ :a => [1, 2, 3] }}
assert_equal({ :a => [1,2,3] }, h)
h = H{{ :a => {1=>2} }}
assert_equal({ :a => {1=>2} }, h)
a = 55
h = H{{ :a => {1=>[2,3,4,{a=>meth}]} }}
assert_equal({ :a => {1=>[2,3,4,{55=>:meth}]} }, h)
end
end
Jump to Line
Something went wrong with that request. Please try again.