Sha256: 3a6c54b8deacae347d496f12271ef1d4afbd2554319d0d9de7483123034a540c

Contents?: true

Size: 1.37 KB

Versions: 1

Compression:

Stored size: 1.37 KB

Contents

describe Gobstones::Parser, "function calls" do

  it "should parse a function call without args" do
    expected = FunctionCall.new 'f1'
    expect('f1()').to be_parsed_as(:expression).and_return(expected)
  end

  it "should not parse a function call without a valid identifier" do
    expect('F1()').to be_parsed_as(:expression).and_fail
  end

  it "should parse a function call with one arg" do
    expected = FunctionCall.new 'func1', [Verde.new]
    expect('func1(Verde)').to be_parsed_as(:expression).and_return(expected)
  end

  it "should parse a function with many args" do
    first_arg = 42.to_gbs_num
    second_arg = NroBolitas.new Verde.new
    third_arg = Norte.new
    expected = FunctionCall.new 'func1', [first_arg, second_arg, third_arg]

    expect('func1(42, nroBolitas(Verde), Norte)').
      to be_parsed_as(:expression).and_return(expected)
  end

  it "should parse a complex function call" do
    or_expr = Or.new VarName.new('a'), VarName.new('b')
    paren_expr = ParenthesesExpr.new Div.new(10.to_gbs_num, VarName.new('c'))
    num_expr = Mul.new 5.to_gbs_num, paren_expr
    func2_call = FunctionCall.new 'func2', [Verde.new, Opuesto.new(Norte.new)]
    func1_call = FunctionCall.new 'func1', [or_expr, num_expr, func2_call]
    expect('func1(a || b, 5*(10 div c), func2(Verde, opuesto(Norte)))').
      to be_parsed_as(:expression).and_return(func1_call)
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
gobstones-0.0.1.1 spec/parser/function_calls_spec.rb