Sha256: f12d6005dc807572b16051fb86fe2d8adbc0c270827faa710548618538626bf8

Contents?: true

Size: 844 Bytes

Versions: 3

Compression:

Stored size: 844 Bytes

Contents

require 'spec_helper'
require 'dentaku/ast/functions/map'
require 'dentaku'

describe Dentaku::AST::Map do
  let(:calculator) { Dentaku::Calculator.new }
  it 'operates on each value in an array' do
    result = Dentaku('SUM(MAP(vals, val, val + 1))', vals: [1, 2, 3])
    expect(result).to eq(9)
  end

  it 'works with an empty array' do
    result = Dentaku('MAP(vals, val, val + 1)', vals: [])
    expect(result).to eq([])
  end

  it 'works with a single value if needed for some reason' do
    result = Dentaku('MAP(vals, val, val + 1)', vals: 1)
    expect(result).to eq([2])
  end

  it 'raises argument error if a string is passed as identifier' do
    expect { calculator.evaluate!('MAP({1, 2, 3}, "val", val + 1)') }.to raise_error(
      Dentaku::ArgumentError,  'MAP() requires second argument to be an identifier'
    )
  end
end

Version data entries

3 entries across 3 versions & 2 rubygems

Version Path
dentaku_zevo-3.5.2 spec/ast/map_spec.rb
dentaku-3.5.1 spec/ast/map_spec.rb
dentaku-3.5.0 spec/ast/map_spec.rb