aboutsummaryrefslogtreecommitdiffstats
path: root/Library/Homebrew/test/string_test.rb
blob: 497c4badb15b021e238279ad3b5e786ded90739c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
require "testing_env"
require "extend/string"

class StringTest < Homebrew::TestCase
  def test_undent
    undented = <<-EOS.undent
    hi
....my friend over
    there
    EOS
    assert_equal "hi\n....my friend over\nthere\n", undented
  end

  def test_undent_not_indented
    undented = <<-EOS.undent
hi
I'm not indented
    EOS
    assert_equal "hi\nI'm not indented\n", undented
  end

  def test_undent_nested
    nest = <<-EOS.undent
      goodbye
    EOS

    undented = <<-EOS.undent
      hello
      #{nest}
    EOS

    assert_equal "hello\ngoodbye\n\n", undented
  end

  def test_inreplace_sub_failure
    s = "foobar".extend StringInreplaceExtension
    s.sub! "not here", "test"
    assert_equal ['expected replacement of "not here" with "test"'], s.errors
  end
end