Sha256: 6ba4b7ce94ee9d911a1d425552b7b7eeb2499a606be571f33834c1a446717404

Contents?: true

Size: 1.26 KB

Versions: 8

Compression:

Stored size: 1.26 KB

Contents

describe "Opal::Parser" do
  it "should parse simple ruby values" do
    opal_eval('3.142').should == 3.142
    opal_eval('123e1').should == 1230.0
    opal_eval('123E+10').should == 1230000000000.0
    opal_eval('123e-9').should == 0.000000123
    opal_eval('false').should == false
    opal_eval('true').should == true
    opal_eval('nil').should == nil
  end

  it "should parse ruby strings" do
    opal_eval('"hello world"').should == "hello world"
    opal_eval('"hello #{100}"').should == "hello 100"
  end

  it "should parse method calls" do
    opal_eval("[1, 2, 3, 4].inspect").should == "[1, 2, 3, 4]"
    opal_eval("[1, 2, 3, 4].map { |a| a + 42 }").should == [43, 44, 45, 46]
  end

  it "should parse constant lookups" do
    opal_eval("Object").should == Object
    opal_eval("Array").should == Array
    opal_eval("OpalSpec::ExampleGroup").should == OpalSpec::ExampleGroup
  end

  it "should parse class and module definitions" do
    opal_eval("class ParserModuleDefinition; end")
    opal_eval <<-STR
      class ParserClassDefinition
        CONSTANT = 500

        def foo
          500
        end

        def self.bar
          42
        end
      end
    STR

    ParserClassDefinition.bar.should == 42
    ParserClassDefinition.new.foo.should == 500
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
opal-0.3.37 spec/grammar/parser_spec.rb
opal-0.3.36 spec/grammar/parser_spec.rb
opal-0.3.35 spec/grammar/parser_spec.rb
opal-0.3.34 spec/parser/simple_spec.rb
opal-0.3.33 spec/parser/simple_spec.rb
opal-0.3.32 spec/parser/simple_spec.rb
opal-0.3.31 spec/parser/simple_spec.rb
opal-0.3.30 spec/parser/simple_spec.rb