Sha256: caf8b22570533eb0759e11b4d34b99cd552afcf484966909e57ea162ccbd3796

Contents?: true

Size: 1.54 KB

Versions: 8

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

8 entries across 8 versions & 2 rubygems

Version Path
freighthopper-0.1.5 test/string_test.rb
freighthopper-0.1.4 test/string_test.rb
simply_stated-0.0.5 vendor/gems/ruby/1.8/gems/freighthopper-0.1.2/test/string_test.rb
simply_stated-0.0.4 vendor/gems/ruby/1.8/gems/freighthopper-0.1.2/test/string_test.rb
freighthopper-0.1.3 test/string_test.rb
freighthopper-0.1.2 test/string_test.rb
freighthopper-0.1.1 test/string_test.rb
freighthopper-0.1.0 test/string_test.rb