tests: add some emoji tests 💯

This commit is contained in:
Alyssa Ross 2017-01-20 17:27:08 +00:00
parent b0fea9eb6c
commit 65dde58057
2 changed files with 33 additions and 0 deletions

View File

@ -0,0 +1,11 @@
require "testing_env"
require "emoji"
class EmojiTest < Homebrew::TestCase
def test_install_badge
assert_equal "🍺", Emoji.install_badge
ENV["HOMEBREW_INSTALL_BADGE"] = "foo"
assert_equal "foo", Emoji.install_badge
end
end

View File

@ -9,6 +9,14 @@ class UtilTests < Homebrew::TestCase
@dir = Pathname.new(mktmpdir)
end
# Helper for matching escape sequences.
def e(code)
/(\e\[\d+m)*\e\[#{code}m/
end
# Helper for matching that style is reset at the end of a string.
Z = /(\e\[\d+m)*\e\[0m\Z/
def test_ofail
shutup { ofail "foo" }
assert Homebrew.failed?
@ -22,11 +30,25 @@ class UtilTests < Homebrew::TestCase
end
def test_pretty_installed
$stdout.stubs(:tty?).returns true
ENV.delete("HOMEBREW_NO_EMOJI")
assert_match(/\A#{e 1}foo #{e 32}#{Z}/, pretty_installed("foo"))
ENV["HOMEBREW_NO_EMOJI"] = "1"
assert_match(/\A#{e 1}foo \(installed\)#{Z}/, pretty_installed("foo"))
$stdout.stubs(:tty?).returns false
assert_equal "foo", pretty_installed("foo")
end
def test_pretty_uninstalled
$stdout.stubs(:tty?).returns true
ENV.delete("HOMEBREW_NO_EMOJI")
assert_match(/\A#{e 1}foo #{e 31}#{Z}/, pretty_uninstalled("foo"))
ENV["HOMEBREW_NO_EMOJI"] = "1"
assert_match(/\A#{e 1}foo \(uninstalled\)#{Z}/, pretty_uninstalled("foo"))
$stdout.stubs(:tty?).returns false
assert_equal "foo", pretty_uninstalled("foo")
end