1 require File.dirname(__FILE__) + '/../spec_helper'
3 describe "A Symbol literal" do
4 it "is a ':' followed by any number of valid characters" do
6 a.should be_kind_of(Symbol)
7 a.inspect.should == ':foo'
10 it "is a ':' followed by any valid variable, method, or constant name" do
24 ].each { |s| s.should be_kind_of(Symbol) }
27 it "is a ':' followed by a single- or double-quoted string that may contain otherwise invalid characters" do
28 [ [:'foo bar', ':"foo bar"'],
31 [:"foo #{1 + 1}", ':"foo 2"'],
33 sym.should be_kind_of(Symbol)
34 sym.inspect.should == str
38 it "may contain '::' in the string" do
39 :'Some::Class'.should be_kind_of(Symbol)
42 it "is converted to a literal, unquoted representation if the symbol contains only valid characters" do
43 a, b, c = :'foo', :'+', :'Foo__9'
44 a.class.should == Symbol
45 a.inspect.should == ':foo'
46 b.class.should == Symbol
47 b.inspect.should == ':+'
48 c.class.should == Symbol
49 c.inspect.should == ':Foo__9'
52 it "must not be an empty string" do
53 lambda { eval ":''" }.should raise_error(SyntaxError)
56 it "can be created by the %s-delimited expression" do
57 a, b = :'foo bar', %s{foo bar}
58 b.class.should == Symbol
59 b.inspect.should == ':"foo bar"'
63 it "is the same object when created from identical strings" do
66 [:'a string', :'a string'],
67 [:"#{var}", :"#{var}"]