Sha256: accd8eabd8cb1ac7f5e72e50be31b680d62e80b265fd2779319486acc66c581f

Contents?: true

Size: 1.13 KB

Versions: 4

Compression:

Stored size: 1.13 KB

Contents

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_raise(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'
    string.extend Term::ANSIColor
    assert_equal "\e]8;;#@link\e\\foo\e]8;;\e\\", string.hyperlink(@link)
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
term-ansicolor-1.10.2 tests/hyperlink_test.rb
term-ansicolor-1.10.1 tests/hyperlink_test.rb
term-ansicolor-1.10.0 tests/hyperlink_test.rb
term-ansicolor-1.9.0 tests/hyperlink_test.rb