Forum | Documentation | Website | Blog

Skip to content
Snippets Groups Projects
sizeof_spec.cr 654 B
Newer Older
Ary Borenszweig's avatar
Ary Borenszweig committed
#!/usr/bin/env bin/crystal --run
require "../../spec_helper"

describe "Code gen: sizeof" do
  it "gets sizeof int" do
    run("sizeof(Int32)").to_i.should eq(4)
  end

  it "gets sizeof struct" do
    run("
      struct Foo
        def initialize(@x, @y, @z)
        end
      end

      Foo.new(1, 2, 3)

      sizeof(Foo)
      ").to_i.should eq(12)
  end

  it "gets sizeof class" do
    run("
      class Foo
        def initialize(@x, @y, @z)
        end
      end

      Foo.new(1, 2, 3)

      sizeof(Foo)
      ").to_i.should eq(8)
  end

  it "gets sizeof union" do
    run("
      sizeof(Int32 | Float64)
      ").to_i.should eq(16)
  end
end