Sha256: 78780c29b01bf2c2e38b44d73bd0199a360f10e6e38831436ad15594fc71f3ff

Contents?: true

Size: 1.38 KB

Versions: 1

Compression:

Stored size: 1.38 KB

Contents

describe Gobstones::Parser, "main definition" do

  let(:return_tuple) { VarTuple.new ['x'.to_var_name, 'y'.to_var_name] }

  it "parses a valid Main definition without return nor commands" do
    main = Main.new empty_body, no_return_statement

    expect('procedure Main() {}').to be_parsed_as(:definition).and_fail
    expect('procedure Main() {}').to be_parsed_as(:main).and_return(main)
  end

  it "parses a valid main procedure with a return of var names" do
    main = Main.new empty_body, ReturnFromMain.new(return_tuple)

    expect('procedure Main() { return (x, y); }').
      to be_parsed_as(:main).and_return(main)
  end

  it "parses a valid main procedure with commands and return" do
    cmd_block = CommandBlock.new [Mover.new(oeste), Skip.new]
    main = Main.new cmd_block, ReturnFromMain.new(return_tuple)

    expect('procedure Main() {
       Mover(Oeste)
       Skip
       return (x, y)
    }').to be_parsed_as(:main).and_return(main)
  end

  it "does not parse a main procedure with an invalid identifier" do
    expect('procedure NotMain() {}').to be_parsed_as(:main).and_fail
  end

  it "does not parse a main procedure with a return of expressions" do
    expect('procedure Main() { return (3+4) }').to be_parsed_as(:main).and_fail
  end

  it "does not parse a main procedure with args" do
    expect('procedure Main(arg1, arg2) {}').to be_parsed_as(:main).and_fail
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
gobstones-0.0.2 spec/parser/main_definition_spec.rb