# encoding: utf-8 class Nanoc::Extra::LinkCollectorTest < Nanoc::TestCase def test_all # Create dummy data File.open('file-a.html', 'w') do |io| io << %[A 1\n] io << %[A 2\n] io << %[\n] io << %[A 4] io << %[A 5\n] end File.open('file-b.html', 'w') do |io| io << %[B 1\n] io << %[B 2\n] io << %[B 3\n] end # Create validator collector = Nanoc::Extra::LinkCollector.new(%w( file-a.html file-b.html )) # Test hrefs_with_filenames = collector.filenames_per_href hrefs = hrefs_with_filenames.keys assert_includes hrefs, 'http://example.com/' assert_includes hrefs, 'https://example.com/' assert_includes hrefs, 'stuff/' refute_includes hrefs, nil assert_includes hrefs, 'mailto:bob@example.com' assert_includes hrefs, '../stuff' assert_includes hrefs, '/stuff' refute_includes hrefs, 'https://example.com/with-fragment#moo' assert_includes hrefs, 'https://example.com/with-fragment' end def test_external # Create dummy data File.open('file-a.html', 'w') do |io| io << %[A 1\n] io << %[A 2\n] io << %[\n] end File.open('file-b.html', 'w') do |io| io << %[B 1\n] io << %[B 2\n] io << %[B 3\n] end # Create validator collector = Nanoc::Extra::LinkCollector.new(%w( file-a.html file-b.html ), :external) # Test hrefs_with_filenames = collector.filenames_per_href hrefs = hrefs_with_filenames.keys assert_includes hrefs, 'http://example.com/' assert_includes hrefs, 'https://example.com/' refute_includes hrefs, 'stuff/' assert_includes hrefs, 'mailto:bob@example.com' refute_includes hrefs, '../stuff' refute_includes hrefs, '/stuff' end def test_internal # Create dummy data File.open('file-a.html', 'w') do |io| io << %[A 1\n] io << %[A 2\n] io << %[\n] end File.open('file-b.html', 'w') do |io| io << %[B 1\n] io << %[B 2\n] io << %[B 3\n] end # Create validator collector = Nanoc::Extra::LinkCollector.new(%w( file-a.html file-b.html ), :internal) # Test hrefs_with_filenames = collector.filenames_per_href hrefs = hrefs_with_filenames.keys refute_includes hrefs, 'http://example.com/' refute_includes hrefs, 'https://example.com/' assert_includes hrefs, 'stuff/' refute_includes hrefs, 'mailto:bob@example.com' assert_includes hrefs, '../stuff' assert_includes hrefs, '/stuff' end end