Sha256: 641d582d8028ebfb60071022bbb305e99a83882569ba201008e592018ac28f2d

Contents?: true

Size: 1.03 KB

Versions: 3

Compression:

Stored size: 1.03 KB

Contents

require 'spec_helper'
require 'dentaku/ast/functions/count'
require 'dentaku'

describe 'Dentaku::AST::Count' do
  it 'returns the length of an array' do
    result = Dentaku('COUNT(1, x, 1.8)', x: 2.3)
    expect(result).to eq 3
  end

  it 'returns the length of a single number object' do
    result = Dentaku('COUNT(x)', x: 2.3)
    expect(result).to eq 1
  end

  it 'returns the length if a single String is passed' do
    result = Dentaku('COUNT(x)', x: 'dentaku')
    expect(result).to eq 7
  end

  it 'returns the length if an array is passed' do
    result = Dentaku('COUNT(x)', x: [4, 5])
    expect(result).to eq 2
  end

  it 'returns the length if an array with one element is passed' do
    result = Dentaku('COUNT(x)', x: [4])
    expect(result).to eq 1
  end

  it 'returns the length if an array even if it has nested array' do
    result = Dentaku('COUNT(1, x, 3)', x: [4, 5])
    expect(result).to eq 3
  end

  it 'returns the length if an array is passed' do
    result = Dentaku('COUNT()')
    expect(result).to eq 0
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
dentaku-3.3.0 spec/ast/count_spec.rb
dentaku-3.2.1 spec/ast/count_spec.rb
dentaku-3.2.0 spec/ast/count_spec.rb