github
Advanced Search
  • Home
  • Pricing and Signup
  • Explore GitHub
  • Blog
  • Login

coderrr / ordered_hash_syntax

  • Admin
  • Watch Unwatch
  • Fork
  • Your Fork
  • Pull Request
  • Download Source
    • 4
    • 1
  • Source
  • Commits
  • Network (1)
  • Issues (0)
  • Downloads (0)
  • Wiki (1)
  • Graphs
  • Branch: master

click here to add a description

click here to add a homepage

  • Branches (1)
    • master ✓
  • Tags (0)
Sending Request…
Enable Donations

Pledgie Donations

Once activated, we'll place the following badge in your repository's detail box:
Pledgie_example
This service is courtesy of Pledgie.

various ordered hash syntax experiments for ruby 1.8 — Read more

  cancel

  cancel
  • Private
  • Read-Only
  • HTTP Read-Only

This URL has Read+Write access

added new faster parse tree based ordered hash 
coderrr (author)
Sat Jul 25 04:09:34 -0700 2009
commit  940b3f94f00c88bc07aca8028b269572269ce1ea
tree    7bba8cf4f20fe8181a18eeabd52559aec4a1cb0b
parent  0a1b5fc5d67452ce47a8f85c4546f4e74cdbb53d
ordered_hash_syntax / parse_tree_oh_test.rb parse_tree_oh_test.rb
100644 75 lines (59 sloc) 1.604 kb
edit raw blame history
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
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
 
Blog | Support | Training | Contact | API | Status | Twitter | Help | Security
© 2010 GitHub Inc. All rights reserved. | Terms of Service | Privacy Policy
Powered by the Dedicated Servers and
Cloud Computing of Rackspace Hosting®
Dedicated Server