Sha256: 8bca4dda6478681872608648afd9e3cda3608df8f92e47c555e44d5aee9618d8

Contents?: true

Size: 1.14 KB

Versions: 2

Compression:

Stored size: 1.14 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_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

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
term-ansicolor-1.11.2 tests/hyperlink_test.rb
term-ansicolor-1.11.1 tests/hyperlink_test.rb