Sha256: da5abe36c0473680978f27b2e7c2b35d860cc8d8c6a60643598acf8e46738558

Contents?: true

Size: 1.47 KB

Versions: 3

Compression:

Stored size: 1.47 KB

Contents

require "test/unit"
require File.dirname(__FILE__) + "/../lib/faye"

class TestChannel < Test::Unit::TestCase
  include Faye
  
  def test_channel_storage
    tree = Channel::Tree.new
    tree['invalid/name']    = 1
    tree['/valid/name']     = 2
    tree['/va()$$lid/name'] = 3
    
    assert_equal nil, tree['invalid/name']
    assert_equal 2,   tree['/valid/name']
    assert_equal 3,   tree['/va()$$lid/name']
  end
  
  def test_keys
    tree = Channel::Tree.new
    tree['/foo'] = tree['/bar'] = tree['/foo/bar'] = true
    assert_equal %w[/bar /foo /foo/bar], tree.keys.sort
  end
  
  def test_removal
    tree = Channel::Tree.new
    tree['/foo'] = tree['/bar'] = tree['/foo/bar'] = true
    
    tree.remove('/foo/bar')
    assert_equal %w[/bar /foo], tree.keys.sort
  end
  
  def test_globbing
    tree = Channel::Tree.new
    tree['/foo/bar']     = 1
    tree['/foo/boo']     = 2
    tree['/foo']         = 3
    tree['/foobar']      = 4
    tree['/foo/bar/boo'] = 5
    tree['/foobar/boo']  = 6
    tree['/foo/*']       = 7
    tree['/foo/**']      = 8
    
    assert_equal  [1,2,7,8],    tree.glob('/foo/*').sort
    assert_equal  [1,7,8],      tree.glob('/foo/bar').sort
    assert_equal  [1,2,5,7,8],  tree.glob('/foo/**').sort
    assert_equal  [5,8],        tree.glob('/foo/bar/boo').sort
    
    tree['/channels/hello'] = 'A'
    tree['/channels/name'] = 'B'
    tree['/channels/nested/hello'] = 'C'
    
    assert_equal %w[A B C],     tree.glob('/channels/**').sort
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
faye-0.5.5 test/test_channel.rb
faye-0.5.4 test/test_channel.rb
faye-0.5.3 test/test_channel.rb