Sha256: ed6c058f41584bf4d7a931283d6653d6bba1ea9c7fef6f3387b67cbc8b110af2

Contents?: true

Size: 1.46 KB

Versions: 23

Compression:

Stored size: 1.46 KB

Contents

describe "The '&&' statement" do
  it "short-circuits evaluation at the first condition to be false" do
    x = nil
    true && false && x = 1
    x.should be_nil
  end

  it "evaluates to the first condition not to be true" do
    ("yes" && 1 && nil && true).should == nil
    ("yes" && 1 && false && true).should == false
  end

  it "evaluates to the last condition if all are true" do
    ("yes" && 1).should == 1
    (1 && "yes").should == "yes"
  end

  it "evaluates the full set of chained conditions during assignment" do
    x = y = nil
    x = 1 && y = 2
    x.should == 2
  end

  it "treats empty expressions as nil" do
    (() && true).should be_nil
    (true && ()).should be_nil
    (() && ()).should be_nil
  end
end

describe "The 'and' statement" do
  it "short-circuits evaluation at the first condition to be false" do
    x = nil
    true and false and x = 1
    x.should be_nil
  end

  it "evaluates to the first condition not to be true" do
    ("yes" and 1 and nil and true).should == nil
    ("yes" and 1 and false and true).should == false
  end

  it "evaluates to the last condition if all are true" do
    ("yes" and 1).should == 1
    (1 and "yes").should == "yes"
  end

  it "when used in assignment, evaluates and assigns expressions individually" do
    x = y = nil
    x = 1 and y = 2
    x.should == 1
  end

  it "treats empty expressions as nil" do
    (() and true).should be_nil
    (true and ()).should be_nil
    (() and ()).should be_nil
  end
end

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
opal-0.3.41 spec/language/and_spec.rb
opal-0.3.40 spec/language/and_spec.rb
opal-0.3.39 spec/language/and_spec.rb
opal-0.3.38 spec/language/and_spec.rb
opal-0.3.37 spec/language/and_spec.rb
opal-0.3.36 spec/language/and_spec.rb
opal-0.3.35 spec/language/and_spec.rb
opal-0.3.34 spec/language/and_spec.rb
opal-0.3.33 spec/language/and_spec.rb
opal-0.3.32 spec/language/and_spec.rb
opal-0.3.31 spec/language/and_spec.rb
opal-0.3.30 spec/language/and_spec.rb
opal-0.3.29 spec/language/and_spec.rb
opal-0.3.28 spec/language/and_spec.rb
opal-0.3.27 spec/language/and_spec.rb
opal-0.3.26 spec/language/and_spec.rb
opal-0.3.25 spec/language/and_spec.rb
opal-0.3.22 spec/language/and_spec.rb
opal-0.3.21 test/language/and_spec.rb
opal-0.3.20 test/language/and_spec.rb