Sha256: 0f30a39a72c2e36961a452d5a0bca0f99917f5864f4accd9163bcc581f62791f

Contents?: true

Size: 1.95 KB

Versions: 5

Compression:

Stored size: 1.95 KB

Contents

require 'facets/string/indent'
require 'test/unit'

class TC_String_Indent < Test::Unit::TestCase

  def test_positive_indent
    assert_equal '    xyz', "xyz".  indent(4)
    assert_equal '    xyz', "  xyz".indent(2)
  end

  def test_multi_line_positive_indent
    assert_equal  "  abc\n" +
                  "  xyz"   , 
                 ("abc\n"   +
                  "xyz"     ).indent(2)
  end

  def test_0_indent
    assert_equal 'xyz', 'xyz'.indent(0)
  end

  def test_negative_indent
    assert_equal '  xyz', '    xyz'.indent(-2)
    assert_equal 'xyz',   '  xyz'.  indent(-2)
  end

  def test_multi_line_negative_indent
    assert_equal  "  abc\n" +
                  "  xyz"   , 
                 ("    abc\n"   +
                  "    xyz"     ).indent(-2)
  end

  def test_outdent_is_alias_for_negative_indent
    assert_equal 'xyz', '  xyz'.outdent(2)
  end

  def test_negative_indent_more_than_is_possible
    assert_equal 'xyz', '  xyz'.indent(-3)
  end

  #-----------------------------------
  # Using a character other than space

  def test_nonspace_positive__indent
    assert_equal '----xyz', "xyz".indent(4, '-')
  end

  def test_nonspace_0_indent
    assert_equal 'xyz', 'xyz'.indent(0, '-')
  end

  def test_nonspace_negative_indent_nonmatching_character
    assert_equal '    xyz', '    xyz'.indent(-2, '-')
    assert_equal '  xyz',   '  xyz'.  indent(-2, '-')
  end

  def test_nonspace_negative_indent
    assert_equal '--xyz', '----xyz'.indent(-2, '-')
    assert_equal 'xyz',   '--xyz'.indent(-2, '-')
  end

  def test_special_regexp_characters_are_escaped
    # make sure . is treated as a literal '.' and not an "any character" wildcard
    assert_equal '  xyz', '  xyz'.indent(-2, '.')
    assert_equal 'xyz',   '..xyz'.indent(-2, '.')

    assert_equal '  xyz', '  xyz'.indent(-2, '^')
    assert_equal 'xyz',   '^^xyz'.indent(-2, '^')

    assert_equal '  xyz', '  xyz'.indent(-2, '*')
    assert_equal 'xyz',   '**xyz'.indent(-2, '*')
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
facets-2.8.4 test/core/string/test_indent.rb
facets-2.8.3 test/core/string/test_indent.rb
facets-2.8.2 test/core/string/test_indent.rb
facets-2.8.1 test/core/string/test_indent.rb
facets-2.8.0 test/core/string/test_indent.rb