Sha256: 055eab62af9c58a1ad538eb2f272efdb02f762d681496d4264416cd4bae13747

Contents?: true

Size: 1.92 KB

Versions: 83

Compression:

Stored size: 1.92 KB

Contents

require File.dirname(File.join(__rhoGetCurrentDir(), __FILE__)) + '/../spec_helper'

describe "A Symbol literal" do
  it "is a ':' followed by any number of valid characters" do
    a = :foo
    a.should be_kind_of(Symbol)
    a.inspect.should == ':foo'
  end

  it "is a ':' followed by any valid variable, method, or constant name" do
    # Add more of these?
    [ :Foo,
      :foo,
      :@foo,
      :@@foo,
      :$foo,
      :_,
      :~,
      :- ,
      :FOO,
      :_Foo,
      :&,
      :_9
    ].each { |s| s.should be_kind_of(Symbol) }
  end

  it "is a ':' followed by a single- or double-quoted string that may contain otherwise invalid characters" do
    [ [:'foo bar',      ':"foo bar"'],
      [:'++',           ':"++"'],
      [:'9',            ':"9"'],
      [:"foo #{1 + 1}", ':"foo 2"'],
    ].each { |sym, str| 
      sym.should be_kind_of(Symbol)
      sym.inspect.should == str
    }
  end

  it "may contain '::' in the string" do
    :'Some::Class'.should be_kind_of(Symbol)
  end

  it "is converted to a literal, unquoted representation if the symbol contains only valid characters" do
    a, b, c = :'foo', :'+', :'Foo__9'
    a.class.should == Symbol
    a.inspect.should == ':foo'
    b.class.should == Symbol
    b.inspect.should == ':+'
    c.class.should == Symbol
    c.inspect.should == ':Foo__9'
  end

  it "can be created by the %s-delimited expression" do
    a, b = :'foo bar', %s{foo bar}
    b.class.should == Symbol
    b.inspect.should == ':"foo bar"'
    b.should == a
  end

  it "is the same object when created from identical strings" do
    var = "@@var"
    [ [:symbol, :symbol],
      [:'a string', :'a string'],
      [:"#{var}", :"#{var}"]
    ].each { |a, b|
      a.should equal(b)
    }
  end

# XXX eval not supported
#  it "does not contain null in the string" do
#    lambda { eval ':"\0" ' }.should raise_error(SyntaxError)
#  end
end

language_version File.join(__rhoGetCurrentDir(), __FILE__), 'symbol'

Version data entries

83 entries across 83 versions & 1 rubygems

Version Path
rhodes-3.1.1 spec/framework_spec/app/spec/language/symbol_spec.rb
rhodes-3.1.1.beta spec/framework_spec/app/spec/language/symbol_spec.rb
rhodes-3.1.0 spec/framework_spec/app/spec/language/symbol_spec.rb
rhodes-3.1.0.beta.5 spec/framework_spec/app/spec/language/symbol_spec.rb
rhodes-3.1.0.beta.4 spec/framework_spec/app/spec/language/symbol_spec.rb
rhodes-3.1.0.beta.3 spec/framework_spec/app/spec/language/symbol_spec.rb
rhodes-3.1.0.beta.2 spec/framework_spec/app/spec/language/symbol_spec.rb
rhodes-3.1.0.beta.1 spec/framework_spec/app/spec/language/symbol_spec.rb
rhodes-3.0.2 spec/framework_spec/app/spec/language/symbol_spec.rb
rhodes-3.0.2.beta.1 spec/framework_spec/app/spec/language/symbol_spec.rb
rhodes-3.0.1 spec/framework_spec/app/spec/language/symbol_spec.rb
rhodes-3.0.1.beta.8 spec/framework_spec/app/spec/language/symbol_spec.rb
rhodes-3.0.1.beta.7 spec/framework_spec/app/spec/language/symbol_spec.rb
rhodes-3.0.1.beta.6 spec/framework_spec/app/spec/language/symbol_spec.rb
rhodes-3.0.1.beta.5 spec/framework_spec/app/spec/language/symbol_spec.rb
rhodes-3.0.1.beta.4 spec/framework_spec/app/spec/language/symbol_spec.rb
rhodes-3.0.1.beta.3 spec/framework_spec/app/spec/language/symbol_spec.rb
rhodes-3.0.1.beta.2 spec/framework_spec/app/spec/language/symbol_spec.rb
rhodes-3.0.0 spec/framework_spec/app/spec/language/symbol_spec.rb
rhodes-3.0.0.beta.7 spec/framework_spec/app/spec/language/symbol_spec.rb