Sha256: 1360600543e4f721bf5f200488ac3870a172b29b286d369078e110be88797b0f

Contents?: true

Size: 1.54 KB

Versions: 3

Compression:

Stored size: 1.54 KB

Contents

require File.instance_eval { expand_path join(dirname(__FILE__), 'test_helper') }
require 'freighthopper'

class StringTest < Test::Unit::TestCase
  context 'strip' do
    should 'still allow normal strip' do
      assert_strip "hello", " hello \t\n"
    end
    
    should 'also allow a string' do
      assert_equal "hello", "---hello---".strip("-")
    end
    
    should 'also allow a regular expression' do
      assert_equal "hello", "123hello456".strip(/[0-9]/)
    end
  end
  
  context 'division operator' do
    context 'with an even division' do
      should 'split the string into that many even strings' do
        divided = ('-' * 10) / 2
        assert_size 2, divided
        assert_equal [5, 5], divided.map{|s| s.length}
      end
    end
    
    context 'with an uneven division' do
      should 'take the difference out of the last one' do
        divided = ('-' * 10) / 3
        assert_size 3, divided
        assert_equal [4,4,2], divided.map(&:length)
      end
    end
  end
  
  context 'unindent' do
    should 'remove the least common leading whitespace' do
      unindented = (<<-END).unindent
        a
          b
            c
      END
      
      assert_equal "a\n  b\n    c", unindented
    end
    
    should 'replace tabs with tablength' do
      unindented = "\ttest\n\t\ttest".unindent :tablength => 4
      assert_equal "test\n    test", unindented
    end

    should 'replace tabs with tablength (defaulting to 2)' do
      unindented = "\ttest\n\t\ttest".unindent
      assert_equal "test\n  test", unindented
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
freighthopper-0.1.12 test/string_test.rb
freighthopper-0.1.11 test/string_test.rb
freighthopper-0.1.9 test/string_test.rb