Sha256: 279bcd4383e88d2e584e6897fd96e7c407697b665225216a0a25398f392f0172

Contents?: true

Size: 1.33 KB

Versions: 34

Compression:

Stored size: 1.33 KB

Contents

# -*- coding: utf-8 -*-
require 'helper'

class TC_Formula < Test::Unit::TestCase

  def setup
    @formula = Writeexcel::Formula.new(0)
  end

  def test_scan
    # scan must return array of token info
    string01 = '1 + 2 * LEN("String")'
    expected01 = [
      [:NUMBER, '1'],
      ['+',     '+'],
      [:NUMBER, '2'],
      ['*',     '*'],
      [:FUNC,   'LEN'],
      ['(',     '('],
      [:STRING, '"String"'],
      [')',     ')'],
      [:EOL,    nil]
    ]
    assert_kind_of(Array, @formula.scan(string01))
    assert_equal(expected01, @formula.scan(string01))

    string02 = 'IF(A1>=0,SIN(0),COS(90))'
    expected02 = [
      [:FUNC,   'IF'],
      ['(',     '('],
      [:REF2D,  'A1'],
      [:GE,     '>='],
      [:NUMBER, '0'],
      [',',     ','],
      [:FUNC,   'SIN'],
      ['(',     '('],
      [:NUMBER, '0'],
      [')',     ')'],
      [',',     ','],
      [:FUNC,   'COS'],
      ['(',     '('],
      [:NUMBER, '90'],
      [')',     ')'],
      [')',     ')'],
      [:EOL,    nil]
    ]
    assert_kind_of(Array, @formula.scan(string02))
    assert_equal(expected02, @formula.scan(string02))
  end

  def test_reverse
    testcase = [
      [ [0,1,2,3,4], [0,[1,[2,3,[4]]]]      ],
      [ [0,1,2,3,4,5], [[0,1,[2,3]],[4,5]]  ]
    ]
    testcase.each do |t|
      assert_equal(t[0], @formula.reverse(t[1]))
    end
  end

end

Version data entries

34 entries across 34 versions & 3 rubygems

Version Path
writeexcel-1.0.5 test/test_formula.rb
writeexcel-1.0.4 test/test_formula.rb
writeexcel-1.0.3 test/test_formula.rb
writeexcel-1.0.2 test/test_formula.rb
writeexcel-1.0.1 test/test_formula.rb
writeexcel-1.0.0 test/test_formula.rb
writeexcel-0.6.19 test/test_formula.rb
writeexcel-0.6.18 test/test_formula.rb
writeexcel-0.6.17 test/test_formula.rb
sunrise-cms-0.5.0.rc1 vendor/bundle/ruby/1.9.1/gems/writeexcel-0.6.16/test/test_formula.rb
writeexcel-0.6.16 test/test_formula.rb
writeexcel-0.6.15 test/test_formula.rb
writeexcel-0.6.14 test/test_formula.rb
sunrise-cms-0.3.3 vendor/bundle/ruby/1.9.1/gems/writeexcel-0.6.13/test/test_formula.rb
sunrise-cms-0.3.2 vendor/bundle/ruby/1.9.1/gems/writeexcel-0.6.13/test/test_formula.rb
sunrise-cms-0.3.1 vendor/bundle/ruby/1.9.1/gems/writeexcel-0.6.13/test/test_formula.rb
sunrise-cms-0.3.0 vendor/bundle/ruby/1.9.1/gems/writeexcel-0.6.13/test/test_formula.rb
sunrise-cms-0.3.0.rc vendor/bundle/ruby/1.9.1/gems/writeexcel-0.6.13/test/test_formula.rb
writeexcel-0.6.13 test/test_formula.rb
ricardoo27-writeexcel-0.6.12.2 test/test_formula.rb