add language/hash spec

This commit is contained in:
Laurent Sansonetti
2014-04-11 20:01:04 +02:00
parent 497f969891
commit ec989dda83
3 changed files with 80 additions and 0 deletions

View File

@@ -12,5 +12,12 @@ Motion::Project::App.setup do |app|
# Make sure the main file is compiled and executed first.
ary = app.files
ary.delete('./app/main.rb')
if files = ENV['files']
files = files.split(',')
ary.delete_if do |path|
base = File.basename(path)
!files.any? { |x| base.include?(x) }
end
end
ary.unshift('./app/main.rb')
end

View File

@@ -0,0 +1,19 @@
describe "Hash literal" do
describe 'new-style hash syntax' do
it 'constructs a new hash with the given elements' do
{foo: 123}.should == {:foo => 123}
{rbx: :cool, specs: 'fail_sometimes'}.should == {:rbx => :cool, :specs => 'fail_sometimes'}
end
it 'ignores a hanging comma' do
{foo: 123,}.should == {:foo => 123}
{rbx: :cool, specs: 'fail_sometimes',}.should == {:rbx => :cool, :specs => 'fail_sometimes'}
end
it 'can mix and match syntax styles' do
{rbx: :cool, :specs => 'fail_sometimes'}.should == {:rbx => :cool, :specs => 'fail_sometimes'}
{'rbx' => :cool, specs: 'fail_sometimes'}.should == {'rbx' => :cool, :specs => 'fail_sometimes'}
end
end
end

View File

@@ -0,0 +1,54 @@
describe "Hash literal" do
it "{} should return an empty hash" do
{}.size.should == 0
{}.should == {}
end
it "{} should return a new hash populated with the given elements" do
h = {:a => 'a', 'b' => 3, 44 => 2.3}
h.size.should == 3
h.should == {:a => "a", "b" => 3, 44 => 2.3}
end
it "treats empty expressions as nils" do
h = {() => ()}
h.keys.should == [nil]
h.values.should == [nil]
h[nil].should == nil
h = {() => :value}
h.keys.should == [nil]
h.values.should == [:value]
h[nil].should == :value
h = {:key => ()}
h.keys.should == [:key]
h.values.should == [nil]
h[:key].should == nil
end
=begin
# We do not support freeze.
it "freezes string keys on initialization" do
key = "foo"
h = {key => "bar"}
key.reverse!
h["foo"].should == "bar"
h.keys.first.should == "foo"
h.keys.first.frozen?.should == true
key.should == "oof"
end
=end
it "checks duplicated keys on initialization" do
h = {:foo => :bar, :foo => :foo}
h.keys.size.should == 1
h.should == {:foo => :foo}
end
it "accepts a hanging comma" do
h = {:a => 1, :b => 2,}
h.size.should == 2
h.should == {:a => 1, :b => 2}
end
end