require File.expand_path('../spec_helper', __FILE__)

describe Opal::Compiler do
  it "should compile simple ruby values" do
    expect_compiled("3.142").to include("return 3.142")
    expect_compiled("123e1").to include("return 1230")
    expect_compiled("123E+10").to include("return 1230000000000")
    expect_compiled("false").to include("return false")
    expect_compiled("true").to include("return true")
    expect_compiled("nil").to include("return nil")
  end

  it "should compile ruby strings" do
    expect_compiled('"hello world"').to include('return "hello world"')
    expect_compiled('"hello #{100}"').to include('"hello "', '100')
  end

  it "should compile method calls" do
    expect_compiled("self.inspect").to include("$inspect()")
    expect_compiled("self.map { |a| a + 10 }").to include("$map")
  end

  it "should compile constant lookups" do
    expect_compiled("Object").to include("scope.Object")
    expect_compiled("Array").to include("scope.Array")
  end

  def expect_compiled(source)
    expect(Opal::Compiler.new.compile source)
  end
end

require File.expand_path('../spec_helper', __FILE__)

describe Opal::Compiler do
  it "should compile simple ruby values" do
    expect_compiled("3.142").to include("return 3.142")
    expect_compiled("123e1").to include("return 1230")
    expect_compiled("123E+10").to include("return 1230000000000")
    expect_compiled("false").to include("return false")
    expect_compiled("true").to include("return true")
    expect_compiled("nil").to include("return nil")
  end

  it "should compile ruby strings" do
    expect_compiled('"hello world"').to include('return "hello world"')
    expect_compiled('"hello #{100}"').to include('"hello "', '100')
  end

  it "should compile method calls" do
    expect_compiled("self.inspect").to include("$inspect()")
    expect_compiled("self.map { |a| a + 10 }").to include("$map")
  end

  it "should compile constant lookups" do
    expect_compiled("Object").to include("scope.Object")
    expect_compiled("Array").to include("scope.Array")
  end

  describe "class names" do
    it "generates a named function for class using $ prefix" do
      expect_compiled("class Foo; end").to include("function $Foo")
    end
  end

  def expect_compiled(source)
    expect(Opal::Compiler.new.compile source)
  end
end

Add spec for named function in classes
Add spec for named function in classes
