# encoding: utf-8
class Nanoc::Filters::RelativizePathsTest < Nanoc::TestCase
def test_filter_html_with_double_quotes
# Create filter with mock item
filter = Nanoc::Filters::RelativizePaths.new
# Mock item
filter.instance_eval do
@item_rep = Nanoc::ItemRep.new(
Nanoc::Item.new(
'content',
{},
'/foo/bar/baz/'),
:blah)
@item_rep.path = '/foo/bar/baz/'
end
# Set content
raw_content = %(foo)
expected_content = %(foo)
# Test
actual_content = filter.setup_and_run(raw_content, type: :html)
assert_equal(expected_content, actual_content)
end
def test_filter_html_with_single_quotes
# Create filter with mock item
filter = Nanoc::Filters::RelativizePaths.new
# Mock item
filter.instance_eval do
@item_rep = Nanoc::ItemRep.new(
Nanoc::Item.new(
'content',
{},
'/foo/bar/baz/'),
:blah)
@item_rep.path = '/foo/bar/baz/'
end
# Set content
raw_content = %(foo)
expected_content = %(foo)
# Test
actual_content = filter.setup_and_run(raw_content, type: :html)
assert_equal(expected_content, actual_content)
end
def test_filter_html_without_quotes
# Create filter with mock item
filter = Nanoc::Filters::RelativizePaths.new
# Mock item
filter.instance_eval do
@item_rep = Nanoc::ItemRep.new(
Nanoc::Item.new(
'content',
{},
'/foo/bar/baz/'),
:blah)
@item_rep.path = '/foo/bar/baz/'
end
# Set content
raw_content = %(foo)
expected_content = %(foo)
# Test
actual_content = filter.setup_and_run(raw_content, type: :html)
assert_equal(expected_content, actual_content)
end
def test_filter_html_with_boilerplate
# Create filter with mock item
filter = Nanoc::Filters::RelativizePaths.new
# Mock item
filter.instance_eval do
@item_rep = Nanoc::ItemRep.new(
Nanoc::Item.new(
'content',
{},
'/foo/bar/baz/'),
:blah)
@item_rep.path = '/foo/bar/baz/'
end
# Set content
raw_content = <
Hello
foo
EOS
expected_match_0 = %r{foo}
expected_match_1 = %r{\A\s*\s*\s*(.|\s)*Hello\s*\s*\s*foo\s*\s*\s*\Z}m
# Test
actual_content = filter.setup_and_run(raw_content, type: :html)
assert_match(expected_match_0, actual_content)
assert_match(expected_match_1, actual_content)
end
def test_filter_html_multiple
# Create filter with mock item
filter = Nanoc::Filters::RelativizePaths.new
# Mock item
filter.instance_eval do
@item_rep = Nanoc::ItemRep.new(
Nanoc::Item.new(
'content',
{},
'/foo/bar/baz/'),
:blah)
@item_rep.path = '/foo/bar/baz/'
end
# Set content
raw_content = %(foo bar)
expected_content = %(foo bar)
# Test
actual_content = filter.setup_and_run(raw_content, type: :html)
assert_equal(expected_content, actual_content)
end
def test_filter_html_nested
# Create filter with mock item
filter = Nanoc::Filters::RelativizePaths.new
# Mock item
filter.instance_eval do
@item_rep = Nanoc::ItemRep.new(
Nanoc::Item.new(
'content',
{},
'/foo/bar/baz/'),
:blah)
@item_rep.path = '/foo/bar/baz/'
end
# Set content
raw_content = %()
expected_content = %()
# Test
actual_content = filter.setup_and_run(raw_content, type: :html)
assert_equal(expected_content, actual_content)
end
def test_filter_html_outside_tag
# Create filter with mock item
filter = Nanoc::Filters::RelativizePaths.new
# Mock item
filter.instance_eval do
@item_rep = Nanoc::ItemRep.new(
Nanoc::Item.new(
'content',
{},
'/foo/bar/baz/'),
:blah)
@item_rep.path = '/foo/bar/baz/'
end
# Set content
raw_content = %(stuff href="/foo" more stuff)
expected_content = %(stuff href="/foo" more stuff)
# Test
actual_content = filter.setup_and_run(raw_content, type: :html)
assert_equal(expected_content, actual_content)
end
def test_filter_html_root
# Create filter with mock item
filter = Nanoc::Filters::RelativizePaths.new
# Mock item
filter.instance_eval do
@item_rep = Nanoc::ItemRep.new(
Nanoc::Item.new(
'content',
{},
'/foo/bar/baz/'),
:blah)
@item_rep.path = '/woof/meow/'
end
# Set content
raw_content = %(foo)
expected_content = %(foo)
# Test
actual_content = filter.setup_and_run(raw_content, type: :html)
assert_equal(expected_content, actual_content)
end
def test_filter_html_network_path
# Create filter with mock item
filter = Nanoc::Filters::RelativizePaths.new
# Mock item
filter.instance_eval do
@item_rep = Nanoc::ItemRep.new(
Nanoc::Item.new(
'content',
{},
'/foo/bar/baz/'),
:blah)
@item_rep.path = '/woof/meow/'
end
# Set content
raw_content = %(example.com)
expected_content = %(example.com)
# Test
actual_content = filter.setup_and_run(raw_content, type: :html)
assert_equal(expected_content, actual_content)
end
def test_filter_html_with_anchor
# Create filter with mock item
filter = Nanoc::Filters::RelativizePaths.new
# Mock item
filter.instance_eval do
@item_rep = Nanoc::ItemRep.new(
Nanoc::Item.new(
'content',
{},
'/foo/bar/baz/'),
:blah)
@item_rep.path = '/woof/meow/'
end
# Set content
raw_content = %(Max Payne)
expected_content = %(Max Payne)
# Test
actual_content = filter.setup_and_run(raw_content, type: :html)
assert_equal(expected_content, actual_content)
end
def test_filter_html_with_url
# Create filter with mock item
filter = Nanoc::Filters::RelativizePaths.new
# Mock item
filter.instance_eval do
@item_rep = Nanoc::ItemRep.new(
Nanoc::Item.new(
'content',
{},
'/foo/bar/baz/'),
:blah)
@item_rep.path = '/woof/meow/'
end
# Set content
raw_content = %(Example)
expected_content = %(Example)
# Test
actual_content = filter.setup_and_run(raw_content, type: :html)
assert_equal(expected_content, actual_content)
end
def test_filter_html_with_relative_path
# Create filter with mock item
filter = Nanoc::Filters::RelativizePaths.new
# Mock item
filter.instance_eval do
@item_rep = Nanoc::ItemRep.new(
Nanoc::Item.new(
'content',
{},
'/foo/bar/baz/'),
:blah)
@item_rep.path = '/woof/meow/'
end
# Set content
raw_content = %(Example)
expected_content = %(Example)
# Test
actual_content = filter.setup_and_run(raw_content, type: :html)
assert_equal(expected_content, actual_content)
end
def test_filter_html_object_with_relative_path
# Create filter with mock item
filter = Nanoc::Filters::RelativizePaths.new
# Mock item
filter.instance_eval do
@item_rep = Nanoc::ItemRep.new(
Nanoc::Item.new(
'content',
{},
'/foo/bar/baz/'),
:blah)
@item_rep.path = '/woof/meow/'
end
raw_content = %()
actual_content = filter.setup_and_run(raw_content, type: :html)
assert_match(/