Sha256: 2f86ecfa7f31e96c8674b458157fd74d978822372d7c76f4e27feccb326e901c

Contents?: true

Size: 1.54 KB

Versions: 2

Compression:

Stored size: 1.54 KB

Contents

require_relative 'test_helper'

# Test how the combinator displays the parsed block contents.
class DisplayTest < Test::Unit::TestCase
  def test_empty_combinator
    assert_equal 'nil', combinator {}.to_s
  end

  def test_literal_number
    assert_equal '23', combinator { 23 }.to_s
  end

  def test_literal_string
    assert_equal '"aa"', combinator { 'aa' }.to_s
  end

  def test_method_calls
    assert_equal 'foo', combinator { foo }.to_s
    assert_equal 'foo.foo', combinator { foo.foo }.to_s
    assert_equal 'foo.foo(1)', combinator { foo.foo 1 }.to_s
    assert_equal 'foo(1)', combinator { foo 1 }.to_s
    assert_equal 'foo(bar)', combinator { foo bar }.to_s
    assert_equal 'foo(1).bar', combinator { foo(1).bar }.to_s
    assert_equal 'foo.foo.foo', combinator { foo.foo.foo }.to_s
    assert_equal 'foo(bar.baz)', combinator { foo bar.baz }.to_s
  end

  def test_operators
    assert_equal '(foo + 1)', combinator { foo + 1 }.to_s
    assert_equal '(foo - 1)', combinator { foo - 1 }.to_s
  end

  def test_operator_equals
    assert_equal '(foo == 1)', combinator { foo == 1 }.to_s
  end

  def test_array_index
    assert_equal 'foo[1]', combinator { foo[1] }.to_s
  end

  def test_to_s_method
    assert_equal 'foo.to_s', combinator { foo.to_s }.to_s
  end

  def test_operator_unary_minus
    assert_equal '-foo', combinator { -foo }.to_s
  end

  def test_operator_if_wont_work
    assert_equal 'bar', combinator { foo ? bar : baz }.to_s
  end

  def test_defined_instance_variables
    @foo = 1
    assert_equal '@foo', combinator { @foo }.to_s
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
iba-0.0.5 test/display_test.rb
iba-0.0.4 test/display_test.rb