Sha256: 17808e71ee02851507bf58939405e415babb496900e1c35c1e236e9cfeb94eca

Contents?: true

Size: 1.05 KB

Versions: 11

Compression:

Stored size: 1.05 KB

Contents

require 'spec_helper'
require 'dentaku/ast/node'
require 'dentaku/tokenizer'
require 'dentaku/parser'

describe Dentaku::AST::Node do
  it 'returns list of dependencies' do
    node = make_node('x + 5')
    expect(node.dependencies).to eq(['x'])

    node = make_node('5 < x')
    expect(node.dependencies).to eq(['x'])

    node = make_node('5 < 7')
    expect(node.dependencies).to eq([])

    node = make_node('(y * 7)')
    expect(node.dependencies).to eq(['y'])

    node = make_node('if(x > 5, y, z)')
    expect(node.dependencies).to eq(['x', 'y', 'z'])

    node = make_node('if(x > 5, y, z)')
    expect(node.dependencies('x' => 7)).to eq(['y'])

    node = make_node('if(x > 5, y, z)')
    expect(node.dependencies('x' => 2)).to eq(['z'])

    node = make_node('')
    expect(node.dependencies).to eq([])
  end

  it 'returns unique list of dependencies' do
    node = make_node('x + x')
    expect(node.dependencies).to eq(['x'])
  end

  private

  def make_node(expression)
    Dentaku::Parser.new(Dentaku::Tokenizer.new.tokenize(expression)).parse
  end
end

Version data entries

11 entries across 11 versions & 2 rubygems

Version Path
dentaku-3.5.4 spec/ast/node_spec.rb
dentaku-3.5.3 spec/ast/node_spec.rb
dentaku-3.5.2 spec/ast/node_spec.rb
dentaku_zevo-3.5.2 spec/ast/node_spec.rb
dentaku-3.5.1 spec/ast/node_spec.rb
dentaku-3.5.0 spec/ast/node_spec.rb
dentaku-3.4.2 spec/ast/node_spec.rb
dentaku-3.4.1 spec/ast/node_spec.rb
dentaku-3.4.0 spec/ast/node_spec.rb
dentaku-3.3.4 spec/ast/node_spec.rb
dentaku-3.3.3 spec/ast/node_spec.rb