Sha256: 7dba4b84bb7cf5664a3a538faa3e453a2b6aac96a9505762eb47e1c0956bb2df

Contents?: true

Size: 1 KB

Versions: 26

Compression:

Stored size: 1 KB

Contents

require 'spec_helper'

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

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

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

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

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

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
opal-0.4.3 spec/parser/if_spec.rb
opal-0.4.2 spec/parser/if_spec.rb
opal-0.4.1 spec/parser/if_spec.rb
opal-0.4.0 spec/parser/if_spec.rb
opal-0.3.44 spec/parser/if_spec.rb
opal-0.3.43 spec/parser/if_spec.rb
opal-0.3.42 spec/grammar/if_spec.rb
opal-0.3.41 spec/grammar/if_spec.rb
opal-0.3.40 spec/grammar/if_spec.rb
opal-0.3.39 spec/grammar/if_spec.rb
opal-0.3.38 spec/grammar/if_spec.rb
opal-0.3.37 spec/grammar/if_spec.rb
opal-0.3.36 spec/grammar/if_spec.rb
opal-0.3.35 spec/grammar/if_spec.rb
opal-0.3.34 spec/grammar/if_spec.rb
opal-0.3.33 spec/grammar/if_spec.rb
opal-0.3.32 spec/grammar/if_spec.rb
opal-0.3.31 spec/grammar/if_spec.rb
opal-0.3.30 spec/grammar/if_spec.rb
opal-0.3.29 spec/grammar/if_spec.rb