Sha256: 5764175600829143f5ef2d13f59d02c55e00667eb118481bb8495dacc1f8ed14

Contents?: true

Size: 1011 Bytes

Versions: 39

Compression:

Stored size: 1011 Bytes

Contents

require 'support/parser_helpers'

describe "The if keyword" do
  it "should return an s(:if) with given truthy and falsy bodies" do
    parsed("if 1; 2; else; 3; end").should == [:if, [:int, 1], [:int, 2], [:int, 3]]
  end

  it "uses nil as fasly body if not given else-then" do
    parsed("if 1; 2; end").should == [:if, [:int, 1], [:int, 2], nil]
  end

  it "is treats elsif parts as sub if expressions for else body" do
    parsed("if 1; 2; elsif 3; 4; else; 5; end").should == [:if, [:int, 1], [:int, 2], [:if, [:int, 3], [:int, 4], [:int, 5]]]
    parsed("if 1; 2; elsif 3; 4; end").should == [:if, [:int, 1], [:int, 2], [:if, [:int, 3], [:int, 4], nil]]
  end

  it "returns a simple s(:if) with nil else body for prefix if statement" do
    parsed("1 if 2").should == [:if, [:int, 2], [:int, 1], nil]
  end
end

describe "The ternary operator" do
  it "gets converted into an if statement with true and false parts" do
    parsed("1 ? 2 : 3").should == [:if, [:int, 1], [:int, 2], [:int, 3]]
  end
end

Version data entries

39 entries across 39 versions & 3 rubygems

Version Path
opal-0.10.6 spec/lib/parser/if_spec.rb
opal-0.10.6.beta spec/lib/parser/if_spec.rb
opal-0.10.5 spec/lib/parser/if_spec.rb
opal-0.10.4 spec/lib/parser/if_spec.rb
opal-0.10.3 spec/lib/parser/if_spec.rb
opal-0.10.2 spec/lib/parser/if_spec.rb
opal-0.10.1 spec/lib/parser/if_spec.rb
opal-0.10.0 spec/lib/parser/if_spec.rb
opal-0.10.0.rc2 spec/lib/parser/if_spec.rb
opal-0.9.4 spec/lib/parser/if_spec.rb
opal-0.9.3 spec/lib/parser/if_spec.rb
opal-0.10.0.rc1 spec/lib/parser/if_spec.rb
opal-0.10.0.beta5 spec/lib/parser/if_spec.rb
opal-0.10.0.beta4 spec/lib/parser/if_spec.rb
opal-0.10.0.beta3 spec/lib/parser/if_spec.rb
opal-0.10.0.beta2 spec/lib/parser/if_spec.rb
opal-0.10.0.beta1 spec/lib/parser/if_spec.rb
opal-0.9.2 spec/lib/parser/if_spec.rb
opal-0.9.0 spec/lib/parser/if_spec.rb
opal-0.9.0.rc1 spec/lib/parser/if_spec.rb