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 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
|
require 'test_helper'
class HyperlinkTest < Test::Unit::TestCase
include Term::ANSIColor
def setup
@link = 'https://foo.example.com'
end
def test_hyperlink_switch_on
assert_equal(
"\e]8;;#@link\e\\",
hyperlink(@link)
)
end
def test_hyperlink_switch_off
assert_equal(
"\e]8;;\e\\",
hyperlink(nil)
)
end
def test_hyperlink_as_link
assert_equal(
hyperlink(@link, as_link: true),
"\e]8;;#@link\e\\#@link\e]8;;\e\\",
)
end
def test_hyperlink_two_args
assert_equal(
"\e]8;;#@link\e\\foo\e]8;;\e\\",
hyperlink(@link, 'foo')
)
end
def test_hyperlink_two_args_with_id
assert_equal(
"\e]8;id=666;#@link\e\\foo\e]8;;\e\\",
hyperlink(@link, 'foo', id: 666)
)
end
def test_hyperlink_block_arg
assert_raises(ArgumentError) { hyperlink(@link, 'bar') { 'baz' } }
assert_equal(
"\e]8;;#@link\e\\foo\e]8;;\e\\",
hyperlink(@link) { 'foo' }
)
end
def test_with_stringy_self
string = 'foo'.dup
string.extend Term::ANSIColor
assert_equal "\e]8;;#@link\e\\foo\e]8;;\e\\", string.hyperlink(@link)
end
end
|