Merge pull request #4947 from pathawks/rubocop/tests
Merge pull request 4947
This commit is contained in:
commit
cd63272080
12
.rubocop.yml
12
.rubocop.yml
|
@ -39,17 +39,6 @@ AllCops:
|
||||||
- features/step_definitions.rb
|
- features/step_definitions.rb
|
||||||
- features/support/formatter.rb
|
- features/support/formatter.rb
|
||||||
- features/support/helpers.rb
|
- features/support/helpers.rb
|
||||||
- test/test_configuration.rb
|
|
||||||
- test/test_document.rb
|
|
||||||
- test/test_entry_filter.rb
|
|
||||||
- test/test_filters.rb
|
|
||||||
- test/test_kramdown.rb
|
|
||||||
- test/test_liquid_renderer.rb
|
|
||||||
- test/test_page.rb
|
|
||||||
- test/test_regenerator.rb
|
|
||||||
- test/test_site.rb
|
|
||||||
- test/test_tags.rb
|
|
||||||
- test/test_utils.rb
|
|
||||||
- bin/**/*
|
- bin/**/*
|
||||||
- benchmark/**/*
|
- benchmark/**/*
|
||||||
- script/**/*
|
- script/**/*
|
||||||
|
@ -66,6 +55,7 @@ Metrics/ClassLength:
|
||||||
Max: 240
|
Max: 240
|
||||||
Exclude:
|
Exclude:
|
||||||
- !ruby/regexp /features\/.*.rb$/
|
- !ruby/regexp /features\/.*.rb$/
|
||||||
|
- !ruby/regexp /test\/.*.rb$/
|
||||||
Metrics/CyclomaticComplexity:
|
Metrics/CyclomaticComplexity:
|
||||||
Max: 8
|
Max: 8
|
||||||
Metrics/LineLength:
|
Metrics/LineLength:
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
require 'helper'
|
require "helper"
|
||||||
|
|
||||||
class TestConfiguration < JekyllUnitTest
|
class TestConfiguration < JekyllUnitTest
|
||||||
@@test_config = {
|
test_config = {
|
||||||
"source" => new(nil).source_dir,
|
"source" => new(nil).source_dir,
|
||||||
"destination" => dest_dir
|
"destination" => dest_dir
|
||||||
}
|
}
|
||||||
|
@ -19,16 +19,31 @@ class TestConfiguration < JekyllUnitTest
|
||||||
|
|
||||||
should "fix common mistakes" do
|
should "fix common mistakes" do
|
||||||
result = Configuration.from({ "paginate" => 0 })
|
result = Configuration.from({ "paginate" => 0 })
|
||||||
assert_nil result["paginate"], "Expected 'paginate' to be corrected to 'nil', but was #{result["paginate"].inspect}"
|
assert_nil(
|
||||||
|
result["paginate"],
|
||||||
|
"Expected 'paginate' to be corrected to 'nil', " \
|
||||||
|
"but was #{result["paginate"].inspect}"
|
||||||
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
should "add default collections" do
|
should "add default collections" do
|
||||||
result = Configuration.from({})
|
result = Configuration.from({})
|
||||||
assert_equal result["collections"], {"posts" => {"output" => true, "permalink" => "/:categories/:year/:month/:day/:title:output_ext"}}
|
assert_equal(
|
||||||
|
result["collections"],
|
||||||
|
{
|
||||||
|
"posts" => {
|
||||||
|
"output" => true,
|
||||||
|
"permalink" => "/:categories/:year/:month/:day/:title:output_ext"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
should "NOT backwards-compatibilize" do
|
should "NOT backwards-compatibilize" do
|
||||||
assert Configuration.from("watch" => true)["watch"], "Expected the 'watch' key to not be removed."
|
assert(
|
||||||
|
Configuration.from("watch" => true)["watch"],
|
||||||
|
"Expected the 'watch' key to not be removed."
|
||||||
|
)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -39,21 +54,35 @@ class TestConfiguration < JekyllUnitTest
|
||||||
end
|
end
|
||||||
|
|
||||||
should "turn an array into a hash" do
|
should "turn an array into a hash" do
|
||||||
result = Configuration[{"collections" => %w{methods}}].add_default_collections
|
result = Configuration[{ "collections" => %w(methods) }].add_default_collections
|
||||||
assert_instance_of Hash, result["collections"]
|
assert_instance_of Hash, result["collections"]
|
||||||
assert_equal result["collections"], {"posts" => {"output" => true}, "methods" => {}}
|
assert_equal(
|
||||||
|
result["collections"],
|
||||||
|
{ "posts" => { "output" => true }, "methods" => {} }
|
||||||
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
should "only assign collections.posts.permalink if a permalink is specified" do
|
should "only assign collections.posts.permalink if a permalink is specified" do
|
||||||
result = Configuration[{"permalink" => "pretty", "collections" => {}}].add_default_collections
|
result = Configuration[{ "permalink" => "pretty", "collections" => {} }]
|
||||||
assert_equal result["collections"], {"posts" => {"output" => true, "permalink" => "/:categories/:year/:month/:day/:title/"}}
|
.add_default_collections
|
||||||
|
assert_equal(
|
||||||
|
result["collections"],
|
||||||
|
{
|
||||||
|
"posts" => {
|
||||||
|
"output" => true,
|
||||||
|
"permalink" => "/:categories/:year/:month/:day/:title/"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
result = Configuration[{"permalink" => nil, "collections" => {}}].add_default_collections
|
result = Configuration[{ "permalink" => nil, "collections" => {} }]
|
||||||
|
.add_default_collections
|
||||||
assert_equal result["collections"], { "posts" => { "output" => true } }
|
assert_equal result["collections"], { "posts" => { "output" => true } }
|
||||||
end
|
end
|
||||||
|
|
||||||
should "forces posts to output" do
|
should "forces posts to output" do
|
||||||
result = Configuration[{"collections" => {"posts" => {"output" => false}}}].add_default_collections
|
result = Configuration[{ "collections" => { "posts" => { "output" => false } } }]
|
||||||
|
.add_default_collections
|
||||||
assert_equal result["collections"]["posts"]["output"], true
|
assert_equal result["collections"]["posts"]["output"], true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -61,18 +90,18 @@ class TestConfiguration < JekyllUnitTest
|
||||||
context "#stringify_keys" do
|
context "#stringify_keys" do
|
||||||
setup do
|
setup do
|
||||||
@mixed_keys = Configuration[{
|
@mixed_keys = Configuration[{
|
||||||
'markdown' => 'kramdown',
|
"markdown" => "kramdown",
|
||||||
:permalink => 'date',
|
:permalink => "date",
|
||||||
'baseurl' => '/',
|
"baseurl" => "/",
|
||||||
:include => ['.htaccess'],
|
:include => [".htaccess"],
|
||||||
:source => './'
|
:source => "./"
|
||||||
}]
|
}]
|
||||||
@string_keys = Configuration[{
|
@string_keys = Configuration[{
|
||||||
'markdown' => 'kramdown',
|
"markdown" => "kramdown",
|
||||||
'permalink' => 'date',
|
"permalink" => "date",
|
||||||
'baseurl' => '/',
|
"baseurl" => "/",
|
||||||
'include' => ['.htaccess'],
|
"include" => [".htaccess"],
|
||||||
'source' => './'
|
"source" => "./"
|
||||||
}]
|
}]
|
||||||
end
|
end
|
||||||
should "stringify symbol keys" do
|
should "stringify symbol keys" do
|
||||||
|
@ -87,7 +116,9 @@ class TestConfiguration < JekyllUnitTest
|
||||||
@config = Configuration[{ "source" => source_dir }]
|
@config = Configuration[{ "source" => source_dir }]
|
||||||
@no_override = {}
|
@no_override = {}
|
||||||
@one_config_file = { "config" => "config.yml" }
|
@one_config_file = { "config" => "config.yml" }
|
||||||
@multiple_files = {"config" => %w[config/site.yml config/deploy.toml configuration.yml]}
|
@multiple_files = {
|
||||||
|
"config" => %w(config/site.yml config/deploy.toml configuration.yml)
|
||||||
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
should "always return an array" do
|
should "always return an array" do
|
||||||
|
@ -108,22 +139,25 @@ class TestConfiguration < JekyllUnitTest
|
||||||
assert_equal [source_dir("_config.yml")], @config.config_files(@no_override)
|
assert_equal [source_dir("_config.yml")], @config.config_files(@no_override)
|
||||||
end
|
end
|
||||||
should "return the config if given one config file" do
|
should "return the config if given one config file" do
|
||||||
assert_equal %w[config.yml], @config.config_files(@one_config_file)
|
assert_equal %w(config.yml), @config.config_files(@one_config_file)
|
||||||
end
|
end
|
||||||
should "return an array of the config files if given many config files" do
|
should "return an array of the config files if given many config files" do
|
||||||
assert_equal %w[config/site.yml config/deploy.toml configuration.yml], @config.config_files(@multiple_files)
|
assert_equal(
|
||||||
|
%w(config/site.yml config/deploy.toml configuration.yml),
|
||||||
|
@config.config_files(@multiple_files)
|
||||||
|
)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context "#read_config_file" do
|
context "#read_config_file" do
|
||||||
setup do
|
setup do
|
||||||
@config = Configuration[{"source" => source_dir('empty.yml')}]
|
@config = Configuration[{ "source" => source_dir("empty.yml") }]
|
||||||
end
|
end
|
||||||
|
|
||||||
should "not raise an error on empty files" do
|
should "not raise an error on empty files" do
|
||||||
allow(SafeYAML).to receive(:load_file).with('empty.yml').and_return(false)
|
allow(SafeYAML).to receive(:load_file).with("empty.yml").and_return(false)
|
||||||
Jekyll.logger.log_level = :warn
|
Jekyll.logger.log_level = :warn
|
||||||
@config.read_config_file('empty.yml')
|
@config.read_config_file("empty.yml")
|
||||||
Jekyll.logger.log_level = :info
|
Jekyll.logger.log_level = :info
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -134,12 +168,15 @@ class TestConfiguration < JekyllUnitTest
|
||||||
end
|
end
|
||||||
|
|
||||||
should "continue to read config files if one is empty" do
|
should "continue to read config files if one is empty" do
|
||||||
allow(SafeYAML).to receive(:load_file).with('empty.yml').and_return(false)
|
allow(SafeYAML).to receive(:load_file).with("empty.yml").and_return(false)
|
||||||
allow(SafeYAML).to receive(:load_file).with('not_empty.yml').and_return({'foo' => 'bar', 'include' => '', 'exclude' => ''})
|
allow(SafeYAML)
|
||||||
|
.to receive(:load_file)
|
||||||
|
.with("not_empty.yml")
|
||||||
|
.and_return({ "foo" => "bar", "include" => "", "exclude" => "" })
|
||||||
Jekyll.logger.log_level = :warn
|
Jekyll.logger.log_level = :warn
|
||||||
read_config = @config.read_config_files(['empty.yml', 'not_empty.yml'])
|
read_config = @config.read_config_files(["empty.yml", "not_empty.yml"])
|
||||||
Jekyll.logger.log_level = :info
|
Jekyll.logger.log_level = :info
|
||||||
assert_equal 'bar', read_config['foo']
|
assert_equal "bar", read_config["foo"]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
context "#backwards_compatibilize" do
|
context "#backwards_compatibilize" do
|
||||||
|
@ -153,7 +190,7 @@ class TestConfiguration < JekyllUnitTest
|
||||||
"pygments" => true,
|
"pygments" => true,
|
||||||
"plugins" => true,
|
"plugins" => true,
|
||||||
"layouts" => true,
|
"layouts" => true,
|
||||||
"data_source" => true,
|
"data_source" => true
|
||||||
}]
|
}]
|
||||||
end
|
end
|
||||||
should "unset 'auto' and 'watch'" do
|
should "unset 'auto' and 'watch'" do
|
||||||
|
@ -169,12 +206,18 @@ class TestConfiguration < JekyllUnitTest
|
||||||
should "transform string exclude into an array" do
|
should "transform string exclude into an array" do
|
||||||
assert @config.key?("exclude")
|
assert @config.key?("exclude")
|
||||||
assert @config.backwards_compatibilize.key?("exclude")
|
assert @config.backwards_compatibilize.key?("exclude")
|
||||||
assert_equal @config.backwards_compatibilize["exclude"], %w[READ-ME.md Gemfile CONTRIBUTING.hello.markdown]
|
assert_equal(
|
||||||
|
@config.backwards_compatibilize["exclude"],
|
||||||
|
%w(READ-ME.md Gemfile CONTRIBUTING.hello.markdown)
|
||||||
|
)
|
||||||
end
|
end
|
||||||
should "transform string include into an array" do
|
should "transform string include into an array" do
|
||||||
assert @config.key?("include")
|
assert @config.key?("include")
|
||||||
assert @config.backwards_compatibilize.key?("include")
|
assert @config.backwards_compatibilize.key?("include")
|
||||||
assert_equal @config.backwards_compatibilize["include"], %w[STOP_THE_PRESSES.txt .heloses .git]
|
assert_equal(
|
||||||
|
@config.backwards_compatibilize["include"],
|
||||||
|
%w(STOP_THE_PRESSES.txt .heloses .git)
|
||||||
|
)
|
||||||
end
|
end
|
||||||
should "set highlighter to pygments" do
|
should "set highlighter to pygments" do
|
||||||
assert @config.key?("pygments")
|
assert @config.key?("pygments")
|
||||||
|
@ -195,62 +238,79 @@ class TestConfiguration < JekyllUnitTest
|
||||||
end
|
end
|
||||||
context "#fix_common_issues" do
|
context "#fix_common_issues" do
|
||||||
setup do
|
setup do
|
||||||
@config = Proc.new do |val|
|
@config = proc do |val|
|
||||||
Configuration[{
|
Configuration[{
|
||||||
'paginate' => val
|
"paginate" => val
|
||||||
}]
|
}]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
should "sets an invalid 'paginate' value to nil" do
|
should "sets an invalid 'paginate' value to nil" do
|
||||||
assert_nil @config.call(0).fix_common_issues['paginate']
|
assert_nil @config.call(0).fix_common_issues["paginate"]
|
||||||
assert_nil @config.call(-1).fix_common_issues['paginate']
|
assert_nil @config.call(-1).fix_common_issues["paginate"]
|
||||||
assert_nil @config.call(true).fix_common_issues['paginate']
|
assert_nil @config.call(true).fix_common_issues["paginate"]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
context "loading configuration" do
|
context "loading configuration" do
|
||||||
setup do
|
setup do
|
||||||
@path = source_dir('_config.yml')
|
@path = source_dir("_config.yml")
|
||||||
@user_config = File.join(Dir.pwd, "my_config_file.yml")
|
@user_config = File.join(Dir.pwd, "my_config_file.yml")
|
||||||
end
|
end
|
||||||
|
|
||||||
should "fire warning with no _config.yml" do
|
should "fire warning with no _config.yml" do
|
||||||
allow(SafeYAML).to receive(:load_file).with(@path) { raise SystemCallError, "No such file or directory - #{@path}" }
|
allow(SafeYAML).to receive(:load_file).with(@path) do
|
||||||
|
raise SystemCallError, "No such file or directory - #{@path}"
|
||||||
|
end
|
||||||
allow($stderr).to receive(:puts).with("Configuration file: none".yellow)
|
allow($stderr).to receive(:puts).with("Configuration file: none".yellow)
|
||||||
assert_equal site_configuration, Jekyll.configuration(@@test_config)
|
assert_equal site_configuration, Jekyll.configuration(test_config)
|
||||||
end
|
end
|
||||||
|
|
||||||
should "load configuration as hash" do
|
should "load configuration as hash" do
|
||||||
allow(SafeYAML).to receive(:load_file).with(@path).and_return(Hash.new)
|
allow(SafeYAML).to receive(:load_file).with(@path).and_return({})
|
||||||
allow($stdout).to receive(:puts).with("Configuration file: #{@path}")
|
allow($stdout).to receive(:puts).with("Configuration file: #{@path}")
|
||||||
assert_equal site_configuration, Jekyll.configuration(@@test_config)
|
assert_equal site_configuration, Jekyll.configuration(test_config)
|
||||||
end
|
end
|
||||||
|
|
||||||
should "fire warning with bad config" do
|
should "fire warning with bad config" do
|
||||||
allow(SafeYAML).to receive(:load_file).with(@path).and_return(Array.new)
|
allow(SafeYAML).to receive(:load_file).with(@path).and_return([])
|
||||||
allow($stderr).to receive(:puts).and_return(("WARNING: ".rjust(20) + "Error reading configuration. Using defaults (and options).").yellow)
|
allow($stderr)
|
||||||
allow($stderr).to receive(:puts).and_return("Configuration file: (INVALID) #{@path}".yellow)
|
.to receive(:puts)
|
||||||
assert_equal site_configuration, Jekyll.configuration(@@test_config)
|
.and_return(
|
||||||
|
("WARNING: "
|
||||||
|
.rjust(20) + "Error reading configuration. Using defaults (and options).")
|
||||||
|
.yellow
|
||||||
|
)
|
||||||
|
allow($stderr)
|
||||||
|
.to receive(:puts)
|
||||||
|
.and_return("Configuration file: (INVALID) #{@path}".yellow)
|
||||||
|
assert_equal site_configuration, Jekyll.configuration(test_config)
|
||||||
end
|
end
|
||||||
|
|
||||||
should "fire warning when user-specified config file isn't there" do
|
should "fire warning when user-specified config file isn't there" do
|
||||||
allow(SafeYAML).to receive(:load_file).with(@user_config) { raise SystemCallError, "No such file or directory - #{@user_config}" }
|
allow(SafeYAML).to receive(:load_file).with(@user_config) do
|
||||||
allow($stderr).to receive(:puts).with(("Fatal: ".rjust(20) + "The configuration file '#{@user_config}' could not be found.").red)
|
raise SystemCallError, "No such file or directory - #{@user_config}"
|
||||||
|
end
|
||||||
|
allow($stderr)
|
||||||
|
.to receive(:puts)
|
||||||
|
.with((
|
||||||
|
"Fatal: ".rjust(20) + \
|
||||||
|
"The configuration file '#{@user_config}' could not be found."
|
||||||
|
).red)
|
||||||
assert_raises LoadError do
|
assert_raises LoadError do
|
||||||
Jekyll.configuration({'config' => [@user_config]})
|
Jekyll.configuration({ "config" => [@user_config] })
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
should "not clobber YAML.load to the dismay of other libraries" do
|
should "not clobber YAML.load to the dismay of other libraries" do
|
||||||
assert_equal :foo, YAML.load(':foo')
|
assert_equal :foo, YAML.load(":foo")
|
||||||
# as opposed to: assert_equal ':foo', SafeYAML.load(':foo')
|
# as opposed to: assert_equal ':foo', SafeYAML.load(':foo')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
context "loading config from external file" do
|
context "loading config from external file" do
|
||||||
setup do
|
setup do
|
||||||
@paths = {
|
@paths = {
|
||||||
:default => source_dir('_config.yml'),
|
:default => source_dir("_config.yml"),
|
||||||
:other => source_dir('_config.live.yml'),
|
:other => source_dir("_config.live.yml"),
|
||||||
:toml => source_dir('_config.dev.toml'),
|
:toml => source_dir("_config.dev.toml"),
|
||||||
:empty => ""
|
:empty => ""
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
@ -258,16 +318,19 @@ class TestConfiguration < JekyllUnitTest
|
||||||
should "load default plus posts config if no config_file is set" do
|
should "load default plus posts config if no config_file is set" do
|
||||||
allow(SafeYAML).to receive(:load_file).with(@paths[:default]).and_return({})
|
allow(SafeYAML).to receive(:load_file).with(@paths[:default]).and_return({})
|
||||||
allow($stdout).to receive(:puts).with("Configuration file: #{@paths[:default]}")
|
allow($stdout).to receive(:puts).with("Configuration file: #{@paths[:default]}")
|
||||||
assert_equal site_configuration, Jekyll.configuration(@@test_config)
|
assert_equal site_configuration, Jekyll.configuration(test_config)
|
||||||
end
|
end
|
||||||
|
|
||||||
should "load different config if specified" do
|
should "load different config if specified" do
|
||||||
allow(SafeYAML).to receive(:load_file).with(@paths[:other]).and_return({"baseurl" => "http://wahoo.dev"})
|
allow(SafeYAML)
|
||||||
|
.to receive(:load_file)
|
||||||
|
.with(@paths[:other])
|
||||||
|
.and_return({ "baseurl" => "http://wahoo.dev" })
|
||||||
allow($stdout).to receive(:puts).with("Configuration file: #{@paths[:other]}")
|
allow($stdout).to receive(:puts).with("Configuration file: #{@paths[:other]}")
|
||||||
Jekyll.configuration({ "config" => @paths[:other] })
|
Jekyll.configuration({ "config" => @paths[:other] })
|
||||||
assert_equal \
|
assert_equal \
|
||||||
site_configuration({ "baseurl" => "http://wahoo.dev" }),
|
site_configuration({ "baseurl" => "http://wahoo.dev" }),
|
||||||
Jekyll.configuration(@@test_config.merge({ "config" => @paths[:other] }))
|
Jekyll.configuration(test_config.merge({ "config" => @paths[:other] }))
|
||||||
end
|
end
|
||||||
|
|
||||||
should "load default config if path passed is empty" do
|
should "load default config if path passed is empty" do
|
||||||
|
@ -275,68 +338,94 @@ class TestConfiguration < JekyllUnitTest
|
||||||
allow($stdout).to receive(:puts).with("Configuration file: #{@paths[:default]}")
|
allow($stdout).to receive(:puts).with("Configuration file: #{@paths[:default]}")
|
||||||
assert_equal \
|
assert_equal \
|
||||||
site_configuration,
|
site_configuration,
|
||||||
Jekyll.configuration(@@test_config.merge({ "config" => [@paths[:empty]] }))
|
Jekyll.configuration(test_config.merge({ "config" => [@paths[:empty]] }))
|
||||||
end
|
end
|
||||||
|
|
||||||
should "successfully load a TOML file" do
|
should "successfully load a TOML file" do
|
||||||
Jekyll.logger.log_level = :warn
|
Jekyll.logger.log_level = :warn
|
||||||
assert_equal \
|
assert_equal \
|
||||||
site_configuration({ "baseurl" => "/you-beautiful-blog-you", "title" => "My magnificent site, wut" }),
|
site_configuration({ "baseurl" => "/you-beautiful-blog-you",
|
||||||
Jekyll.configuration(@@test_config.merge({ "config" => [@paths[:toml]] }))
|
"title" => "My magnificent site, wut" }),
|
||||||
|
Jekyll.configuration(test_config.merge({ "config" => [@paths[:toml]] }))
|
||||||
Jekyll.logger.log_level = :info
|
Jekyll.logger.log_level = :info
|
||||||
end
|
end
|
||||||
|
|
||||||
should "load multiple config files" do
|
should "load multiple config files" do
|
||||||
External.require_with_graceful_fail('toml')
|
External.require_with_graceful_fail("toml")
|
||||||
|
|
||||||
allow(SafeYAML).to receive(:load_file).with(@paths[:default]).and_return(Hash.new)
|
allow(SafeYAML).to receive(:load_file).with(@paths[:default]).and_return({})
|
||||||
allow(SafeYAML).to receive(:load_file).with(@paths[:other]).and_return(Hash.new)
|
allow(SafeYAML).to receive(:load_file).with(@paths[:other]).and_return({})
|
||||||
allow(TOML).to receive(:load_file).with(@paths[:toml]).and_return(Hash.new)
|
allow(TOML).to receive(:load_file).with(@paths[:toml]).and_return({})
|
||||||
allow($stdout).to receive(:puts).with("Configuration file: #{@paths[:default]}")
|
allow($stdout).to receive(:puts).with("Configuration file: #{@paths[:default]}")
|
||||||
allow($stdout).to receive(:puts).with("Configuration file: #{@paths[:other]}")
|
allow($stdout).to receive(:puts).with("Configuration file: #{@paths[:other]}")
|
||||||
allow($stdout).to receive(:puts).with("Configuration file: #{@paths[:toml]}")
|
allow($stdout).to receive(:puts).with("Configuration file: #{@paths[:toml]}")
|
||||||
assert_equal \
|
assert_equal(
|
||||||
site_configuration,
|
site_configuration,
|
||||||
Jekyll.configuration(@@test_config.merge({ "config" => [@paths[:default], @paths[:other], @paths[:toml]] }))
|
Jekyll.configuration(
|
||||||
|
test_config.merge(
|
||||||
|
{ "config" => [@paths[:default], @paths[:other], @paths[:toml]] }
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
should "load multiple config files and last config should win" do
|
should "load multiple config files and last config should win" do
|
||||||
allow(SafeYAML).to receive(:load_file).with(@paths[:default]).and_return({"baseurl" => "http://example.dev"})
|
allow(SafeYAML)
|
||||||
allow(SafeYAML).to receive(:load_file).with(@paths[:other]).and_return({"baseurl" => "http://wahoo.dev"})
|
.to receive(:load_file)
|
||||||
allow($stdout).to receive(:puts).with("Configuration file: #{@paths[:default]}")
|
.with(@paths[:default])
|
||||||
allow($stdout).to receive(:puts).with("Configuration file: #{@paths[:other]}")
|
.and_return({ "baseurl" => "http://example.dev" })
|
||||||
|
allow(SafeYAML)
|
||||||
|
.to receive(:load_file)
|
||||||
|
.with(@paths[:other])
|
||||||
|
.and_return({ "baseurl" => "http://wahoo.dev" })
|
||||||
|
allow($stdout)
|
||||||
|
.to receive(:puts)
|
||||||
|
.with("Configuration file: #{@paths[:default]}")
|
||||||
|
allow($stdout)
|
||||||
|
.to receive(:puts)
|
||||||
|
.with("Configuration file: #{@paths[:other]}")
|
||||||
assert_equal \
|
assert_equal \
|
||||||
site_configuration({ "baseurl" => "http://wahoo.dev" }),
|
site_configuration({ "baseurl" => "http://wahoo.dev" }),
|
||||||
Jekyll.configuration(@@test_config.merge({ "config" => [@paths[:default], @paths[:other]] }))
|
Jekyll.configuration(
|
||||||
|
test_config.merge({ "config" => [@paths[:default], @paths[:other]] })
|
||||||
|
)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context "#add_default_collections" do
|
context "#add_default_collections" do
|
||||||
should "not do anything if collections is nil" do
|
should "not do anything if collections is nil" do
|
||||||
conf = Configuration[default_configuration].tap {|c| c['collections'] = nil }
|
conf = Configuration[default_configuration].tap { |c| c["collections"] = nil }
|
||||||
assert_equal conf.add_default_collections, conf
|
assert_equal conf.add_default_collections, conf
|
||||||
assert_nil conf.add_default_collections['collections']
|
assert_nil conf.add_default_collections["collections"]
|
||||||
end
|
end
|
||||||
|
|
||||||
should "converts collections to a hash if an array" do
|
should "converts collections to a hash if an array" do
|
||||||
conf = Configuration[default_configuration].tap {|c| c['collections'] = ['docs'] }
|
conf = Configuration[default_configuration].tap do |c|
|
||||||
|
c["collections"] = ["docs"]
|
||||||
|
end
|
||||||
assert_equal conf.add_default_collections, conf.merge({
|
assert_equal conf.add_default_collections, conf.merge({
|
||||||
"collections" => {
|
"collections" => {
|
||||||
"docs" => {},
|
"docs" => {},
|
||||||
"posts" => {
|
"posts" => {
|
||||||
"output" => true,
|
"output" => true,
|
||||||
"permalink" => "/:categories/:year/:month/:day/:title:output_ext"
|
"permalink" => "/:categories/:year/:month/:day/:title:output_ext"
|
||||||
}}})
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
should "force collections.posts.output = true" do
|
should "force collections.posts.output = true" do
|
||||||
conf = Configuration[default_configuration].tap {|c| c['collections'] = {'posts' => {'output' => false}} }
|
conf = Configuration[default_configuration].tap do |c|
|
||||||
|
c["collections"] = { "posts" => { "output" => false } }
|
||||||
|
end
|
||||||
assert_equal conf.add_default_collections, conf.merge({
|
assert_equal conf.add_default_collections, conf.merge({
|
||||||
"collections" => {
|
"collections" => {
|
||||||
"posts" => {
|
"posts" => {
|
||||||
"output" => true,
|
"output" => true,
|
||||||
"permalink" => "/:categories/:year/:month/:day/:title:output_ext"
|
"permalink" => "/:categories/:year/:month/:day/:title:output_ext"
|
||||||
}}})
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
should "set collections.posts.permalink if it's not set" do
|
should "set collections.posts.permalink if it's not set" do
|
||||||
|
@ -346,13 +435,15 @@ class TestConfiguration < JekyllUnitTest
|
||||||
"posts" => {
|
"posts" => {
|
||||||
"output" => true,
|
"output" => true,
|
||||||
"permalink" => "/:categories/:year/:month/:day/:title:output_ext"
|
"permalink" => "/:categories/:year/:month/:day/:title:output_ext"
|
||||||
}}})
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
should "leave collections.posts.permalink alone if it is set" do
|
should "leave collections.posts.permalink alone if it is set" do
|
||||||
posts_permalink = "/:year/:title/"
|
posts_permalink = "/:year/:title/"
|
||||||
conf = Configuration[default_configuration].tap do |c|
|
conf = Configuration[default_configuration].tap do |c|
|
||||||
c['collections'] = {
|
c["collections"] = {
|
||||||
"posts" => { "permalink" => posts_permalink }
|
"posts" => { "permalink" => posts_permalink }
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
@ -361,7 +452,9 @@ class TestConfiguration < JekyllUnitTest
|
||||||
"posts" => {
|
"posts" => {
|
||||||
"output" => true,
|
"output" => true,
|
||||||
"permalink" => posts_permalink
|
"permalink" => posts_permalink
|
||||||
}}})
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
require 'helper'
|
require "helper"
|
||||||
|
|
||||||
class TestDocument < JekyllUnitTest
|
class TestDocument < JekyllUnitTest
|
||||||
|
|
||||||
def assert_equal_value(key, one, other)
|
def assert_equal_value(key, one, other)
|
||||||
assert_equal(one[key], other[key])
|
assert_equal(one[key], other[key])
|
||||||
end
|
end
|
||||||
|
@ -12,7 +11,9 @@ class TestDocument < JekyllUnitTest
|
||||||
"collections" => ["methods"]
|
"collections" => ["methods"]
|
||||||
})
|
})
|
||||||
@site.process
|
@site.process
|
||||||
@document = @site.collections["methods"].docs.detect {|d| d.relative_path == "_methods/configuration.md" }
|
@document = @site.collections["methods"].docs.detect do |d|
|
||||||
|
d.relative_path == "_methods/configuration.md"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
should "exist" do
|
should "exist" do
|
||||||
|
@ -86,11 +87,12 @@ class TestDocument < JekyllUnitTest
|
||||||
end
|
end
|
||||||
|
|
||||||
context "with YAML ending in three dots" do
|
context "with YAML ending in three dots" do
|
||||||
|
|
||||||
setup do
|
setup do
|
||||||
@site = fixture_site({ "collections" => ["methods"] })
|
@site = fixture_site({ "collections" => ["methods"] })
|
||||||
@site.process
|
@site.process
|
||||||
@document = @site.collections["methods"].docs.detect {|d| d.relative_path == "_methods/yaml_with_dots.md" }
|
@document = @site.collections["methods"].docs.detect do |d|
|
||||||
|
d.relative_path == "_methods/yaml_with_dots.md"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
should "know its data" do
|
should "know its data" do
|
||||||
|
@ -100,13 +102,12 @@ class TestDocument < JekyllUnitTest
|
||||||
end
|
end
|
||||||
|
|
||||||
should "output the collection name in the #to_liquid method" do
|
should "output the collection name in the #to_liquid method" do
|
||||||
assert_equal @document.to_liquid['collection'], "methods"
|
assert_equal @document.to_liquid["collection"], "methods"
|
||||||
end
|
end
|
||||||
|
|
||||||
should "output its relative path as path in Liquid" do
|
should "output its relative path as path in Liquid" do
|
||||||
assert_equal @document.to_liquid['path'], "_methods/configuration.md"
|
assert_equal @document.to_liquid["path"], "_methods/configuration.md"
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
context "a document as part of a collection with frontmatter defaults" do
|
context "a document as part of a collection with frontmatter defaults" do
|
||||||
|
@ -117,7 +118,7 @@ class TestDocument < JekyllUnitTest
|
||||||
"scope" => { "path"=>"", "type"=>"slides" },
|
"scope" => { "path"=>"", "type"=>"slides" },
|
||||||
"values" => {
|
"values" => {
|
||||||
"nested" => {
|
"nested" => {
|
||||||
"key"=>"myval",
|
"key" => "myval"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}]
|
}]
|
||||||
|
@ -154,7 +155,10 @@ class TestDocument < JekyllUnitTest
|
||||||
should "override default values in the document frontmatter" do
|
should "override default values in the document frontmatter" do
|
||||||
assert_equal "Override title", @document.data["title"]
|
assert_equal "Override title", @document.data["title"]
|
||||||
assert_equal "slide", @document.data["layout"]
|
assert_equal "slide", @document.data["layout"]
|
||||||
assert_equal({"test1"=>"override1","test2"=>"override2"}, @document.data["nested"])
|
assert_equal(
|
||||||
|
{ "test1"=>"override1", "test2"=>"override2" },
|
||||||
|
@document.data["nested"]
|
||||||
|
)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -166,7 +170,7 @@ class TestDocument < JekyllUnitTest
|
||||||
"scope" => { "path"=>"_slides", "type"=>"slides" },
|
"scope" => { "path"=>"_slides", "type"=>"slides" },
|
||||||
"values" => {
|
"values" => {
|
||||||
"nested" => {
|
"nested" => {
|
||||||
"key"=>"value123",
|
"key" => "value123"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}]
|
}]
|
||||||
|
@ -190,7 +194,7 @@ class TestDocument < JekyllUnitTest
|
||||||
"scope" => { "path"=>"somepath", "type"=>"slides" },
|
"scope" => { "path"=>"somepath", "type"=>"slides" },
|
||||||
"values" => {
|
"values" => {
|
||||||
"nested" => {
|
"nested" => {
|
||||||
"key"=>"myval",
|
"key" => "myval"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}]
|
}]
|
||||||
|
@ -259,9 +263,9 @@ class TestDocument < JekyllUnitTest
|
||||||
@site = fixture_site({
|
@site = fixture_site({
|
||||||
"collections" => {
|
"collections" => {
|
||||||
"slides" => {
|
"slides" => {
|
||||||
"output" => true,
|
"output" => true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
|
||||||
})
|
})
|
||||||
@site.permalink_style = :pretty
|
@site.permalink_style = :pretty
|
||||||
@site.process
|
@site.process
|
||||||
|
@ -283,9 +287,9 @@ class TestDocument < JekyllUnitTest
|
||||||
@site = fixture_site({
|
@site = fixture_site({
|
||||||
"collections" => {
|
"collections" => {
|
||||||
"slides" => {
|
"slides" => {
|
||||||
"output" => true,
|
"output" => true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
|
||||||
})
|
})
|
||||||
@site.permalink_style = :pretty
|
@site.permalink_style = :pretty
|
||||||
@site.process
|
@site.process
|
||||||
|
@ -337,7 +341,7 @@ class TestDocument < JekyllUnitTest
|
||||||
"output" => true,
|
"output" => true,
|
||||||
"permalink" => "/slides/:title"
|
"permalink" => "/slides/:title"
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
})
|
})
|
||||||
@site.process
|
@site.process
|
||||||
@document = @site.collections["slides"].docs[3]
|
@document = @site.collections["slides"].docs[3]
|
||||||
|
@ -363,7 +367,10 @@ class TestDocument < JekyllUnitTest
|
||||||
end
|
end
|
||||||
|
|
||||||
should "produce the right URL if they have a wild slug" do
|
should "produce the right URL if they have a wild slug" do
|
||||||
assert_equal "/slides/Well,-so-what-is-Jekyll,-then", @document_with_strange_slug.url
|
assert_equal(
|
||||||
|
"/slides/Well,-so-what-is-Jekyll,-then",
|
||||||
|
@document_with_strange_slug.url
|
||||||
|
)
|
||||||
end
|
end
|
||||||
should "produce the right destination file if they have a wild slug" do
|
should "produce the right destination file if they have a wild slug" do
|
||||||
dest_file = dest_dir("/slides/Well,-so-what-is-Jekyll,-then.html")
|
dest_file = dest_dir("/slides/Well,-so-what-is-Jekyll,-then.html")
|
||||||
|
@ -401,7 +408,7 @@ class TestDocument < JekyllUnitTest
|
||||||
"slides" => {
|
"slides" => {
|
||||||
"output" => true
|
"output" => true
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
})
|
})
|
||||||
@site.process
|
@site.process
|
||||||
@files = @site.collections["slides"].docs
|
@files = @site.collections["slides"].docs
|
||||||
|
@ -409,13 +416,17 @@ class TestDocument < JekyllUnitTest
|
||||||
|
|
||||||
context "without output overrides" do
|
context "without output overrides" do
|
||||||
should "be output according to collection defaults" do
|
should "be output according to collection defaults" do
|
||||||
refute_nil @files.find { |doc| doc.relative_path == "_slides/example-slide-4.html" }
|
refute_nil @files.find do |doc|
|
||||||
|
doc.relative_path == "_slides/example-slide-4.html"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context "with output overrides" do
|
context "with output overrides" do
|
||||||
should "be output according its front matter" do
|
should "be output according its front matter" do
|
||||||
assert_nil @files.find { |doc| doc.relative_path == "_slides/non-outputted-slide.html" }
|
assert_nil @files.find { |doc|
|
||||||
|
doc.relative_path == "_slides/non-outputted-slide.html"
|
||||||
|
}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -430,7 +441,9 @@ class TestDocument < JekyllUnitTest
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@site.process
|
@site.process
|
||||||
@document = @site.collections["slides"].files.find { |doc| doc.relative_path == "_slides/octojekyll.png" }
|
@document = @site.collections["slides"].files.find do |doc|
|
||||||
|
doc.relative_path == "_slides/octojekyll.png"
|
||||||
|
end
|
||||||
@dest_file = dest_dir("slides/octojekyll.png")
|
@dest_file = dest_dir("slides/octojekyll.png")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -458,10 +471,12 @@ class TestDocument < JekyllUnitTest
|
||||||
"methods" => {
|
"methods" => {
|
||||||
"output" => true
|
"output" => true
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
})
|
})
|
||||||
@site.process
|
@site.process
|
||||||
@document = @site.collections["methods"].docs.find { |doc| doc.relative_path == "_methods/escape-+ #%20[].md" }
|
@document = @site.collections["methods"].docs.find do |doc|
|
||||||
|
doc.relative_path == "_methods/escape-+ #%20[].md"
|
||||||
|
end
|
||||||
@dest_file = dest_dir("methods/escape-+ #%20[].html")
|
@dest_file = dest_dir("methods/escape-+ #%20[].html")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -476,7 +491,5 @@ class TestDocument < JekyllUnitTest
|
||||||
should "be output in the correct place" do
|
should "be output in the correct place" do
|
||||||
assert_equal true, File.file?(@dest_file)
|
assert_equal true, File.file?(@dest_file)
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
require 'helper'
|
require "helper"
|
||||||
|
|
||||||
class TestEntryFilter < JekyllUnitTest
|
class TestEntryFilter < JekyllUnitTest
|
||||||
context "Filtering entries" do
|
context "Filtering entries" do
|
||||||
|
@ -7,16 +7,16 @@ class TestEntryFilter < JekyllUnitTest
|
||||||
end
|
end
|
||||||
|
|
||||||
should "filter entries" do
|
should "filter entries" do
|
||||||
ent1 = %w[foo.markdown bar.markdown baz.markdown #baz.markdown#
|
ent1 = %w(foo.markdown bar.markdown baz.markdown #baz.markdown#
|
||||||
.baz.markdow foo.markdown~ .htaccess _posts _pages ~$benbalter.docx]
|
.baz.markdow foo.markdown~ .htaccess _posts _pages ~$benbalter.docx)
|
||||||
|
|
||||||
entries = EntryFilter.new(@site).filter(ent1)
|
entries = EntryFilter.new(@site).filter(ent1)
|
||||||
assert_equal %w[foo.markdown bar.markdown baz.markdown .htaccess], entries
|
assert_equal %w(foo.markdown bar.markdown baz.markdown .htaccess), entries
|
||||||
end
|
end
|
||||||
|
|
||||||
should "allow regexp filtering" do
|
should "allow regexp filtering" do
|
||||||
files = %w(README.md)
|
files = %w(README.md)
|
||||||
@site.exclude = excludes = [
|
@site.exclude = [
|
||||||
/README/
|
/README/
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -26,63 +26,69 @@ class TestEntryFilter < JekyllUnitTest
|
||||||
end
|
end
|
||||||
|
|
||||||
should "filter entries with exclude" do
|
should "filter entries with exclude" do
|
||||||
excludes = %w[README TODO vendor/bundle]
|
excludes = %w(README TODO vendor/bundle)
|
||||||
files = %w[index.html site.css .htaccess vendor]
|
files = %w(index.html site.css .htaccess vendor)
|
||||||
|
|
||||||
@site.exclude = excludes + ["exclude*"]
|
@site.exclude = excludes + ["exclude*"]
|
||||||
assert_equal files, @site.reader.filter_entries(excludes + files + ["excludeA"])
|
assert_equal files, @site.reader.filter_entries(excludes + files + ["excludeA"])
|
||||||
end
|
end
|
||||||
|
|
||||||
should "filter entries with exclude relative to site source" do
|
should "filter entries with exclude relative to site source" do
|
||||||
excludes = %w[README TODO css]
|
excludes = %w(README TODO css)
|
||||||
files = %w[index.html vendor/css .htaccess]
|
files = %w(index.html vendor/css .htaccess)
|
||||||
|
|
||||||
@site.exclude = excludes
|
@site.exclude = excludes
|
||||||
assert_equal files, @site.reader.filter_entries(excludes + files + ["css"])
|
assert_equal files, @site.reader.filter_entries(excludes + files + ["css"])
|
||||||
end
|
end
|
||||||
|
|
||||||
should "filter excluded directory and contained files" do
|
should "filter excluded directory and contained files" do
|
||||||
excludes = %w[README TODO css]
|
excludes = %w(README TODO css)
|
||||||
files = %w[index.html .htaccess]
|
files = %w(index.html .htaccess)
|
||||||
|
|
||||||
@site.exclude = excludes
|
@site.exclude = excludes
|
||||||
assert_equal files, @site.reader.filter_entries(excludes + files + ["css", "css/main.css", "css/vendor.css"])
|
assert_equal(
|
||||||
|
files,
|
||||||
|
@site.reader.filter_entries(
|
||||||
|
excludes + files + ["css", "css/main.css", "css/vendor.css"]
|
||||||
|
)
|
||||||
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
should "not filter entries within include" do
|
should "not filter entries within include" do
|
||||||
includes = %w[_index.html .htaccess include*]
|
includes = %w(_index.html .htaccess include*)
|
||||||
files = %w[index.html _index.html .htaccess includeA]
|
files = %w(index.html _index.html .htaccess includeA)
|
||||||
|
|
||||||
@site.include = includes
|
@site.include = includes
|
||||||
assert_equal files, @site.reader.filter_entries(files)
|
assert_equal files, @site.reader.filter_entries(files)
|
||||||
end
|
end
|
||||||
|
|
||||||
should "keep safe symlink entries when safe mode enabled" do
|
should "keep safe symlink entries when safe mode enabled" do
|
||||||
site = Site.new(site_configuration('safe' => true))
|
allow(File).to receive(:symlink?).with("symlink.js").and_return(true)
|
||||||
allow(File).to receive(:symlink?).with('symlink.js').and_return(true)
|
files = %w(symlink.js)
|
||||||
files = %w[symlink.js]
|
|
||||||
assert_equal files, @site.reader.filter_entries(files)
|
assert_equal files, @site.reader.filter_entries(files)
|
||||||
end
|
end
|
||||||
|
|
||||||
should "not filter symlink entries when safe mode disabled" do
|
should "not filter symlink entries when safe mode disabled" do
|
||||||
allow(File).to receive(:symlink?).with('symlink.js').and_return(true)
|
allow(File).to receive(:symlink?).with("symlink.js").and_return(true)
|
||||||
files = %w[symlink.js]
|
files = %w(symlink.js)
|
||||||
assert_equal files, @site.reader.filter_entries(files)
|
assert_equal files, @site.reader.filter_entries(files)
|
||||||
end
|
end
|
||||||
|
|
||||||
should "filter symlink pointing outside site source" do
|
should "filter symlink pointing outside site source" do
|
||||||
ent1 = %w[_includes/tmp]
|
ent1 = %w(_includes/tmp)
|
||||||
entries = EntryFilter.new(@site).filter(ent1)
|
entries = EntryFilter.new(@site).filter(ent1)
|
||||||
assert_equal %w[], entries
|
assert_equal %w(), entries
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# rubocop:disable Performance/FixedSize
|
||||||
should "include only safe symlinks in safe mode" do
|
should "include only safe symlinks in safe mode" do
|
||||||
site = Site.new(site_configuration('safe' => true))
|
site = Site.new(site_configuration("safe" => true))
|
||||||
|
|
||||||
site.reader.read_directories("symlink-test")
|
site.reader.read_directories("symlink-test")
|
||||||
assert_equal %w[main.scss symlinked-file].length, site.pages.length
|
|
||||||
|
assert_equal %w(main.scss symlinked-file).length, site.pages.length
|
||||||
refute_equal [], site.static_files
|
refute_equal [], site.static_files
|
||||||
end
|
end
|
||||||
|
# rubocop:enable Performance/FixedSize
|
||||||
|
|
||||||
should "include symlinks in unsafe mode" do
|
should "include symlinks in unsafe mode" do
|
||||||
site = Site.new(site_configuration)
|
site = Site.new(site_configuration)
|
||||||
|
@ -118,9 +124,9 @@ class TestEntryFilter < JekyllUnitTest
|
||||||
end
|
end
|
||||||
|
|
||||||
should "match even if there is no leading slash" do
|
should "match even if there is no leading slash" do
|
||||||
data = ['vendor/bundle']
|
data = ["vendor/bundle"]
|
||||||
assert @filter.glob_include?(data, '/vendor/bundle')
|
assert @filter.glob_include?(data, "/vendor/bundle")
|
||||||
assert @filter.glob_include?(data, 'vendor/bundle')
|
assert @filter.glob_include?(data, "vendor/bundle")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
# coding: utf-8
|
# coding: utf-8
|
||||||
|
|
||||||
require 'helper'
|
require "helper"
|
||||||
|
|
||||||
class TestFilters < JekyllUnitTest
|
class TestFilters < JekyllUnitTest
|
||||||
class JekyllFilter
|
class JekyllFilter
|
||||||
|
@ -8,18 +8,24 @@ class TestFilters < JekyllUnitTest
|
||||||
attr_accessor :site, :context
|
attr_accessor :site, :context
|
||||||
|
|
||||||
def initialize(opts = {})
|
def initialize(opts = {})
|
||||||
@site = Jekyll::Site.new(Jekyll.configuration(opts.merge('skip_config_files' => true)))
|
@site = Jekyll::Site.new(
|
||||||
|
Jekyll.configuration(opts.merge("skip_config_files" => true))
|
||||||
|
)
|
||||||
@context = Liquid::Context.new({}, {}, { :site => @site })
|
@context = Liquid::Context.new({}, {}, { :site => @site })
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context "filters" do
|
context "filters" do
|
||||||
setup do
|
setup do
|
||||||
@filter = JekyllFilter.new({"source" => source_dir, "destination" => dest_dir, "timezone" => "UTC"})
|
@filter = JekyllFilter.new({
|
||||||
|
"source" => source_dir,
|
||||||
|
"destination" => dest_dir,
|
||||||
|
"timezone" => "UTC"
|
||||||
|
})
|
||||||
@sample_time = Time.utc(2013, 03, 27, 11, 22, 33)
|
@sample_time = Time.utc(2013, 03, 27, 11, 22, 33)
|
||||||
@sample_date = Date.parse("2013-03-27")
|
@sample_date = Date.parse("2013-03-27")
|
||||||
@time_as_string = "September 11, 2001 12:46:30 -0000"
|
@time_as_string = "September 11, 2001 12:46:30 -0000"
|
||||||
@time_as_numeric = 1399680607
|
@time_as_numeric = 1_399_680_607
|
||||||
@array_of_objects = [
|
@array_of_objects = [
|
||||||
{ "color" => "red", "size" => "large" },
|
{ "color" => "red", "size" => "large" },
|
||||||
{ "color" => "red", "size" => "medium" },
|
{ "color" => "red", "size" => "medium" },
|
||||||
|
@ -28,18 +34,30 @@ class TestFilters < JekyllUnitTest
|
||||||
end
|
end
|
||||||
|
|
||||||
should "markdownify with simple string" do
|
should "markdownify with simple string" do
|
||||||
assert_equal "<p>something <strong>really</strong> simple</p>\n", @filter.markdownify("something **really** simple")
|
assert_equal(
|
||||||
|
"<p>something <strong>really</strong> simple</p>\n",
|
||||||
|
@filter.markdownify("something **really** simple")
|
||||||
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
context "smartify filter" do
|
context "smartify filter" do
|
||||||
should "convert quotes and typographic characters" do
|
should "convert quotes and typographic characters" do
|
||||||
assert_equal "SmartyPants is *not* Markdown", @filter.smartify("SmartyPants is *not* Markdown")
|
assert_equal(
|
||||||
assert_equal "“This filter’s test…”", @filter.smartify(%q{"This filter's test..."})
|
"SmartyPants is *not* Markdown",
|
||||||
|
@filter.smartify("SmartyPants is *not* Markdown")
|
||||||
|
)
|
||||||
|
assert_equal(
|
||||||
|
"“This filter’s test…”",
|
||||||
|
@filter.smartify(%q{"This filter's test..."})
|
||||||
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
should "escapes special characters when configured to do so" do
|
should "escapes special characters when configured to do so" do
|
||||||
kramdown = JekyllFilter.new({ :kramdown => { :entity_output => :symbolic } })
|
kramdown = JekyllFilter.new({ :kramdown => { :entity_output => :symbolic } })
|
||||||
assert_equal "“This filter’s test…”", kramdown.smartify(%q{"This filter's test..."})
|
assert_equal(
|
||||||
|
"“This filter’s test…”",
|
||||||
|
kramdown.smartify(%q{"This filter's test..."})
|
||||||
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
should "convert HTML entities to unicode characters" do
|
should "convert HTML entities to unicode characters" do
|
||||||
|
@ -48,8 +66,14 @@ class TestFilters < JekyllUnitTest
|
||||||
end
|
end
|
||||||
|
|
||||||
should "allow raw HTML passthrough" do
|
should "allow raw HTML passthrough" do
|
||||||
assert_equal "Span HTML is <em>not</em> escaped", @filter.smartify("Span HTML is <em>not</em> escaped")
|
assert_equal(
|
||||||
assert_equal "<div>Block HTML is not escaped</div>", @filter.smartify("<div>Block HTML is not escaped</div>")
|
"Span HTML is <em>not</em> escaped",
|
||||||
|
@filter.smartify("Span HTML is <em>not</em> escaped")
|
||||||
|
)
|
||||||
|
assert_equal(
|
||||||
|
"<div>Block HTML is not escaped</div>",
|
||||||
|
@filter.smartify("<div>Block HTML is not escaped</div>")
|
||||||
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
should "escape special characters" do
|
should "escape special characters" do
|
||||||
|
@ -60,11 +84,17 @@ class TestFilters < JekyllUnitTest
|
||||||
end
|
end
|
||||||
|
|
||||||
should "sassify with simple string" do
|
should "sassify with simple string" do
|
||||||
assert_equal "p {\n color: #123456; }\n", @filter.sassify("$blue:#123456\np\n color: $blue")
|
assert_equal(
|
||||||
|
"p {\n color: #123456; }\n",
|
||||||
|
@filter.sassify("$blue:#123456\np\n color: $blue")
|
||||||
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
should "scssify with simple string" do
|
should "scssify with simple string" do
|
||||||
assert_equal "p {\n color: #123456; }\n", @filter.scssify("$blue:#123456; p{color: $blue}")
|
assert_equal(
|
||||||
|
"p {\n color: #123456; }\n",
|
||||||
|
@filter.scssify("$blue:#123456; p{color: $blue}")
|
||||||
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
should "convert array to sentence string with no args" do
|
should "convert array to sentence string with no args" do
|
||||||
|
@ -78,12 +108,15 @@ class TestFilters < JekyllUnitTest
|
||||||
|
|
||||||
should "convert array to sentence string with two args" do
|
should "convert array to sentence string with two args" do
|
||||||
assert_equal "1 and 2", @filter.array_to_sentence_string([1, 2])
|
assert_equal "1 and 2", @filter.array_to_sentence_string([1, 2])
|
||||||
assert_equal "chunky and bacon", @filter.array_to_sentence_string(["chunky", "bacon"])
|
assert_equal "chunky and bacon", @filter.array_to_sentence_string(%w(chunky bacon))
|
||||||
end
|
end
|
||||||
|
|
||||||
should "convert array to sentence string with multiple args" do
|
should "convert array to sentence string with multiple args" do
|
||||||
assert_equal "1, 2, 3, and 4", @filter.array_to_sentence_string([1, 2, 3, 4])
|
assert_equal "1, 2, 3, and 4", @filter.array_to_sentence_string([1, 2, 3, 4])
|
||||||
assert_equal "chunky, bacon, bits, and pieces", @filter.array_to_sentence_string(["chunky", "bacon", "bits", "pieces"])
|
assert_equal(
|
||||||
|
"chunky, bacon, bits, and pieces",
|
||||||
|
@filter.array_to_sentence_string(%w(chunky bacon bits pieces))
|
||||||
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
context "date filters" do
|
context "date filters" do
|
||||||
|
@ -97,11 +130,17 @@ class TestFilters < JekyllUnitTest
|
||||||
end
|
end
|
||||||
|
|
||||||
should "format a time with xmlschema" do
|
should "format a time with xmlschema" do
|
||||||
assert_equal "2013-03-27T11:22:33+00:00", @filter.date_to_xmlschema(@sample_time)
|
assert_equal(
|
||||||
|
"2013-03-27T11:22:33+00:00",
|
||||||
|
@filter.date_to_xmlschema(@sample_time)
|
||||||
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
should "format a time according to RFC-822" do
|
should "format a time according to RFC-822" do
|
||||||
assert_equal "Wed, 27 Mar 2013 11:22:33 +0000", @filter.date_to_rfc822(@sample_time)
|
assert_equal(
|
||||||
|
"Wed, 27 Mar 2013 11:22:33 +0000",
|
||||||
|
@filter.date_to_rfc822(@sample_time)
|
||||||
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
should "not modify a time in-place when using filters" do
|
should "not modify a time in-place when using filters" do
|
||||||
|
@ -122,11 +161,17 @@ class TestFilters < JekyllUnitTest
|
||||||
end
|
end
|
||||||
|
|
||||||
should "format a time with xmlschema" do
|
should "format a time with xmlschema" do
|
||||||
assert_equal "2013-03-27T00:00:00+00:00", @filter.date_to_xmlschema(@sample_date)
|
assert_equal(
|
||||||
|
"2013-03-27T00:00:00+00:00",
|
||||||
|
@filter.date_to_xmlschema(@sample_date)
|
||||||
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
should "format a time according to RFC-822" do
|
should "format a time according to RFC-822" do
|
||||||
assert_equal "Wed, 27 Mar 2013 00:00:00 +0000", @filter.date_to_rfc822(@sample_date)
|
assert_equal(
|
||||||
|
"Wed, 27 Mar 2013 00:00:00 +0000",
|
||||||
|
@filter.date_to_rfc822(@sample_date)
|
||||||
|
)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -140,11 +185,17 @@ class TestFilters < JekyllUnitTest
|
||||||
end
|
end
|
||||||
|
|
||||||
should "format a time with xmlschema" do
|
should "format a time with xmlschema" do
|
||||||
assert_equal "2001-09-11T12:46:30+00:00", @filter.date_to_xmlschema(@time_as_string)
|
assert_equal(
|
||||||
|
"2001-09-11T12:46:30+00:00",
|
||||||
|
@filter.date_to_xmlschema(@time_as_string)
|
||||||
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
should "format a time according to RFC-822" do
|
should "format a time according to RFC-822" do
|
||||||
assert_equal "Tue, 11 Sep 2001 12:46:30 +0000", @filter.date_to_rfc822(@time_as_string)
|
assert_equal(
|
||||||
|
"Tue, 11 Sep 2001 12:46:30 +0000",
|
||||||
|
@filter.date_to_rfc822(@time_as_string)
|
||||||
|
)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -158,18 +209,27 @@ class TestFilters < JekyllUnitTest
|
||||||
end
|
end
|
||||||
|
|
||||||
should "format a time with xmlschema" do
|
should "format a time with xmlschema" do
|
||||||
assert_match(/2014-05-10T00:10:07/, @filter.date_to_xmlschema(@time_as_numeric))
|
assert_match(
|
||||||
|
"2014-05-10T00:10:07",
|
||||||
|
@filter.date_to_xmlschema(@time_as_numeric)
|
||||||
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
should "format a time according to RFC-822" do
|
should "format a time according to RFC-822" do
|
||||||
assert_equal "Sat, 10 May 2014 00:10:07 +0000", @filter.date_to_rfc822(@time_as_numeric)
|
assert_equal(
|
||||||
|
"Sat, 10 May 2014 00:10:07 +0000",
|
||||||
|
@filter.date_to_rfc822(@time_as_numeric)
|
||||||
|
)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
should "escape xml with ampersands" do
|
should "escape xml with ampersands" do
|
||||||
assert_equal "AT&T", @filter.xml_escape("AT&T")
|
assert_equal "AT&T", @filter.xml_escape("AT&T")
|
||||||
assert_equal "<code>command &lt;filename&gt;</code>", @filter.xml_escape("<code>command <filename></code>")
|
assert_equal(
|
||||||
|
"<code>command &lt;filename&gt;</code>",
|
||||||
|
@filter.xml_escape("<code>command <filename></code>")
|
||||||
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
should "not error when xml escaping nil" do
|
should "not error when xml escaping nil" do
|
||||||
|
@ -195,7 +255,10 @@ class TestFilters < JekyllUnitTest
|
||||||
|
|
||||||
should "convert array to json" do
|
should "convert array to json" do
|
||||||
assert_equal "[1,2]", @filter.jsonify([1, 2])
|
assert_equal "[1,2]", @filter.jsonify([1, 2])
|
||||||
assert_equal "[{\"name\":\"Jack\"},{\"name\":\"Smith\"}]", @filter.jsonify([{:name => 'Jack'}, {:name => 'Smith'}])
|
assert_equal(
|
||||||
|
"[{\"name\":\"Jack\"},{\"name\":\"Smith\"}]",
|
||||||
|
@filter.jsonify([{ :name => "Jack" }, { :name => "Smith" }])
|
||||||
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
should "convert drop to json" do
|
should "convert drop to json" do
|
||||||
|
@ -240,6 +303,7 @@ class TestFilters < JekyllUnitTest
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# rubocop:disable Style/StructInheritance
|
||||||
class M < Struct.new(:message)
|
class M < Struct.new(:message)
|
||||||
def to_liquid
|
def to_liquid
|
||||||
[message]
|
[message]
|
||||||
|
@ -247,7 +311,12 @@ class TestFilters < JekyllUnitTest
|
||||||
end
|
end
|
||||||
class T < Struct.new(:name)
|
class T < Struct.new(:name)
|
||||||
def to_liquid
|
def to_liquid
|
||||||
{ "name" => name, :v => 1, :thing => M.new({:kay => "jewelers"}), :stuff => true }
|
{
|
||||||
|
"name" => name,
|
||||||
|
:v => 1,
|
||||||
|
:thing => M.new({ :kay => "jewelers" }),
|
||||||
|
:stuff => true
|
||||||
|
}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -277,6 +346,7 @@ class TestFilters < JekyllUnitTest
|
||||||
result = @filter.jsonify([T.new("Jeremiah"), T.new("Smathers")])
|
result = @filter.jsonify([T.new("Jeremiah"), T.new("Smathers")])
|
||||||
assert_equal expected, JSON.parse(result)
|
assert_equal expected, JSON.parse(result)
|
||||||
end
|
end
|
||||||
|
# rubocop:enable Style/StructInheritance
|
||||||
|
|
||||||
should "handle hashes with all sorts of weird keys and values" do
|
should "handle hashes with all sorts of weird keys and values" do
|
||||||
my_hash = { "posts" => Array.new(3) { |i| T.new(i) } }
|
my_hash = { "posts" => Array.new(3) { |i| T.new(i) } }
|
||||||
|
@ -324,16 +394,28 @@ class TestFilters < JekyllUnitTest
|
||||||
@filter.site.process
|
@filter.site.process
|
||||||
grouping = @filter.group_by(@filter.site.pages, "layout")
|
grouping = @filter.group_by(@filter.site.pages, "layout")
|
||||||
grouping.each do |g|
|
grouping.each do |g|
|
||||||
assert ["default", "nil", ""].include?(g["name"]), "#{g['name']} isn't a valid grouping."
|
assert(
|
||||||
|
["default", "nil", ""].include?(g["name"]),
|
||||||
|
"#{g["name"]} isn't a valid grouping."
|
||||||
|
)
|
||||||
case g["name"]
|
case g["name"]
|
||||||
when "default"
|
when "default"
|
||||||
assert g["items"].is_a?(Array), "The list of grouped items for 'default' is not an Array."
|
assert(
|
||||||
|
g["items"].is_a?(Array),
|
||||||
|
"The list of grouped items for 'default' is not an Array."
|
||||||
|
)
|
||||||
assert_equal 5, g["items"].size
|
assert_equal 5, g["items"].size
|
||||||
when "nil"
|
when "nil"
|
||||||
assert g["items"].is_a?(Array), "The list of grouped items for 'nil' is not an Array."
|
assert(
|
||||||
|
g["items"].is_a?(Array),
|
||||||
|
"The list of grouped items for 'nil' is not an Array."
|
||||||
|
)
|
||||||
assert_equal 2, g["items"].size
|
assert_equal 2, g["items"].size
|
||||||
when ""
|
when ""
|
||||||
assert g["items"].is_a?(Array), "The list of grouped items for '' is not an Array."
|
assert(
|
||||||
|
g["items"].is_a?(Array),
|
||||||
|
"The list of grouped items for '' is not an Array."
|
||||||
|
)
|
||||||
assert_equal 13, g["items"].size
|
assert_equal 13, g["items"].size
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -343,7 +425,11 @@ class TestFilters < JekyllUnitTest
|
||||||
grouping = @filter.group_by(@filter.site.pages, "layout")
|
grouping = @filter.group_by(@filter.site.pages, "layout")
|
||||||
grouping.each do |g|
|
grouping.each do |g|
|
||||||
p g
|
p g
|
||||||
assert_equal g["items"].size, g["size"], "The size property for '#{g["name"]}' doesn't match the size of the Array."
|
assert_equal(
|
||||||
|
g["items"].size,
|
||||||
|
g["size"],
|
||||||
|
"The size property for '#{g["name"]}' doesn't match the size of the Array."
|
||||||
|
)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -364,17 +450,29 @@ class TestFilters < JekyllUnitTest
|
||||||
end
|
end
|
||||||
|
|
||||||
should "filter array properties appropriately" do
|
should "filter array properties appropriately" do
|
||||||
hash = {"a"=>{"tags"=>["x","y"]}, "b"=>{"tags"=>["x"]}, "c"=>{"tags"=>["y","z"]}}
|
hash = {
|
||||||
|
"a" => { "tags"=>%w(x y) },
|
||||||
|
"b" => { "tags"=>["x"] },
|
||||||
|
"c" => { "tags"=>%w(y z) }
|
||||||
|
}
|
||||||
assert_equal 2, @filter.where(hash, "tags", "x").length
|
assert_equal 2, @filter.where(hash, "tags", "x").length
|
||||||
end
|
end
|
||||||
|
|
||||||
should "filter array properties alongside string properties" do
|
should "filter array properties alongside string properties" do
|
||||||
hash = {"a"=>{"tags"=>["x","y"]}, "b"=>{"tags"=>"x"}, "c"=>{"tags"=>["y","z"]}}
|
hash = {
|
||||||
|
"a" => { "tags"=>%w(x y) },
|
||||||
|
"b" => { "tags"=>"x" },
|
||||||
|
"c" => { "tags"=>%w(y z) }
|
||||||
|
}
|
||||||
assert_equal 2, @filter.where(hash, "tags", "x").length
|
assert_equal 2, @filter.where(hash, "tags", "x").length
|
||||||
end
|
end
|
||||||
|
|
||||||
should "not match substrings" do
|
should "not match substrings" do
|
||||||
hash = {"a"=>{"category"=>"bear"}, "b"=>{"category"=>"wolf"}, "c"=>{"category"=>["bear","lion"]}}
|
hash = {
|
||||||
|
"a" => { "category"=>"bear" },
|
||||||
|
"b" => { "category"=>"wolf" },
|
||||||
|
"c" => { "category"=>%w(bear lion) }
|
||||||
|
}
|
||||||
assert_equal 0, @filter.where(hash, "category", "ear").length
|
assert_equal 0, @filter.where(hash, "category", "ear").length
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -382,7 +480,7 @@ class TestFilters < JekyllUnitTest
|
||||||
hash = {
|
hash = {
|
||||||
"The Words" => { "rating" => 1.2, "featured" => false },
|
"The Words" => { "rating" => 1.2, "featured" => false },
|
||||||
"Limitless" => { "rating" => 9.2, "featured" => true },
|
"Limitless" => { "rating" => 9.2, "featured" => true },
|
||||||
"Hustle" => {"rating" => 4.7, "featured" => true},
|
"Hustle" => { "rating" => 4.7, "featured" => true }
|
||||||
}
|
}
|
||||||
|
|
||||||
results = @filter.where(hash, "featured", "true")
|
results = @filter.where(hash, "featured", "true")
|
||||||
|
@ -404,18 +502,24 @@ class TestFilters < JekyllUnitTest
|
||||||
should "filter objects in a hash appropriately" do
|
should "filter objects in a hash appropriately" do
|
||||||
hash = { "a"=>{ "color"=>"red" }, "b"=>{ "color"=>"blue" } }
|
hash = { "a"=>{ "color"=>"red" }, "b"=>{ "color"=>"blue" } }
|
||||||
assert_equal 1, @filter.where_exp(hash, "item", "item.color == 'red'").length
|
assert_equal 1, @filter.where_exp(hash, "item", "item.color == 'red'").length
|
||||||
assert_equal [{"color"=>"red"}], @filter.where_exp(hash, "item", "item.color == 'red'")
|
assert_equal(
|
||||||
|
[{ "color"=>"red" }],
|
||||||
|
@filter.where_exp(hash, "item", "item.color == 'red'")
|
||||||
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
should "filter objects appropriately" do
|
should "filter objects appropriately" do
|
||||||
assert_equal 2, @filter.where_exp(@array_of_objects, "item", "item.color == 'red'").length
|
assert_equal(
|
||||||
|
2,
|
||||||
|
@filter.where_exp(@array_of_objects, "item", "item.color == 'red'").length
|
||||||
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
should "stringify during comparison for compatibility with liquid parsing" do
|
should "stringify during comparison for compatibility with liquid parsing" do
|
||||||
hash = {
|
hash = {
|
||||||
"The Words" => { "rating" => 1.2, "featured" => false },
|
"The Words" => { "rating" => 1.2, "featured" => false },
|
||||||
"Limitless" => { "rating" => 9.2, "featured" => true },
|
"Limitless" => { "rating" => 9.2, "featured" => true },
|
||||||
"Hustle" => {"rating" => 4.7, "featured" => true},
|
"Hustle" => { "rating" => 4.7, "featured" => true }
|
||||||
}
|
}
|
||||||
|
|
||||||
results = @filter.where_exp(hash, "item", "item.featured == true")
|
results = @filter.where_exp(hash, "item", "item.featured == true")
|
||||||
|
@ -465,15 +569,18 @@ class TestFilters < JekyllUnitTest
|
||||||
assert_equal [1, 2, 2.2, 3], @filter.sort([3, 2.2, 2, 1])
|
assert_equal [1, 2, 2.2, 3], @filter.sort([3, 2.2, 2, 1])
|
||||||
end
|
end
|
||||||
should "return sorted strings" do
|
should "return sorted strings" do
|
||||||
assert_equal ["10", "2"], @filter.sort(["10", "2"])
|
assert_equal %w(10 2), @filter.sort(%w(10 2))
|
||||||
assert_equal [{"a" => "10"}, {"a" => "2"}], @filter.sort([{"a" => "10"}, {"a" => "2"}], "a")
|
assert_equal(
|
||||||
assert_equal ["FOO", "Foo", "foo"], @filter.sort(["foo", "Foo", "FOO"])
|
[{ "a" => "10" }, { "a" => "2" }],
|
||||||
assert_equal ["_foo", "foo", "foo_"], @filter.sort(["foo_", "_foo", "foo"])
|
@filter.sort([{ "a" => "10" }, { "a" => "2" }], "a")
|
||||||
|
)
|
||||||
|
assert_equal %w(FOO Foo foo), @filter.sort(%w(foo Foo FOO))
|
||||||
|
assert_equal %w(_foo foo foo_), @filter.sort(%w(foo_ _foo foo))
|
||||||
# Cyrillic
|
# Cyrillic
|
||||||
assert_equal ["ВУЗ", "Вуз", "вуз"], @filter.sort(["Вуз", "вуз", "ВУЗ"])
|
assert_equal %w(ВУЗ Вуз вуз), @filter.sort(%w(Вуз вуз ВУЗ))
|
||||||
assert_equal ["_вуз", "вуз", "вуз_"], @filter.sort(["вуз_", "_вуз", "вуз"])
|
assert_equal %w(_вуз вуз вуз_), @filter.sort(%w(вуз_ _вуз вуз))
|
||||||
# Hebrew
|
# Hebrew
|
||||||
assert_equal ["אלף", "בית"], @filter.sort(["בית", "אלף"])
|
assert_equal %w(אלף בית), @filter.sort(%w(בית אלף))
|
||||||
end
|
end
|
||||||
should "return sorted by property array" do
|
should "return sorted by property array" do
|
||||||
assert_equal [{ "a" => 1 }, { "a" => 2 }, { "a" => 3 }, { "a" => 4 }],
|
assert_equal [{ "a" => 1 }, { "a" => 2 }, { "a" => 3 }, { "a" => 4 }],
|
||||||
|
@ -512,41 +619,41 @@ class TestFilters < JekyllUnitTest
|
||||||
|
|
||||||
context "push filter" do
|
context "push filter" do
|
||||||
should "return a new array with the element pushed to the end" do
|
should "return a new array with the element pushed to the end" do
|
||||||
assert_equal %w{hi there bernie}, @filter.push(%w{hi there}, "bernie")
|
assert_equal %w(hi there bernie), @filter.push(%w(hi there), "bernie")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context "pop filter" do
|
context "pop filter" do
|
||||||
should "return a new array with the last element popped" do
|
should "return a new array with the last element popped" do
|
||||||
assert_equal %w{hi there}, @filter.pop(%w{hi there bernie})
|
assert_equal %w(hi there), @filter.pop(%w(hi there bernie))
|
||||||
end
|
end
|
||||||
|
|
||||||
should "allow multiple els to be popped" do
|
should "allow multiple els to be popped" do
|
||||||
assert_equal %w{hi there bert}, @filter.pop(%w{hi there bert and ernie}, 2)
|
assert_equal %w(hi there bert), @filter.pop(%w(hi there bert and ernie), 2)
|
||||||
end
|
end
|
||||||
|
|
||||||
should "cast string inputs for # into nums" do
|
should "cast string inputs for # into nums" do
|
||||||
assert_equal %w{hi there bert}, @filter.pop(%w{hi there bert and ernie}, "2")
|
assert_equal %w(hi there bert), @filter.pop(%w(hi there bert and ernie), "2")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context "shift filter" do
|
context "shift filter" do
|
||||||
should "return a new array with the element removed from the front" do
|
should "return a new array with the element removed from the front" do
|
||||||
assert_equal %w{a friendly greeting}, @filter.shift(%w{just a friendly greeting})
|
assert_equal %w(a friendly greeting), @filter.shift(%w(just a friendly greeting))
|
||||||
end
|
end
|
||||||
|
|
||||||
should "allow multiple els to be shifted" do
|
should "allow multiple els to be shifted" do
|
||||||
assert_equal %w{bert and ernie}, @filter.shift(%w{hi there bert and ernie}, 2)
|
assert_equal %w(bert and ernie), @filter.shift(%w(hi there bert and ernie), 2)
|
||||||
end
|
end
|
||||||
|
|
||||||
should "cast string inputs for # into nums" do
|
should "cast string inputs for # into nums" do
|
||||||
assert_equal %w{bert and ernie}, @filter.shift(%w{hi there bert and ernie}, "2")
|
assert_equal %w(bert and ernie), @filter.shift(%w(hi there bert and ernie), "2")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context "unshift filter" do
|
context "unshift filter" do
|
||||||
should "return a new array with the element put at the front" do
|
should "return a new array with the element put at the front" do
|
||||||
assert_equal %w{aloha there bernie}, @filter.unshift(%w{there bernie}, "aloha")
|
assert_equal %w(aloha there bernie), @filter.unshift(%w(there bernie), "aloha")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -563,6 +670,5 @@ class TestFilters < JekyllUnitTest
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,22 +1,22 @@
|
||||||
# encoding: UTF-8
|
# encoding: UTF-8
|
||||||
|
|
||||||
require 'helper'
|
require "helper"
|
||||||
|
|
||||||
class TestKramdown < JekyllUnitTest
|
class TestKramdown < JekyllUnitTest
|
||||||
context "kramdown" do
|
context "kramdown" do
|
||||||
setup do
|
setup do
|
||||||
@config = {
|
@config = {
|
||||||
'markdown' => 'kramdown',
|
"markdown" => "kramdown",
|
||||||
'kramdown' => {
|
"kramdown" => {
|
||||||
'smart_quotes' => 'lsquo,rsquo,ldquo,rdquo',
|
"smart_quotes" => "lsquo,rsquo,ldquo,rdquo",
|
||||||
'entity_output' => 'as_char',
|
"entity_output" => "as_char",
|
||||||
'toc_levels' => '1..6',
|
"toc_levels" => "1..6",
|
||||||
'auto_ids' => false,
|
"auto_ids" => false,
|
||||||
'footnote_nr' => 1,
|
"footnote_nr" => 1,
|
||||||
|
|
||||||
'syntax_highlighter' => 'rouge',
|
"syntax_highlighter" => "rouge",
|
||||||
'syntax_highlighter_opts' => {
|
"syntax_highlighter_opts" => {
|
||||||
'bold_every' => 8, 'css' => :class
|
"bold_every" => 8, "css" => :class
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -33,25 +33,28 @@ class TestKramdown < JekyllUnitTest
|
||||||
|
|
||||||
context "when asked to convert smart quotes" do
|
context "when asked to convert smart quotes" do
|
||||||
should "convert" do
|
should "convert" do
|
||||||
assert_match %r!<p>(“|“)Pit(’|’)hy(”|”)<\/p>!, @markdown.convert(%{"Pit'hy"}).strip
|
assert_match(
|
||||||
|
%r!<p>(“|“)Pit(’|’)hy(”|”)<\/p>!,
|
||||||
|
@markdown.convert(%("Pit'hy")).strip
|
||||||
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
should "support custom types" do
|
should "support custom types" do
|
||||||
override = {
|
override = {
|
||||||
"highlighter" => nil,
|
"highlighter" => nil,
|
||||||
'kramdown' => {
|
"kramdown" => {
|
||||||
'smart_quotes' => 'lsaquo,rsaquo,laquo,raquo'
|
"smart_quotes" => "lsaquo,rsaquo,laquo,raquo"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
markdown = Converters::Markdown.new(Utils.deep_merge_hashes(@config, override))
|
markdown = Converters::Markdown.new(Utils.deep_merge_hashes(@config, override))
|
||||||
assert_match %r!<p>(«|«)Pit(›|›)hy(»|»)<\/p>!, \
|
assert_match %r!<p>(«|«)Pit(›|›)hy(»|»)<\/p>!, \
|
||||||
markdown.convert(%{"Pit'hy"}).strip
|
markdown.convert(%("Pit'hy")).strip
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
should "render fenced code blocks with syntax highlighting" do
|
should "render fenced code blocks with syntax highlighting" do
|
||||||
result = nokogiri_fragment(@markdown.convert(Utils.strip_heredoc <<-MARKDOWN))
|
result = nokogiri_fragment(@markdown.convert(Utils.strip_heredoc(<<-MARKDOWN)))
|
||||||
~~~ruby
|
~~~ruby
|
||||||
puts "Hello World"
|
puts "Hello World"
|
||||||
~~~
|
~~~
|
||||||
|
@ -72,7 +75,7 @@ class TestKramdown < JekyllUnitTest
|
||||||
}
|
}
|
||||||
|
|
||||||
markdown = Converters::Markdown.new(Utils.deep_merge_hashes(@config, override))
|
markdown = Converters::Markdown.new(Utils.deep_merge_hashes(@config, override))
|
||||||
result = nokogiri_fragment(markdown.convert(Utils.strip_heredoc <<-MARKDOWN))
|
result = nokogiri_fragment(markdown.convert(Utils.strip_heredoc(<<-MARKDOWN)))
|
||||||
~~~ruby
|
~~~ruby
|
||||||
puts "Hello World"
|
puts "Hello World"
|
||||||
~~~
|
~~~
|
||||||
|
@ -86,14 +89,14 @@ class TestKramdown < JekyllUnitTest
|
||||||
override = {
|
override = {
|
||||||
"markdown" => "kramdown",
|
"markdown" => "kramdown",
|
||||||
"kramdown" => {
|
"kramdown" => {
|
||||||
"enable_coderay" => true,
|
"enable_coderay" => true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@config.delete("highlighter")
|
@config.delete("highlighter")
|
||||||
@config["kramdown"].delete("syntax_highlighter")
|
@config["kramdown"].delete("syntax_highlighter")
|
||||||
markdown = Converters::Markdown.new(Utils.deep_merge_hashes(@config, override))
|
markdown = Converters::Markdown.new(Utils.deep_merge_hashes(@config, override))
|
||||||
result = nokogiri_fragment(markdown.convert(Utils.strip_heredoc <<-MARKDOWN))
|
result = nokogiri_fragment(markdown.convert(Utils.strip_heredoc(<<-MARKDOWN)))
|
||||||
~~~ruby
|
~~~ruby
|
||||||
puts "Hello World"
|
puts "Hello World"
|
||||||
~~~
|
~~~
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
require 'helper'
|
require "helper"
|
||||||
|
|
||||||
class TestLiquidRenderer < JekyllUnitTest
|
class TestLiquidRenderer < JekyllUnitTest
|
||||||
context "profiler" do
|
context "profiler" do
|
||||||
|
@ -12,11 +12,13 @@ class TestLiquidRenderer < JekyllUnitTest
|
||||||
|
|
||||||
output = @renderer.stats_table
|
output = @renderer.stats_table
|
||||||
|
|
||||||
|
# rubocop:disable Metrics/LineLength
|
||||||
expected = [
|
expected = [
|
||||||
/^Filename\s+|\s+Count\s+|\s+Bytes\s+|\s+Time$/,
|
/^Filename\s+|\s+Count\s+|\s+Bytes\s+|\s+Time$/,
|
||||||
/^-+\++-+\++-+\++-+$/,
|
/^-+\++-+\++-+\++-+$/,
|
||||||
/^_posts\/2010-01-09-date-override\.markdown\s+|\s+\d+\s+|\s+\d+\.\d{2}K\s+|\s+\d+\.\d{3}$/,
|
%r!^_posts/2010-01-09-date-override\.markdown\s+|\s+\d+\s+|\s+\d+\.\d{2}K\s+|\s+\d+\.\d{3}$!
|
||||||
]
|
]
|
||||||
|
# rubocop:enable Metrics/LineLength
|
||||||
|
|
||||||
expected.each do |regexp|
|
expected.each do |regexp|
|
||||||
assert_match regexp, output
|
assert_match regexp, output
|
||||||
|
|
|
@ -1,15 +1,18 @@
|
||||||
require 'helper'
|
require "helper"
|
||||||
|
|
||||||
class TestPage < JekyllUnitTest
|
class TestPage < JekyllUnitTest
|
||||||
def setup_page(*args)
|
def setup_page(*args)
|
||||||
dir, file = args
|
dir, file = args
|
||||||
dir, file = ['', dir] if file.nil?
|
if file.nil?
|
||||||
|
file = dir
|
||||||
|
dir = ""
|
||||||
|
end
|
||||||
@page = Page.new(@site, source_dir, dir, file)
|
@page = Page.new(@site, source_dir, dir, file)
|
||||||
end
|
end
|
||||||
|
|
||||||
def do_render(page)
|
def do_render(page)
|
||||||
layouts = {
|
layouts = {
|
||||||
"default" => Layout.new(@site, source_dir('_layouts'), "simple.html")
|
"default" => Layout.new(@site, source_dir("_layouts"), "simple.html")
|
||||||
}
|
}
|
||||||
page.render(layouts, @site.site_payload)
|
page.render(layouts, @site.site_payload)
|
||||||
end
|
end
|
||||||
|
@ -26,7 +29,7 @@ class TestPage < JekyllUnitTest
|
||||||
|
|
||||||
context "processing pages" do
|
context "processing pages" do
|
||||||
should "create url based on filename" do
|
should "create url based on filename" do
|
||||||
@page = setup_page('contacts.html')
|
@page = setup_page("contacts.html")
|
||||||
assert_equal "/contacts.html", @page.url
|
assert_equal "/contacts.html", @page.url
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -36,29 +39,29 @@ class TestPage < JekyllUnitTest
|
||||||
end
|
end
|
||||||
|
|
||||||
should "create url with non-alphabetic characters" do
|
should "create url with non-alphabetic characters" do
|
||||||
@page = setup_page('+', '%# +.md')
|
@page = setup_page("+", '%# +.md')
|
||||||
assert_equal "/+/%25%23%20+.html", @page.url
|
assert_equal "/+/%25%23%20+.html", @page.url
|
||||||
end
|
end
|
||||||
|
|
||||||
context "in a directory hierarchy" do
|
context "in a directory hierarchy" do
|
||||||
should "create url based on filename" do
|
should "create url based on filename" do
|
||||||
@page = setup_page('/contacts', 'bar.html')
|
@page = setup_page("/contacts", "bar.html")
|
||||||
assert_equal "/contacts/bar.html", @page.url
|
assert_equal "/contacts/bar.html", @page.url
|
||||||
end
|
end
|
||||||
|
|
||||||
should "create index url based on filename" do
|
should "create index url based on filename" do
|
||||||
@page = setup_page('/contacts', 'index.html')
|
@page = setup_page("/contacts", "index.html")
|
||||||
assert_equal "/contacts/", @page.url
|
assert_equal "/contacts/", @page.url
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
should "deal properly with extensions" do
|
should "deal properly with extensions" do
|
||||||
@page = setup_page('deal.with.dots.html')
|
@page = setup_page("deal.with.dots.html")
|
||||||
assert_equal ".html", @page.ext
|
assert_equal ".html", @page.ext
|
||||||
end
|
end
|
||||||
|
|
||||||
should "deal properly with non-html extensions" do
|
should "deal properly with non-html extensions" do
|
||||||
@page = setup_page('dynamic_page.php')
|
@page = setup_page("dynamic_page.php")
|
||||||
@dest_file = dest_dir("dynamic_page.php")
|
@dest_file = dest_dir("dynamic_page.php")
|
||||||
assert_equal ".php", @page.ext
|
assert_equal ".php", @page.ext
|
||||||
assert_equal "dynamic_page", @page.basename
|
assert_equal "dynamic_page", @page.basename
|
||||||
|
@ -67,7 +70,7 @@ class TestPage < JekyllUnitTest
|
||||||
end
|
end
|
||||||
|
|
||||||
should "deal properly with dots" do
|
should "deal properly with dots" do
|
||||||
@page = setup_page('deal.with.dots.html')
|
@page = setup_page("deal.with.dots.html")
|
||||||
@dest_file = dest_dir("deal.with.dots.html")
|
@dest_file = dest_dir("deal.with.dots.html")
|
||||||
|
|
||||||
assert_equal "deal.with.dots", @page.basename
|
assert_equal "deal.with.dots", @page.basename
|
||||||
|
@ -75,19 +78,19 @@ class TestPage < JekyllUnitTest
|
||||||
end
|
end
|
||||||
|
|
||||||
should "make properties accessible through #[]" do
|
should "make properties accessible through #[]" do
|
||||||
page = setup_page('properties.html')
|
page = setup_page("properties.html")
|
||||||
attrs = {
|
attrs = {
|
||||||
content: "All the properties.\n",
|
:content => "All the properties.\n",
|
||||||
dir: "/properties/",
|
:dir => "/properties/",
|
||||||
excerpt: nil,
|
:excerpt => nil,
|
||||||
foo: 'bar',
|
:foo => "bar",
|
||||||
layout: 'default',
|
:layout => "default",
|
||||||
name: "properties.html",
|
:name => "properties.html",
|
||||||
path: "properties.html",
|
:path => "properties.html",
|
||||||
permalink: '/properties/',
|
:permalink => "/properties/",
|
||||||
published: nil,
|
:published => nil,
|
||||||
title: 'Properties Page',
|
:title => "Properties Page",
|
||||||
url: "/properties/"
|
:url => "/properties/"
|
||||||
}
|
}
|
||||||
|
|
||||||
attrs.each do |attr, val|
|
attrs.each do |attr, val|
|
||||||
|
@ -103,38 +106,38 @@ class TestPage < JekyllUnitTest
|
||||||
end
|
end
|
||||||
|
|
||||||
should "return dir, url, and destination correctly" do
|
should "return dir, url, and destination correctly" do
|
||||||
@page = setup_page('contacts.html')
|
@page = setup_page("contacts.html")
|
||||||
@dest_file = dest_dir("contacts/index.html")
|
@dest_file = dest_dir("contacts/index.html")
|
||||||
|
|
||||||
assert_equal '/contacts/', @page.dir
|
assert_equal "/contacts/", @page.dir
|
||||||
assert_equal '/contacts/', @page.url
|
assert_equal "/contacts/", @page.url
|
||||||
assert_equal @dest_file, @page.destination(dest_dir)
|
assert_equal @dest_file, @page.destination(dest_dir)
|
||||||
end
|
end
|
||||||
|
|
||||||
should "return dir correctly for index page" do
|
should "return dir correctly for index page" do
|
||||||
@page = setup_page('index.html')
|
@page = setup_page("index.html")
|
||||||
assert_equal '/', @page.dir
|
assert_equal "/", @page.dir
|
||||||
end
|
end
|
||||||
|
|
||||||
context "in a directory hierarchy" do
|
context "in a directory hierarchy" do
|
||||||
should "create url based on filename" do
|
should "create url based on filename" do
|
||||||
@page = setup_page('/contacts', 'bar.html')
|
@page = setup_page("/contacts", "bar.html")
|
||||||
assert_equal "/contacts/bar/", @page.url
|
assert_equal "/contacts/bar/", @page.url
|
||||||
end
|
end
|
||||||
|
|
||||||
should "create index url based on filename" do
|
should "create index url based on filename" do
|
||||||
@page = setup_page('/contacts', 'index.html')
|
@page = setup_page("/contacts", "index.html")
|
||||||
assert_equal "/contacts/", @page.url
|
assert_equal "/contacts/", @page.url
|
||||||
end
|
end
|
||||||
|
|
||||||
should "return dir correctly" do
|
should "return dir correctly" do
|
||||||
@page = setup_page('/contacts', 'bar.html')
|
@page = setup_page("/contacts", "bar.html")
|
||||||
assert_equal '/contacts/bar/', @page.dir
|
assert_equal "/contacts/bar/", @page.dir
|
||||||
end
|
end
|
||||||
|
|
||||||
should "return dir correctly for index page" do
|
should "return dir correctly for index page" do
|
||||||
@page = setup_page('/contacts', 'index.html')
|
@page = setup_page("/contacts", "index.html")
|
||||||
assert_equal '/contacts/', @page.dir
|
assert_equal "/contacts/", @page.dir
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -145,16 +148,16 @@ class TestPage < JekyllUnitTest
|
||||||
end
|
end
|
||||||
|
|
||||||
should "return url and destination correctly" do
|
should "return url and destination correctly" do
|
||||||
@page = setup_page('contacts.html')
|
@page = setup_page("contacts.html")
|
||||||
@dest_file = dest_dir("contacts.html")
|
@dest_file = dest_dir("contacts.html")
|
||||||
assert_equal '/contacts.html', @page.url
|
assert_equal "/contacts.html", @page.url
|
||||||
assert_equal @dest_file, @page.destination(dest_dir)
|
assert_equal @dest_file, @page.destination(dest_dir)
|
||||||
end
|
end
|
||||||
|
|
||||||
should "return dir correctly" do
|
should "return dir correctly" do
|
||||||
assert_equal '/', setup_page('contacts.html').dir
|
assert_equal "/", setup_page("contacts.html").dir
|
||||||
assert_equal '/contacts/', setup_page('contacts/bar.html').dir
|
assert_equal "/contacts/", setup_page("contacts/bar.html").dir
|
||||||
assert_equal '/contacts/', setup_page('contacts/index.html').dir
|
assert_equal "/contacts/", setup_page("contacts/index.html").dir
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -164,9 +167,9 @@ class TestPage < JekyllUnitTest
|
||||||
end
|
end
|
||||||
|
|
||||||
should "return url and destination correctly" do
|
should "return url and destination correctly" do
|
||||||
@page = setup_page('contacts.html')
|
@page = setup_page("contacts.html")
|
||||||
@dest_file = dest_dir("contacts/index.html")
|
@dest_file = dest_dir("contacts/index.html")
|
||||||
assert_equal '/contacts/', @page.url
|
assert_equal "/contacts/", @page.url
|
||||||
assert_equal @dest_file, @page.destination(dest_dir)
|
assert_equal @dest_file, @page.destination(dest_dir)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -177,9 +180,9 @@ class TestPage < JekyllUnitTest
|
||||||
end
|
end
|
||||||
|
|
||||||
should "return url and destination correctly" do
|
should "return url and destination correctly" do
|
||||||
@page = setup_page('contacts.html')
|
@page = setup_page("contacts.html")
|
||||||
@dest_file = dest_dir("contacts.html")
|
@dest_file = dest_dir("contacts.html")
|
||||||
assert_equal '/contacts.html', @page.url
|
assert_equal "/contacts.html", @page.url
|
||||||
assert_equal @dest_file, @page.destination(dest_dir)
|
assert_equal @dest_file, @page.destination(dest_dir)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -190,9 +193,9 @@ class TestPage < JekyllUnitTest
|
||||||
end
|
end
|
||||||
|
|
||||||
should "return url and destination correctly" do
|
should "return url and destination correctly" do
|
||||||
@page = setup_page('contacts.html')
|
@page = setup_page("contacts.html")
|
||||||
@dest_file = dest_dir("contacts.html")
|
@dest_file = dest_dir("contacts.html")
|
||||||
assert_equal '/contacts', @page.url
|
assert_equal "/contacts", @page.url
|
||||||
assert_equal @dest_file, @page.destination(dest_dir)
|
assert_equal @dest_file, @page.destination(dest_dir)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -200,9 +203,9 @@ class TestPage < JekyllUnitTest
|
||||||
context "with any other permalink style" do
|
context "with any other permalink style" do
|
||||||
should "return dir correctly" do
|
should "return dir correctly" do
|
||||||
@site.permalink_style = nil
|
@site.permalink_style = nil
|
||||||
assert_equal '/', setup_page('contacts.html').dir
|
assert_equal "/", setup_page("contacts.html").dir
|
||||||
assert_equal '/contacts/', setup_page('contacts/index.html').dir
|
assert_equal "/contacts/", setup_page("contacts/index.html").dir
|
||||||
assert_equal '/contacts/', setup_page('contacts/bar.html').dir
|
assert_equal "/contacts/", setup_page("contacts/bar.html").dir
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -216,7 +219,7 @@ class TestPage < JekyllUnitTest
|
||||||
end
|
end
|
||||||
|
|
||||||
should "return nil permalink if no permalink exists" do
|
should "return nil permalink if no permalink exists" do
|
||||||
@page = setup_page('')
|
@page = setup_page("")
|
||||||
assert_equal nil, @page.permalink
|
assert_equal nil, @page.permalink
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -233,7 +236,7 @@ class TestPage < JekyllUnitTest
|
||||||
|
|
||||||
context "with specified layout of nil" do
|
context "with specified layout of nil" do
|
||||||
setup do
|
setup do
|
||||||
@page = setup_page('sitemap.xml')
|
@page = setup_page("sitemap.xml")
|
||||||
end
|
end
|
||||||
|
|
||||||
should "layout of nil is respected" do
|
should "layout of nil is respected" do
|
||||||
|
@ -247,60 +250,60 @@ class TestPage < JekyllUnitTest
|
||||||
end
|
end
|
||||||
|
|
||||||
should "write properly" do
|
should "write properly" do
|
||||||
page = setup_page('contacts.html')
|
page = setup_page("contacts.html")
|
||||||
do_render(page)
|
do_render(page)
|
||||||
page.write(dest_dir)
|
page.write(dest_dir)
|
||||||
|
|
||||||
assert File.directory?(dest_dir)
|
assert File.directory?(dest_dir)
|
||||||
assert_exist dest_dir('contacts.html')
|
assert_exist dest_dir("contacts.html")
|
||||||
end
|
end
|
||||||
|
|
||||||
should "write even when the folder name is plus and permalink has +" do
|
should "write even when the folder name is plus and permalink has +" do
|
||||||
page = setup_page('+', 'foo.md')
|
page = setup_page("+", "foo.md")
|
||||||
do_render(page)
|
do_render(page)
|
||||||
page.write(dest_dir)
|
page.write(dest_dir)
|
||||||
|
|
||||||
assert File.directory?(dest_dir), "#{dest_dir} should be a directory"
|
assert File.directory?(dest_dir), "#{dest_dir} should be a directory"
|
||||||
assert_exist dest_dir('+', 'plus+in+url.html')
|
assert_exist dest_dir("+", "plus+in+url.html")
|
||||||
end
|
end
|
||||||
|
|
||||||
should "write even when permalink has '%# +'" do
|
should "write even when permalink has '%# +'" do
|
||||||
page = setup_page('+', '%# +.md')
|
page = setup_page("+", '%# +.md')
|
||||||
do_render(page)
|
do_render(page)
|
||||||
page.write(dest_dir)
|
page.write(dest_dir)
|
||||||
|
|
||||||
assert File.directory?(dest_dir)
|
assert File.directory?(dest_dir)
|
||||||
assert_exist dest_dir('+', '%# +.html')
|
assert_exist dest_dir("+", '%# +.html')
|
||||||
end
|
end
|
||||||
|
|
||||||
should "write properly without html extension" do
|
should "write properly without html extension" do
|
||||||
page = setup_page('contacts.html')
|
page = setup_page("contacts.html")
|
||||||
page.site.permalink_style = :pretty
|
page.site.permalink_style = :pretty
|
||||||
do_render(page)
|
do_render(page)
|
||||||
page.write(dest_dir)
|
page.write(dest_dir)
|
||||||
|
|
||||||
assert File.directory?(dest_dir)
|
assert File.directory?(dest_dir)
|
||||||
assert_exist dest_dir('contacts', 'index.html')
|
assert_exist dest_dir("contacts", "index.html")
|
||||||
end
|
end
|
||||||
|
|
||||||
should "support .htm extension and respects that" do
|
should "support .htm extension and respects that" do
|
||||||
page = setup_page('contacts.htm')
|
page = setup_page("contacts.htm")
|
||||||
page.site.permalink_style = :pretty
|
page.site.permalink_style = :pretty
|
||||||
do_render(page)
|
do_render(page)
|
||||||
page.write(dest_dir)
|
page.write(dest_dir)
|
||||||
|
|
||||||
assert File.directory?(dest_dir)
|
assert File.directory?(dest_dir)
|
||||||
assert_exist dest_dir('contacts', 'index.htm')
|
assert_exist dest_dir("contacts", "index.htm")
|
||||||
end
|
end
|
||||||
|
|
||||||
should "support .xhtml extension and respects that" do
|
should "support .xhtml extension and respects that" do
|
||||||
page = setup_page('contacts.xhtml')
|
page = setup_page("contacts.xhtml")
|
||||||
page.site.permalink_style = :pretty
|
page.site.permalink_style = :pretty
|
||||||
do_render(page)
|
do_render(page)
|
||||||
page.write(dest_dir)
|
page.write(dest_dir)
|
||||||
|
|
||||||
assert File.directory?(dest_dir)
|
assert File.directory?(dest_dir)
|
||||||
assert_exist dest_dir('contacts', 'index.xhtml')
|
assert_exist dest_dir("contacts", "index.xhtml")
|
||||||
end
|
end
|
||||||
|
|
||||||
should "write properly with extension different from html" do
|
should "write properly with extension different from html" do
|
||||||
|
@ -312,48 +315,47 @@ class TestPage < JekyllUnitTest
|
||||||
assert_equal "/sitemap.xml", page.url
|
assert_equal "/sitemap.xml", page.url
|
||||||
assert_nil page.url[/\.html$/]
|
assert_nil page.url[/\.html$/]
|
||||||
assert File.directory?(dest_dir)
|
assert File.directory?(dest_dir)
|
||||||
assert_exist dest_dir('sitemap.xml')
|
assert_exist dest_dir("sitemap.xml")
|
||||||
end
|
end
|
||||||
|
|
||||||
should "write dotfiles properly" do
|
should "write dotfiles properly" do
|
||||||
page = setup_page('.htaccess')
|
page = setup_page(".htaccess")
|
||||||
do_render(page)
|
do_render(page)
|
||||||
page.write(dest_dir)
|
page.write(dest_dir)
|
||||||
|
|
||||||
assert File.directory?(dest_dir)
|
assert File.directory?(dest_dir)
|
||||||
assert_exist dest_dir('.htaccess')
|
assert_exist dest_dir(".htaccess")
|
||||||
end
|
end
|
||||||
|
|
||||||
context "in a directory hierarchy" do
|
context "in a directory hierarchy" do
|
||||||
should "write properly the index" do
|
should "write properly the index" do
|
||||||
page = setup_page('/contacts', 'index.html')
|
page = setup_page("/contacts", "index.html")
|
||||||
do_render(page)
|
do_render(page)
|
||||||
page.write(dest_dir)
|
page.write(dest_dir)
|
||||||
|
|
||||||
assert File.directory?(dest_dir)
|
assert File.directory?(dest_dir)
|
||||||
assert_exist dest_dir('contacts', 'index.html')
|
assert_exist dest_dir("contacts", "index.html")
|
||||||
end
|
end
|
||||||
|
|
||||||
should "write properly" do
|
should "write properly" do
|
||||||
page = setup_page('/contacts', 'bar.html')
|
page = setup_page("/contacts", "bar.html")
|
||||||
do_render(page)
|
do_render(page)
|
||||||
page.write(dest_dir)
|
page.write(dest_dir)
|
||||||
|
|
||||||
assert File.directory?(dest_dir)
|
assert File.directory?(dest_dir)
|
||||||
assert_exist dest_dir('contacts', 'bar.html')
|
assert_exist dest_dir("contacts", "bar.html")
|
||||||
end
|
end
|
||||||
|
|
||||||
should "write properly without html extension" do
|
should "write properly without html extension" do
|
||||||
page = setup_page('/contacts', 'bar.html')
|
page = setup_page("/contacts", "bar.html")
|
||||||
page.site.permalink_style = :pretty
|
page.site.permalink_style = :pretty
|
||||||
do_render(page)
|
do_render(page)
|
||||||
page.write(dest_dir)
|
page.write(dest_dir)
|
||||||
|
|
||||||
assert File.directory?(dest_dir)
|
assert File.directory?(dest_dir)
|
||||||
assert_exist dest_dir('contacts', 'bar', 'index.html')
|
assert_exist dest_dir("contacts", "bar", "index.html")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
require 'helper'
|
require "helper"
|
||||||
|
|
||||||
class TestRegenerator < JekyllUnitTest
|
class TestRegenerator < JekyllUnitTest
|
||||||
context "The site regenerator" do
|
context "The site regenerator" do
|
||||||
|
@ -39,12 +39,11 @@ class TestRegenerator < JekyllUnitTest
|
||||||
# we need to create the destinations for these files,
|
# we need to create the destinations for these files,
|
||||||
# because regenerate? checks if the destination exists
|
# because regenerate? checks if the destination exists
|
||||||
[@page, @post, @document, @asset_file].each do |item|
|
[@page, @post, @document, @asset_file].each do |item|
|
||||||
if item.respond_to?(:destination)
|
next unless item.respond_to?(:destination)
|
||||||
dest = item.destination(@site.dest)
|
dest = item.destination(@site.dest)
|
||||||
FileUtils.mkdir_p(File.dirname(dest))
|
FileUtils.mkdir_p(File.dirname(dest))
|
||||||
FileUtils.touch(dest)
|
FileUtils.touch(dest)
|
||||||
end
|
end
|
||||||
end
|
|
||||||
@regenerator.write_metadata
|
@regenerator.write_metadata
|
||||||
@regenerator = Regenerator.new(@site)
|
@regenerator = Regenerator.new(@site)
|
||||||
|
|
||||||
|
@ -69,7 +68,7 @@ class TestRegenerator < JekyllUnitTest
|
||||||
[@page, @post, @document, @asset_file].each do |item|
|
[@page, @post, @document, @asset_file].each do |item|
|
||||||
if item.respond_to?(:destination)
|
if item.respond_to?(:destination)
|
||||||
dest = item.destination(@site.dest)
|
dest = item.destination(@site.dest)
|
||||||
File.unlink(dest) unless !File.exist?(dest)
|
File.unlink(dest) if File.exist?(dest)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -171,7 +170,7 @@ class TestRegenerator < JekyllUnitTest
|
||||||
metadata_file = source_dir(".jekyll-metadata")
|
metadata_file = source_dir(".jekyll-metadata")
|
||||||
@regenerator = Regenerator.new(@site)
|
@regenerator = Regenerator.new(@site)
|
||||||
|
|
||||||
File.open(metadata_file, 'w') do |f|
|
File.open(metadata_file, "w") do |f|
|
||||||
f.write(@regenerator.metadata.to_yaml)
|
f.write(@regenerator.metadata.to_yaml)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -182,7 +181,7 @@ class TestRegenerator < JekyllUnitTest
|
||||||
should "not crash when reading corrupted marshal file" do
|
should "not crash when reading corrupted marshal file" do
|
||||||
metadata_file = source_dir(".jekyll-metadata")
|
metadata_file = source_dir(".jekyll-metadata")
|
||||||
File.open(metadata_file, "w") do |file|
|
File.open(metadata_file, "w") do |file|
|
||||||
file.puts Marshal.dump({ foo: 'bar' })[0,5]
|
file.puts Marshal.dump({ :foo => "bar" })[0, 5]
|
||||||
end
|
end
|
||||||
|
|
||||||
@regenerator = Regenerator.new(@site)
|
@regenerator = Regenerator.new(@site)
|
||||||
|
@ -282,7 +281,7 @@ class TestRegenerator < JekyllUnitTest
|
||||||
end
|
end
|
||||||
|
|
||||||
should "not regenerate again if multiple dependencies" do
|
should "not regenerate again if multiple dependencies" do
|
||||||
multi_deps = @regenerator.metadata.select {|k,v| v['deps'].length > 2}
|
multi_deps = @regenerator.metadata.select { |_k, v| v["deps"].length > 2 }
|
||||||
multi_dep_path = multi_deps.keys.first
|
multi_dep_path = multi_deps.keys.first
|
||||||
|
|
||||||
assert @regenerator.metadata[multi_dep_path]["deps"].length > 2
|
assert @regenerator.metadata[multi_dep_path]["deps"].length > 2
|
||||||
|
|
|
@ -1,45 +1,47 @@
|
||||||
require 'helper'
|
require "helper"
|
||||||
|
|
||||||
class TestSite < JekyllUnitTest
|
class TestSite < JekyllUnitTest
|
||||||
context "configuring sites" do
|
context "configuring sites" do
|
||||||
should "have an array for plugins by default" do
|
should "have an array for plugins by default" do
|
||||||
site = Site.new default_configuration
|
site = Site.new default_configuration
|
||||||
assert_equal [File.join(Dir.pwd, '_plugins')], site.plugins
|
assert_equal [File.join(Dir.pwd, "_plugins")], site.plugins
|
||||||
end
|
end
|
||||||
|
|
||||||
should "look for plugins under the site directory by default" do
|
should "look for plugins under the site directory by default" do
|
||||||
site = Site.new(site_configuration)
|
site = Site.new(site_configuration)
|
||||||
assert_equal [source_dir('_plugins')], site.plugins
|
assert_equal [source_dir("_plugins")], site.plugins
|
||||||
end
|
end
|
||||||
|
|
||||||
should "have an array for plugins if passed as a string" do
|
should "have an array for plugins if passed as a string" do
|
||||||
site = Site.new(site_configuration({ 'plugins_dir' => '/tmp/plugins' }))
|
site = Site.new(site_configuration({ "plugins_dir" => "/tmp/plugins" }))
|
||||||
assert_equal ['/tmp/plugins'], site.plugins
|
assert_equal ["/tmp/plugins"], site.plugins
|
||||||
end
|
end
|
||||||
|
|
||||||
should "have an array for plugins if passed as an array" do
|
should "have an array for plugins if passed as an array" do
|
||||||
site = Site.new(site_configuration({ 'plugins_dir' => ['/tmp/plugins', '/tmp/otherplugins'] }))
|
site = Site.new(site_configuration({
|
||||||
assert_equal ['/tmp/plugins', '/tmp/otherplugins'], site.plugins
|
"plugins_dir" => ["/tmp/plugins", "/tmp/otherplugins"]
|
||||||
|
}))
|
||||||
|
assert_equal ["/tmp/plugins", "/tmp/otherplugins"], site.plugins
|
||||||
end
|
end
|
||||||
|
|
||||||
should "have an empty array for plugins if nothing is passed" do
|
should "have an empty array for plugins if nothing is passed" do
|
||||||
site = Site.new(site_configuration({ 'plugins_dir' => [] }))
|
site = Site.new(site_configuration({ "plugins_dir" => [] }))
|
||||||
assert_equal [], site.plugins
|
assert_equal [], site.plugins
|
||||||
end
|
end
|
||||||
|
|
||||||
should "have the default for plugins if nil is passed" do
|
should "have the default for plugins if nil is passed" do
|
||||||
site = Site.new(site_configuration({ 'plugins_dir' => nil }))
|
site = Site.new(site_configuration({ "plugins_dir" => nil }))
|
||||||
assert_equal [source_dir('_plugins')], site.plugins
|
assert_equal [source_dir("_plugins")], site.plugins
|
||||||
end
|
end
|
||||||
|
|
||||||
should "expose default baseurl" do
|
should "expose default baseurl" do
|
||||||
site = Site.new(default_configuration)
|
site = Site.new(default_configuration)
|
||||||
assert_equal Jekyll::Configuration::DEFAULTS['baseurl'], site.baseurl
|
assert_equal Jekyll::Configuration::DEFAULTS["baseurl"], site.baseurl
|
||||||
end
|
end
|
||||||
|
|
||||||
should "expose baseurl passed in from config" do
|
should "expose baseurl passed in from config" do
|
||||||
site = Site.new(site_configuration({ 'baseurl' => '/blog' }))
|
site = Site.new(site_configuration({ "baseurl" => "/blog" }))
|
||||||
assert_equal '/blog', site.baseurl
|
assert_equal "/blog", site.baseurl
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
context "creating sites" do
|
context "creating sites" do
|
||||||
|
@ -55,7 +57,7 @@ class TestSite < JekyllUnitTest
|
||||||
end
|
end
|
||||||
|
|
||||||
should "have an empty tag hash by default" do
|
should "have an empty tag hash by default" do
|
||||||
assert_equal Hash.new, @site.tags
|
assert_equal({}, @site.tags)
|
||||||
end
|
end
|
||||||
|
|
||||||
should "give site with parsed pages and posts to generators" do
|
should "give site with parsed pages and posts to generators" do
|
||||||
|
@ -65,14 +67,14 @@ class TestSite < JekyllUnitTest
|
||||||
raise "#{page} isn't a page" unless page.is_a?(Page)
|
raise "#{page} isn't a page" unless page.is_a?(Page)
|
||||||
raise "#{page} doesn't respond to :name" unless page.respond_to?(:name)
|
raise "#{page} doesn't respond to :name" unless page.respond_to?(:name)
|
||||||
end
|
end
|
||||||
site.file_read_opts[:secret_message] = 'hi'
|
site.file_read_opts[:secret_message] = "hi"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@site = Site.new(site_configuration)
|
@site = Site.new(site_configuration)
|
||||||
@site.read
|
@site.read
|
||||||
@site.generate
|
@site.generate
|
||||||
refute_equal 0, @site.pages.size
|
refute_equal 0, @site.pages.size
|
||||||
assert_equal 'hi', @site.file_read_opts[:secret_message]
|
assert_equal "hi", @site.file_read_opts[:secret_message]
|
||||||
end
|
end
|
||||||
|
|
||||||
should "reset data before processing" do
|
should "reset data before processing" do
|
||||||
|
@ -157,13 +159,21 @@ class TestSite < JekyllUnitTest
|
||||||
end
|
end
|
||||||
|
|
||||||
should "setup plugins in priority order" do
|
should "setup plugins in priority order" do
|
||||||
assert_equal @site.converters.sort_by(&:class).map{|c|c.class.priority}, @site.converters.map{|c|c.class.priority}
|
assert_equal(
|
||||||
assert_equal @site.generators.sort_by(&:class).map{|g|g.class.priority}, @site.generators.map{|g|g.class.priority}
|
@site.converters.sort_by(&:class).map { |c| c.class.priority },
|
||||||
|
@site.converters.map { |c| c.class.priority }
|
||||||
|
)
|
||||||
|
assert_equal(
|
||||||
|
@site.generators.sort_by(&:class).map { |g| g.class.priority },
|
||||||
|
@site.generators.map { |g| g.class.priority }
|
||||||
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
should "sort pages alphabetically" do
|
should "sort pages alphabetically" do
|
||||||
method = Dir.method(:entries)
|
method = Dir.method(:entries)
|
||||||
allow(Dir).to receive(:entries) { |*args, &block| method.call(*args, &block).reverse }
|
allow(Dir).to receive(:entries) do |*args, &block|
|
||||||
|
method.call(*args, &block).reverse
|
||||||
|
end
|
||||||
@site.process
|
@site.process
|
||||||
# files in symlinked directories may appear twice
|
# files in symlinked directories may appear twice
|
||||||
sorted_pages = %w(
|
sorted_pages = %w(
|
||||||
|
@ -192,9 +202,11 @@ class TestSite < JekyllUnitTest
|
||||||
end
|
end
|
||||||
|
|
||||||
should "read posts" do
|
should "read posts" do
|
||||||
@site.posts.docs.concat(PostReader.new(@site).read_posts(''))
|
@site.posts.docs.concat(PostReader.new(@site).read_posts(""))
|
||||||
posts = Dir[source_dir('_posts', '**', '*')]
|
posts = Dir[source_dir("_posts", "**", "*")]
|
||||||
posts.delete_if { |post| File.directory?(post) && !(post =~ Document::DATE_FILENAME_MATCHER) }
|
posts.delete_if do |post|
|
||||||
|
File.directory?(post) && !(post =~ Document::DATE_FILENAME_MATCHER)
|
||||||
|
end
|
||||||
assert_equal posts.size - @num_invalid_posts, @site.posts.size
|
assert_equal posts.size - @num_invalid_posts, @site.posts.size
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -209,11 +221,11 @@ class TestSite < JekyllUnitTest
|
||||||
end
|
end
|
||||||
|
|
||||||
should "expose jekyll version to site payload" do
|
should "expose jekyll version to site payload" do
|
||||||
assert_equal Jekyll::VERSION, @site.site_payload['jekyll']['version']
|
assert_equal Jekyll::VERSION, @site.site_payload["jekyll"]["version"]
|
||||||
end
|
end
|
||||||
|
|
||||||
should "expose list of static files to site payload" do
|
should "expose list of static files to site payload" do
|
||||||
assert_equal @site.static_files, @site.site_payload['site']['static_files']
|
assert_equal @site.static_files, @site.site_payload["site"]["static_files"]
|
||||||
end
|
end
|
||||||
|
|
||||||
should "deploy payload" do
|
should "deploy payload" do
|
||||||
|
@ -221,118 +233,125 @@ class TestSite < JekyllUnitTest
|
||||||
@site.process
|
@site.process
|
||||||
|
|
||||||
posts = Dir[source_dir("**", "_posts", "**", "*")]
|
posts = Dir[source_dir("**", "_posts", "**", "*")]
|
||||||
posts.delete_if { |post| File.directory?(post) && !(post =~ Document::DATE_FILENAME_MATCHER) }
|
posts.delete_if do |post|
|
||||||
categories = %w(2013 bar baz category foo z_category MixedCase Mixedcase publish_test win).sort
|
File.directory?(post) && !(post =~ Document::DATE_FILENAME_MATCHER)
|
||||||
|
end
|
||||||
|
categories = %w(
|
||||||
|
2013 bar baz category foo z_category MixedCase Mixedcase publish_test win
|
||||||
|
).sort
|
||||||
|
|
||||||
assert_equal posts.size - @num_invalid_posts, @site.posts.size
|
assert_equal posts.size - @num_invalid_posts, @site.posts.size
|
||||||
assert_equal categories, @site.categories.keys.sort
|
assert_equal categories, @site.categories.keys.sort
|
||||||
assert_equal 5, @site.categories['foo'].size
|
assert_equal 5, @site.categories["foo"].size
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'error handling' do
|
context "error handling" do
|
||||||
should "raise if destination is included in source" do
|
should "raise if destination is included in source" do
|
||||||
assert_raises Jekyll::Errors::FatalException do
|
assert_raises Jekyll::Errors::FatalException do
|
||||||
Site.new(site_configuration('destination' => source_dir))
|
Site.new(site_configuration("destination" => source_dir))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
should "raise if destination is source" do
|
should "raise if destination is source" do
|
||||||
assert_raises Jekyll::Errors::FatalException do
|
assert_raises Jekyll::Errors::FatalException do
|
||||||
Site.new(site_configuration('destination' => File.join(source_dir, "..")))
|
Site.new(site_configuration("destination" => File.join(source_dir, "..")))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'with orphaned files in destination' do
|
context "with orphaned files in destination" do
|
||||||
setup do
|
setup do
|
||||||
clear_dest
|
clear_dest
|
||||||
@site.regenerator.clear
|
@site.regenerator.clear
|
||||||
@site.process
|
@site.process
|
||||||
# generate some orphaned files:
|
# generate some orphaned files:
|
||||||
# single file
|
# single file
|
||||||
File.open(dest_dir('obsolete.html'), 'w')
|
File.open(dest_dir("obsolete.html"), "w")
|
||||||
# single file in sub directory
|
# single file in sub directory
|
||||||
FileUtils.mkdir(dest_dir('qux'))
|
FileUtils.mkdir(dest_dir("qux"))
|
||||||
File.open(dest_dir('qux/obsolete.html'), 'w')
|
File.open(dest_dir("qux/obsolete.html"), "w")
|
||||||
# empty directory
|
# empty directory
|
||||||
FileUtils.mkdir(dest_dir('quux'))
|
FileUtils.mkdir(dest_dir("quux"))
|
||||||
FileUtils.mkdir(dest_dir('.git'))
|
FileUtils.mkdir(dest_dir(".git"))
|
||||||
FileUtils.mkdir(dest_dir('.svn'))
|
FileUtils.mkdir(dest_dir(".svn"))
|
||||||
FileUtils.mkdir(dest_dir('.hg'))
|
FileUtils.mkdir(dest_dir(".hg"))
|
||||||
# single file in repository
|
# single file in repository
|
||||||
File.open(dest_dir('.git/HEAD'), 'w')
|
File.open(dest_dir(".git/HEAD"), "w")
|
||||||
File.open(dest_dir('.svn/HEAD'), 'w')
|
File.open(dest_dir(".svn/HEAD"), "w")
|
||||||
File.open(dest_dir('.hg/HEAD'), 'w')
|
File.open(dest_dir(".hg/HEAD"), "w")
|
||||||
end
|
end
|
||||||
|
|
||||||
teardown do
|
teardown do
|
||||||
FileUtils.rm_f(dest_dir('obsolete.html'))
|
FileUtils.rm_f(dest_dir("obsolete.html"))
|
||||||
FileUtils.rm_rf(dest_dir('qux'))
|
FileUtils.rm_rf(dest_dir("qux"))
|
||||||
FileUtils.rm_f(dest_dir('quux'))
|
FileUtils.rm_f(dest_dir("quux"))
|
||||||
FileUtils.rm_rf(dest_dir('.git'))
|
FileUtils.rm_rf(dest_dir(".git"))
|
||||||
FileUtils.rm_rf(dest_dir('.svn'))
|
FileUtils.rm_rf(dest_dir(".svn"))
|
||||||
FileUtils.rm_rf(dest_dir('.hg'))
|
FileUtils.rm_rf(dest_dir(".hg"))
|
||||||
end
|
end
|
||||||
|
|
||||||
should 'remove orphaned files in destination' do
|
should "remove orphaned files in destination" do
|
||||||
@site.process
|
@site.process
|
||||||
refute_exist dest_dir('obsolete.html')
|
refute_exist dest_dir("obsolete.html")
|
||||||
refute_exist dest_dir('qux')
|
refute_exist dest_dir("qux")
|
||||||
refute_exist dest_dir('quux')
|
refute_exist dest_dir("quux")
|
||||||
assert_exist dest_dir('.git')
|
assert_exist dest_dir(".git")
|
||||||
assert_exist dest_dir('.git', 'HEAD')
|
assert_exist dest_dir(".git", "HEAD")
|
||||||
end
|
end
|
||||||
|
|
||||||
should 'remove orphaned files in destination - keep_files .svn' do
|
should "remove orphaned files in destination - keep_files .svn" do
|
||||||
config = site_configuration('keep_files' => %w{.svn})
|
config = site_configuration("keep_files" => %w(.svn))
|
||||||
@site = Site.new(config)
|
@site = Site.new(config)
|
||||||
@site.process
|
@site.process
|
||||||
refute_exist dest_dir('.htpasswd')
|
refute_exist dest_dir(".htpasswd")
|
||||||
refute_exist dest_dir('obsolete.html')
|
refute_exist dest_dir("obsolete.html")
|
||||||
refute_exist dest_dir('qux')
|
refute_exist dest_dir("qux")
|
||||||
refute_exist dest_dir('quux')
|
refute_exist dest_dir("quux")
|
||||||
refute_exist dest_dir('.git')
|
refute_exist dest_dir(".git")
|
||||||
refute_exist dest_dir('.git', 'HEAD')
|
refute_exist dest_dir(".git", "HEAD")
|
||||||
assert_exist dest_dir('.svn')
|
assert_exist dest_dir(".svn")
|
||||||
assert_exist dest_dir('.svn', 'HEAD')
|
assert_exist dest_dir(".svn", "HEAD")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'using a non-default markdown processor in the configuration' do
|
context "using a non-default markdown processor in the configuration" do
|
||||||
should 'use the non-default markdown processor' do
|
should "use the non-default markdown processor" do
|
||||||
class Jekyll::Converters::Markdown::CustomMarkdown
|
class Jekyll::Converters::Markdown::CustomMarkdown
|
||||||
def initialize(*args)
|
def initialize(*args)
|
||||||
@args = args
|
@args = args
|
||||||
end
|
end
|
||||||
|
|
||||||
def convert(*args)
|
def convert(*_args)
|
||||||
""
|
""
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
custom_processor = "CustomMarkdown"
|
custom_processor = "CustomMarkdown"
|
||||||
s = Site.new(site_configuration('markdown' => custom_processor))
|
s = Site.new(site_configuration("markdown" => custom_processor))
|
||||||
s.process
|
s.process
|
||||||
|
|
||||||
# Do some cleanup, we don't like straggling stuff's.
|
# Do some cleanup, we don't like straggling stuff's.
|
||||||
Jekyll::Converters::Markdown.send(:remove_const, :CustomMarkdown)
|
Jekyll::Converters::Markdown.send(:remove_const, :CustomMarkdown)
|
||||||
end
|
end
|
||||||
|
|
||||||
should 'ignore, if there are any bad characters in the class name' do
|
should "ignore, if there are any bad characters in the class name" do
|
||||||
module Jekyll::Converters::Markdown::Custom
|
module Jekyll::Converters::Markdown::Custom
|
||||||
class Markdown
|
class Markdown
|
||||||
def initialize(*args)
|
def initialize(*args)
|
||||||
@args = args
|
@args = args
|
||||||
end
|
end
|
||||||
|
|
||||||
def convert(*args)
|
def convert(*_args)
|
||||||
""
|
""
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
bad_processor = "Custom::Markdown"
|
bad_processor = "Custom::Markdown"
|
||||||
s = Site.new(site_configuration('markdown' => bad_processor, 'incremental' => false))
|
s = Site.new(site_configuration(
|
||||||
|
"markdown" => bad_processor,
|
||||||
|
"incremental" => false
|
||||||
|
))
|
||||||
assert_raises Jekyll::Errors::FatalException do
|
assert_raises Jekyll::Errors::FatalException do
|
||||||
s.process
|
s.process
|
||||||
end
|
end
|
||||||
|
@ -342,96 +361,105 @@ class TestSite < JekyllUnitTest
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'with an invalid markdown processor in the configuration' do
|
context "with an invalid markdown processor in the configuration" do
|
||||||
should 'not throw an error at initialization time' do
|
should "not throw an error at initialization time" do
|
||||||
bad_processor = 'not a processor name'
|
bad_processor = "not a processor name"
|
||||||
assert Site.new(site_configuration('markdown' => bad_processor))
|
assert Site.new(site_configuration("markdown" => bad_processor))
|
||||||
end
|
end
|
||||||
|
|
||||||
should 'throw FatalException at process time' do
|
should "throw FatalException at process time" do
|
||||||
bad_processor = 'not a processor name'
|
bad_processor = "not a processor name"
|
||||||
s = Site.new(site_configuration('markdown' => bad_processor, 'incremental' => false))
|
s = Site.new(site_configuration(
|
||||||
|
"markdown" => bad_processor,
|
||||||
|
"incremental" => false
|
||||||
|
))
|
||||||
assert_raises Jekyll::Errors::FatalException do
|
assert_raises Jekyll::Errors::FatalException do
|
||||||
s.process
|
s.process
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'data directory' do
|
context "data directory" do
|
||||||
should 'auto load yaml files' do
|
should "auto load yaml files" do
|
||||||
site = Site.new(site_configuration)
|
site = Site.new(site_configuration)
|
||||||
site.process
|
site.process
|
||||||
|
|
||||||
file_content = SafeYAML.load_file(File.join(source_dir, '_data', 'members.yaml'))
|
file_content = SafeYAML.load_file(File.join(source_dir, "_data", "members.yaml"))
|
||||||
|
|
||||||
assert_equal site.data['members'], file_content
|
assert_equal site.data["members"], file_content
|
||||||
assert_equal site.site_payload['site']['data']['members'], file_content
|
assert_equal site.site_payload["site"]["data"]["members"], file_content
|
||||||
end
|
end
|
||||||
|
|
||||||
should 'load yaml files from extracted method' do
|
should "load yaml files from extracted method" do
|
||||||
site = Site.new(site_configuration)
|
site = Site.new(site_configuration)
|
||||||
site.process
|
site.process
|
||||||
|
|
||||||
file_content = DataReader.new(site).read_data_file(source_dir('_data', 'members.yaml'))
|
file_content = DataReader.new(site)
|
||||||
|
.read_data_file(source_dir("_data", "members.yaml"))
|
||||||
|
|
||||||
assert_equal site.data['members'], file_content
|
assert_equal site.data["members"], file_content
|
||||||
assert_equal site.site_payload['site']['data']['members'], file_content
|
assert_equal site.site_payload["site"]["data"]["members"], file_content
|
||||||
end
|
end
|
||||||
|
|
||||||
should 'auto load yml files' do
|
should "auto load yml files" do
|
||||||
site = Site.new(site_configuration)
|
site = Site.new(site_configuration)
|
||||||
site.process
|
site.process
|
||||||
|
|
||||||
file_content = SafeYAML.load_file(File.join(source_dir, '_data', 'languages.yml'))
|
file_content = SafeYAML.load_file(File.join(source_dir, "_data", "languages.yml"))
|
||||||
|
|
||||||
assert_equal site.data['languages'], file_content
|
assert_equal site.data["languages"], file_content
|
||||||
assert_equal site.site_payload['site']['data']['languages'], file_content
|
assert_equal site.site_payload["site"]["data"]["languages"], file_content
|
||||||
end
|
end
|
||||||
|
|
||||||
should 'auto load json files' do
|
should "auto load json files" do
|
||||||
site = Site.new(site_configuration)
|
site = Site.new(site_configuration)
|
||||||
site.process
|
site.process
|
||||||
|
|
||||||
file_content = SafeYAML.load_file(File.join(source_dir, '_data', 'members.json'))
|
file_content = SafeYAML.load_file(File.join(source_dir, "_data", "members.json"))
|
||||||
|
|
||||||
assert_equal site.data['members'], file_content
|
assert_equal site.data["members"], file_content
|
||||||
assert_equal site.site_payload['site']['data']['members'], file_content
|
assert_equal site.site_payload["site"]["data"]["members"], file_content
|
||||||
end
|
end
|
||||||
|
|
||||||
should 'auto load yaml files in subdirectory' do
|
should "auto load yaml files in subdirectory" do
|
||||||
site = Site.new(site_configuration)
|
site = Site.new(site_configuration)
|
||||||
site.process
|
site.process
|
||||||
|
|
||||||
file_content = SafeYAML.load_file(File.join(source_dir, '_data', 'categories', 'dairy.yaml'))
|
file_content = SafeYAML.load_file(File.join(
|
||||||
|
source_dir, "_data", "categories", "dairy.yaml"
|
||||||
|
))
|
||||||
|
|
||||||
assert_equal site.data['categories']['dairy'], file_content
|
assert_equal site.data["categories"]["dairy"], file_content
|
||||||
assert_equal site.site_payload['site']['data']['categories']['dairy'], file_content
|
assert_equal(
|
||||||
|
site.site_payload["site"]["data"]["categories"]["dairy"],
|
||||||
|
file_content
|
||||||
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
should "load symlink files in unsafe mode" do
|
should "load symlink files in unsafe mode" do
|
||||||
site = Site.new(site_configuration('safe' => false))
|
site = Site.new(site_configuration("safe" => false))
|
||||||
site.process
|
site.process
|
||||||
|
|
||||||
file_content = SafeYAML.load_file(File.join(source_dir, '_data', 'products.yml'))
|
file_content = SafeYAML.load_file(File.join(source_dir, "_data", "products.yml"))
|
||||||
|
|
||||||
assert_equal site.data['products'], file_content
|
assert_equal site.data["products"], file_content
|
||||||
assert_equal site.site_payload['site']['data']['products'], file_content
|
assert_equal site.site_payload["site"]["data"]["products"], file_content
|
||||||
end
|
end
|
||||||
|
|
||||||
should "load the symlink files in safe mode, as they resolve to inside site.source" do
|
should "load the symlink files in safe mode, " \
|
||||||
site = Site.new(site_configuration('safe' => true))
|
"as they resolve to inside site.source" do
|
||||||
|
site = Site.new(site_configuration("safe" => true))
|
||||||
site.process
|
site.process
|
||||||
file_content = SafeYAML.load_file(File.join(source_dir, '_data', 'products.yml'))
|
file_content = SafeYAML.load_file(File.join(source_dir, "_data", "products.yml"))
|
||||||
assert_equal site.data['products'], file_content
|
assert_equal site.data["products"], file_content
|
||||||
assert_equal site.site_payload['site']['data']['products'], file_content
|
assert_equal site.site_payload["site"]["data"]["products"], file_content
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
context "manipulating the Jekyll environment" do
|
context "manipulating the Jekyll environment" do
|
||||||
setup do
|
setup do
|
||||||
@site = Site.new(site_configuration({
|
@site = Site.new(site_configuration({
|
||||||
'incremental' => false
|
"incremental" => false
|
||||||
}))
|
}))
|
||||||
@site.process
|
@site.process
|
||||||
@page = @site.pages.find { |p| p.name == "environment.html" }
|
@page = @site.pages.find { |p| p.name == "environment.html" }
|
||||||
|
@ -445,7 +473,7 @@ class TestSite < JekyllUnitTest
|
||||||
setup do
|
setup do
|
||||||
ENV["JEKYLL_ENV"] = "production"
|
ENV["JEKYLL_ENV"] = "production"
|
||||||
@site = Site.new(site_configuration({
|
@site = Site.new(site_configuration({
|
||||||
'incremental' => false
|
"incremental" => false
|
||||||
}))
|
}))
|
||||||
@site.process
|
@site.process
|
||||||
@page = @site.pages.find { |p| p.name == "environment.html" }
|
@page = @site.pages.find { |p| p.name == "environment.html" }
|
||||||
|
@ -463,7 +491,7 @@ class TestSite < JekyllUnitTest
|
||||||
|
|
||||||
context "with liquid profiling" do
|
context "with liquid profiling" do
|
||||||
setup do
|
setup do
|
||||||
@site = Site.new(site_configuration('profile' => true))
|
@site = Site.new(site_configuration("profile" => true))
|
||||||
end
|
end
|
||||||
|
|
||||||
# Suppress output while testing
|
# Suppress output while testing
|
||||||
|
@ -483,7 +511,7 @@ class TestSite < JekyllUnitTest
|
||||||
context "incremental build" do
|
context "incremental build" do
|
||||||
setup do
|
setup do
|
||||||
@site = Site.new(site_configuration({
|
@site = Site.new(site_configuration({
|
||||||
'incremental' => true
|
"incremental" => true
|
||||||
}))
|
}))
|
||||||
@site.read
|
@site.read
|
||||||
end
|
end
|
||||||
|
@ -533,8 +561,6 @@ class TestSite < JekyllUnitTest
|
||||||
mtime2 = File.stat(dest).mtime.to_i
|
mtime2 = File.stat(dest).mtime.to_i
|
||||||
refute_equal mtime1, mtime2 # must be regenerated
|
refute_equal mtime1, mtime2 # must be regenerated
|
||||||
end
|
end
|
||||||
|
end
|
||||||
end
|
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,18 +1,17 @@
|
||||||
# coding: utf-8
|
# coding: utf-8
|
||||||
|
require "helper"
|
||||||
require 'helper'
|
|
||||||
|
|
||||||
class TestTags < JekyllUnitTest
|
class TestTags < JekyllUnitTest
|
||||||
|
|
||||||
def setup
|
def setup
|
||||||
FileUtils.mkdir_p("tmp")
|
FileUtils.mkdir_p("tmp")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# rubocop:disable Metrics/AbcSize
|
||||||
def create_post(content, override = {}, converter_class = Jekyll::Converters::Markdown)
|
def create_post(content, override = {}, converter_class = Jekyll::Converters::Markdown)
|
||||||
site = fixture_site({ "highlighter" => "rouge" }.merge(override))
|
site = fixture_site({ "highlighter" => "rouge" }.merge(override))
|
||||||
|
|
||||||
site.posts.docs.concat(PostReader.new(site).read_posts('')) if override['read_posts']
|
site.posts.docs.concat(PostReader.new(site).read_posts("")) if override["read_posts"]
|
||||||
CollectionReader.new(site).read if override['read_collections']
|
CollectionReader.new(site).read if override["read_collections"]
|
||||||
|
|
||||||
info = { :filters => [Jekyll::Filters], :registers => { :site => site } }
|
info = { :filters => [Jekyll::Filters], :registers => { :site => site } }
|
||||||
@converter = site.converters.find { |c| c.class == converter_class }
|
@converter = site.converters.find { |c| c.class == converter_class }
|
||||||
|
@ -22,6 +21,7 @@ class TestTags < JekyllUnitTest
|
||||||
@result = Liquid::Template.parse(content).render!(payload, info)
|
@result = Liquid::Template.parse(content).render!(payload, info)
|
||||||
@result = @converter.convert(@result)
|
@result = @converter.convert(@result)
|
||||||
end
|
end
|
||||||
|
# rubocop:enable Metrics/AbcSize
|
||||||
|
|
||||||
def fill_post(code, override = {})
|
def fill_post(code, override = {})
|
||||||
content = <<CONTENT
|
content = <<CONTENT
|
||||||
|
@ -42,7 +42,12 @@ CONTENT
|
||||||
end
|
end
|
||||||
|
|
||||||
def highlight_block_with_opts(options_string)
|
def highlight_block_with_opts(options_string)
|
||||||
Jekyll::Tags::HighlightBlock.parse('highlight', options_string, ["test", "{% endhighlight %}", "\n"], {})
|
Jekyll::Tags::HighlightBlock.parse(
|
||||||
|
"highlight",
|
||||||
|
options_string,
|
||||||
|
["test", "{% endhighlight %}", "\n"],
|
||||||
|
{}
|
||||||
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
context "language name" do
|
context "language name" do
|
||||||
|
@ -63,49 +68,72 @@ CONTENT
|
||||||
|
|
||||||
context "highlight tag in unsafe mode" do
|
context "highlight tag in unsafe mode" do
|
||||||
should "set the no options with just a language name" do
|
should "set the no options with just a language name" do
|
||||||
tag = highlight_block_with_opts('ruby ')
|
tag = highlight_block_with_opts("ruby ")
|
||||||
assert_equal({}, tag.instance_variable_get(:@highlight_options))
|
assert_equal({}, tag.instance_variable_get(:@highlight_options))
|
||||||
end
|
end
|
||||||
|
|
||||||
should "set the linenos option as 'inline' if no linenos value" do
|
should "set the linenos option as 'inline' if no linenos value" do
|
||||||
tag = highlight_block_with_opts('ruby linenos ')
|
tag = highlight_block_with_opts("ruby linenos ")
|
||||||
assert_equal({ :linenos => 'inline' }, tag.instance_variable_get(:@highlight_options))
|
assert_equal(
|
||||||
|
{ :linenos => "inline" },
|
||||||
|
tag.instance_variable_get(:@highlight_options)
|
||||||
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
should "set the linenos option to 'table' if the linenos key is given the table value" do
|
should "set the linenos option to 'table' " \
|
||||||
tag = highlight_block_with_opts('ruby linenos=table ')
|
"if the linenos key is given the table value" do
|
||||||
assert_equal({ :linenos => 'table' }, tag.instance_variable_get(:@highlight_options))
|
tag = highlight_block_with_opts("ruby linenos=table ")
|
||||||
|
assert_equal(
|
||||||
|
{ :linenos => "table" },
|
||||||
|
tag.instance_variable_get(:@highlight_options)
|
||||||
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
should "recognize nowrap option with linenos set" do
|
should "recognize nowrap option with linenos set" do
|
||||||
tag = highlight_block_with_opts('ruby linenos=table nowrap ')
|
tag = highlight_block_with_opts("ruby linenos=table nowrap ")
|
||||||
assert_equal({ :linenos => 'table', :nowrap => true }, tag.instance_variable_get(:@highlight_options))
|
assert_equal(
|
||||||
|
{ :linenos => "table", :nowrap => true },
|
||||||
|
tag.instance_variable_get(:@highlight_options)
|
||||||
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
should "recognize the cssclass option" do
|
should "recognize the cssclass option" do
|
||||||
tag = highlight_block_with_opts('ruby linenos=table cssclass=hl ')
|
tag = highlight_block_with_opts("ruby linenos=table cssclass=hl ")
|
||||||
assert_equal({ :cssclass => 'hl', :linenos => 'table' }, tag.instance_variable_get(:@highlight_options))
|
assert_equal(
|
||||||
|
{ :cssclass => "hl", :linenos => "table" },
|
||||||
|
tag.instance_variable_get(:@highlight_options)
|
||||||
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
should "recognize the hl_linenos option and its value" do
|
should "recognize the hl_linenos option and its value" do
|
||||||
tag = highlight_block_with_opts('ruby linenos=table cssclass=hl hl_linenos=3 ')
|
tag = highlight_block_with_opts("ruby linenos=table cssclass=hl hl_linenos=3 ")
|
||||||
assert_equal({ :cssclass => 'hl', :linenos => 'table', :hl_linenos => '3' }, tag.instance_variable_get(:@highlight_options))
|
assert_equal(
|
||||||
|
{ :cssclass => "hl", :linenos => "table", :hl_linenos => "3" },
|
||||||
|
tag.instance_variable_get(:@highlight_options)
|
||||||
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
should "recognize multiple values of hl_linenos" do
|
should "recognize multiple values of hl_linenos" do
|
||||||
tag = highlight_block_with_opts('ruby linenos=table cssclass=hl hl_linenos="3 5 6" ')
|
tag = highlight_block_with_opts 'ruby linenos=table cssclass=hl hl_linenos="3 5 6" '
|
||||||
assert_equal({ :cssclass => 'hl', :linenos => 'table', :hl_linenos => ['3', '5', '6'] }, tag.instance_variable_get(:@highlight_options))
|
assert_equal(
|
||||||
|
{ :cssclass => "hl", :linenos => "table", :hl_linenos => %w(3 5 6) },
|
||||||
|
tag.instance_variable_get(:@highlight_options)
|
||||||
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
should "treat language name as case insensitive" do
|
should "treat language name as case insensitive" do
|
||||||
tag = highlight_block_with_opts('Ruby ')
|
tag = highlight_block_with_opts("Ruby ")
|
||||||
assert_equal "ruby", tag.instance_variable_get(:@lang), "lexers should be case insensitive"
|
assert_equal(
|
||||||
|
"ruby",
|
||||||
|
tag.instance_variable_get(:@lang),
|
||||||
|
"lexers should be case insensitive"
|
||||||
|
)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context "in safe mode" do
|
context "in safe mode" do
|
||||||
setup do
|
setup do
|
||||||
@tag = highlight_block_with_opts('text ')
|
@tag = highlight_block_with_opts("text ")
|
||||||
end
|
end
|
||||||
|
|
||||||
should "allow linenos" do
|
should "allow linenos" do
|
||||||
|
@ -114,8 +142,8 @@ CONTENT
|
||||||
end
|
end
|
||||||
|
|
||||||
should "allow hl_lines" do
|
should "allow hl_lines" do
|
||||||
sanitized = @tag.sanitized_opts({:hl_lines => %w[1 2 3 4]}, true)
|
sanitized = @tag.sanitized_opts({ :hl_lines => %w(1 2 3 4) }, true)
|
||||||
assert_equal %w[1 2 3 4], sanitized[:hl_lines]
|
assert_equal %w(1 2 3 4), sanitized[:hl_lines]
|
||||||
end
|
end
|
||||||
|
|
||||||
should "allow cssclass" do
|
should "allow cssclass" do
|
||||||
|
@ -145,7 +173,7 @@ CONTENT
|
||||||
|
|
||||||
context "post content has highlight tag" do
|
context "post content has highlight tag" do
|
||||||
setup do
|
setup do
|
||||||
fill_post("test", {'highlighter' => 'pygments'})
|
fill_post("test", { "highlighter" => "pygments" })
|
||||||
end
|
end
|
||||||
|
|
||||||
should "not cause a markdown error" do
|
should "not cause a markdown error" do
|
||||||
|
@ -153,31 +181,45 @@ CONTENT
|
||||||
end
|
end
|
||||||
|
|
||||||
should "render markdown with pygments" do
|
should "render markdown with pygments" do
|
||||||
assert_match %{<pre><code class="language-text" data-lang="text">test</code></pre>}, @result
|
assert_match(
|
||||||
|
%(<pre><code class="language-text" data-lang="text">test</code></pre>),
|
||||||
|
@result
|
||||||
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
should "render markdown with pygments with line numbers" do
|
should "render markdown with pygments with line numbers" do
|
||||||
assert_match %{<pre><code class="language-text" data-lang="text"><span class="lineno">1</span> test</code></pre>}, @result
|
assert_match(
|
||||||
|
%(<pre><code class="language-text" data-lang="text">) +
|
||||||
|
%(<span class="lineno">1</span> test</code></pre>),
|
||||||
|
@result
|
||||||
|
)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context "post content has highlight with file reference" do
|
context "post content has highlight with file reference" do
|
||||||
setup do
|
setup do
|
||||||
fill_post("./jekyll.gemspec", {'highlighter' => 'pygments'})
|
fill_post("./jekyll.gemspec", { "highlighter" => "pygments" })
|
||||||
end
|
end
|
||||||
|
|
||||||
should "not embed the file" do
|
should "not embed the file" do
|
||||||
assert_match %{<pre><code class="language-text" data-lang="text">./jekyll.gemspec</code></pre>}, @result
|
assert_match(
|
||||||
|
%(<pre><code class="language-text" data-lang="text">) +
|
||||||
|
%(./jekyll.gemspec</code></pre>),
|
||||||
|
@result
|
||||||
|
)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context "post content has highlight tag with UTF character" do
|
context "post content has highlight tag with UTF character" do
|
||||||
setup do
|
setup do
|
||||||
fill_post("Æ", {'highlighter' => 'pygments'})
|
fill_post("Æ", { "highlighter" => "pygments" })
|
||||||
end
|
end
|
||||||
|
|
||||||
should "render markdown with pygments line handling" do
|
should "render markdown with pygments line handling" do
|
||||||
assert_match %{<pre><code class="language-text" data-lang="text">Æ</code></pre>}, @result
|
assert_match(
|
||||||
|
%(<pre><code class="language-text" data-lang="text">Æ</code></pre>),
|
||||||
|
@result
|
||||||
|
)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -190,15 +232,19 @@ CONTENT
|
||||||
[1,] FALSE TRUE
|
[1,] FALSE TRUE
|
||||||
[2,] FALSE TRUE
|
[2,] FALSE TRUE
|
||||||
EOS
|
EOS
|
||||||
fill_post(code, {'highlighter' => 'pygments'})
|
fill_post(code, { "highlighter" => "pygments" })
|
||||||
end
|
end
|
||||||
|
|
||||||
should "only strip the preceding newlines" do
|
should "only strip the preceding newlines" do
|
||||||
assert_match %{<pre><code class=\"language-text\" data-lang=\"text\"> [,1] [,2]}, @result
|
assert_match(
|
||||||
|
%(<pre><code class=\"language-text\" data-lang=\"text\"> [,1] [,2]),
|
||||||
|
@result
|
||||||
|
)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context "post content has highlight tag with preceding spaces & lines in several places" do
|
context "post content has highlight tag " \
|
||||||
|
"with preceding spaces & lines in several places" do
|
||||||
setup do
|
setup do
|
||||||
code = <<-EOS
|
code = <<-EOS
|
||||||
|
|
||||||
|
@ -211,21 +257,29 @@ EOS
|
||||||
|
|
||||||
|
|
||||||
EOS
|
EOS
|
||||||
fill_post(code, {'highlighter' => 'pygments'})
|
fill_post(code, { "highlighter" => "pygments" })
|
||||||
end
|
end
|
||||||
|
|
||||||
should "only strip the newlines which precede and succeed the entire block" do
|
should "only strip the newlines which precede and succeed the entire block" do
|
||||||
assert_match "<pre><code class=\"language-text\" data-lang=\"text\"> [,1] [,2]\n\n\n[1,] FALSE TRUE\n[2,] FALSE TRUE</code></pre>", @result
|
assert_match(
|
||||||
|
"<pre><code class=\"language-text\" data-lang=\"text\">" \
|
||||||
|
" [,1] [,2]\n\n\n[1,] FALSE TRUE\n[2,] FALSE TRUE</code></pre>",
|
||||||
|
@result
|
||||||
|
)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context "post content has highlight tag with preceding spaces & Windows-style newlines" do
|
context "post content has highlight tag with " \
|
||||||
|
"preceding spaces & Windows-style newlines" do
|
||||||
setup do
|
setup do
|
||||||
fill_post "\r\n\r\n\r\n [,1] [,2]", {'highlighter' => 'pygments'}
|
fill_post "\r\n\r\n\r\n [,1] [,2]", { "highlighter" => "pygments" }
|
||||||
end
|
end
|
||||||
|
|
||||||
should "only strip the preceding newlines" do
|
should "only strip the preceding newlines" do
|
||||||
assert_match %{<pre><code class=\"language-text\" data-lang=\"text\"> [,1] [,2]}, @result
|
assert_match(
|
||||||
|
%(<pre><code class="language-text" data-lang="text"> [,1] [,2]),
|
||||||
|
@result
|
||||||
|
)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -236,11 +290,14 @@ EOS
|
||||||
[1,] FALSE TRUE
|
[1,] FALSE TRUE
|
||||||
[2,] FALSE TRUE
|
[2,] FALSE TRUE
|
||||||
EOS
|
EOS
|
||||||
fill_post(code, {'highlighter' => 'pygments'})
|
fill_post(code, { "highlighter" => "pygments" })
|
||||||
end
|
end
|
||||||
|
|
||||||
should "only strip the preceding newlines" do
|
should "only strip the preceding newlines" do
|
||||||
assert_match %{<pre><code class=\"language-text\" data-lang=\"text\"> [,1] [,2]}, @result
|
assert_match(
|
||||||
|
%(<pre><code class=\"language-text\" data-lang=\"text\"> [,1] [,2]),
|
||||||
|
@result
|
||||||
|
)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -252,11 +309,21 @@ EOS
|
||||||
end
|
end
|
||||||
|
|
||||||
should "render markdown with rouge" do
|
should "render markdown with rouge" do
|
||||||
assert_match %{<pre><code class="language-text" data-lang="text">test</code></pre>}, @result
|
assert_match(
|
||||||
|
%(<pre><code class="language-text" data-lang="text">test</code></pre>),
|
||||||
|
@result
|
||||||
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
should "render markdown with rouge with line numbers" do
|
should "render markdown with rouge with line numbers" do
|
||||||
assert_match %{<table style="border-spacing: 0"><tbody><tr><td class="gutter gl" style="text-align: right"><pre class="lineno">1</pre></td><td class="code"><pre>test<span class="w">\n</span></pre></td></tr></tbody></table>}, @result
|
assert_match(
|
||||||
|
%(<table style="border-spacing: 0"><tbody>) +
|
||||||
|
%(<tr><td class="gutter gl" style="text-align: right">) +
|
||||||
|
%(<pre class="lineno">1</pre></td>) +
|
||||||
|
%(<td class="code"><pre>test<span class="w">\n</span></pre></td></tr>) +
|
||||||
|
%(</tbody></table>),
|
||||||
|
@result
|
||||||
|
)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -266,7 +333,11 @@ EOS
|
||||||
end
|
end
|
||||||
|
|
||||||
should "not embed the file" do
|
should "not embed the file" do
|
||||||
assert_match %{<pre><code class="language-text" data-lang="text">./jekyll.gemspec</code></pre>}, @result
|
assert_match(
|
||||||
|
'<pre><code class="language-text" data-lang="text">' \
|
||||||
|
"./jekyll.gemspec</code></pre>",
|
||||||
|
@result
|
||||||
|
)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -276,7 +347,10 @@ EOS
|
||||||
end
|
end
|
||||||
|
|
||||||
should "render markdown with pygments line handling" do
|
should "render markdown with pygments line handling" do
|
||||||
assert_match %{<pre><code class="language-text" data-lang="text">Æ</code></pre>}, @result
|
assert_match(
|
||||||
|
'<pre><code class="language-text" data-lang="text">Æ</code></pre>',
|
||||||
|
@result
|
||||||
|
)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -292,11 +366,15 @@ EOS
|
||||||
end
|
end
|
||||||
|
|
||||||
should "only strip the preceding newlines" do
|
should "only strip the preceding newlines" do
|
||||||
assert_match %{<pre><code class=\"language-text\" data-lang=\"text\"> [,1] [,2]}, @result
|
assert_match(
|
||||||
|
'<pre><code class="language-text" data-lang="text"> [,1] [,2]',
|
||||||
|
@result
|
||||||
|
)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context "post content has highlight tag with preceding spaces & lines in several places" do
|
context "post content has highlight tag with " \
|
||||||
|
"preceding spaces & lines in several places" do
|
||||||
setup do
|
setup do
|
||||||
fill_post <<-EOS
|
fill_post <<-EOS
|
||||||
|
|
||||||
|
@ -312,7 +390,11 @@ EOS
|
||||||
end
|
end
|
||||||
|
|
||||||
should "only strip the newlines which precede and succeed the entire block" do
|
should "only strip the newlines which precede and succeed the entire block" do
|
||||||
assert_match "<pre><code class=\"language-text\" data-lang=\"text\"> [,1] [,2]\n\n\n[1,] FALSE TRUE\n[2,] FALSE TRUE</code></pre>", @result
|
assert_match(
|
||||||
|
"<pre><code class=\"language-text\" data-lang=\"text\"> [,1] [,2]\n\n\n" \
|
||||||
|
"[1,] FALSE TRUE\n[2,] FALSE TRUE</code></pre>",
|
||||||
|
@result
|
||||||
|
)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -333,17 +415,29 @@ EOS
|
||||||
end
|
end
|
||||||
|
|
||||||
should "should stop highlighting at boundary" do
|
should "should stop highlighting at boundary" do
|
||||||
assert_match "<p>This is not yet highlighted</p>\n\n<figure class=\"highlight\"><pre><code class=\"language-php\" data-lang=\"php\"><table style=\"border-spacing: 0\"><tbody><tr><td class=\"gutter gl\" style=\"text-align: right\"><pre class=\"lineno\">1</pre></td><td class=\"code\"><pre>test<span class=\"w\">\n</span></pre></td></tr></tbody></table></code></pre></figure>\n\n<p>This should not be highlighted, right?</p>", @result
|
expected = <<-EOS
|
||||||
|
<p>This is not yet highlighted</p>
|
||||||
|
|
||||||
|
<figure class="highlight"><pre><code class="language-php" data-lang="php"><table style="border-spacing: 0"><tbody><tr><td class="gutter gl" style="text-align: right"><pre class="lineno">1</pre></td><td class="code"><pre>test<span class="w">
|
||||||
|
</span></pre></td></tr></tbody></table></code></pre></figure>
|
||||||
|
|
||||||
|
<p>This should not be highlighted, right?</p>
|
||||||
|
EOS
|
||||||
|
assert_match(expected, @result)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context "post content has highlight tag with preceding spaces & Windows-style newlines" do
|
context "post content has highlight tag with " \
|
||||||
|
"preceding spaces & Windows-style newlines" do
|
||||||
setup do
|
setup do
|
||||||
fill_post "\r\n\r\n\r\n [,1] [,2]"
|
fill_post "\r\n\r\n\r\n [,1] [,2]"
|
||||||
end
|
end
|
||||||
|
|
||||||
should "only strip the preceding newlines" do
|
should "only strip the preceding newlines" do
|
||||||
assert_match %{<pre><code class=\"language-text\" data-lang=\"text\"> [,1] [,2]}, @result
|
assert_match(
|
||||||
|
'<pre><code class="language-text" data-lang="text"> [,1] [,2]',
|
||||||
|
@result
|
||||||
|
)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -357,7 +451,10 @@ EOS
|
||||||
end
|
end
|
||||||
|
|
||||||
should "only strip the preceding newlines" do
|
should "only strip the preceding newlines" do
|
||||||
assert_match %{<pre><code class=\"language-text\" data-lang=\"text\"> [,1] [,2]}, @result
|
assert_match(
|
||||||
|
'<pre><code class="language-text" data-lang="text"> [,1] [,2]',
|
||||||
|
@result
|
||||||
|
)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -388,24 +485,24 @@ CONTENT
|
||||||
end
|
end
|
||||||
|
|
||||||
create_post(@content, {
|
create_post(@content, {
|
||||||
'markdown' => 'rdiscount'
|
"markdown" => "rdiscount"
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
should "parse correctly" do
|
should "parse correctly" do
|
||||||
assert_match %r{<em>FIGHT!</em>}, @result
|
assert_match %r{<em>FIGHT!</em>}, @result
|
||||||
assert_match %r{<em>FINISH HIM</em>}, @result
|
assert_match %r!<em>FINISH HIM</em>!, @result
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context "using Kramdown" do
|
context "using Kramdown" do
|
||||||
setup do
|
setup do
|
||||||
create_post(@content, 'markdown' => 'kramdown')
|
create_post(@content, "markdown" => "kramdown")
|
||||||
end
|
end
|
||||||
|
|
||||||
should "parse correctly" do
|
should "parse correctly" do
|
||||||
assert_match %r{<em>FIGHT!</em>}, @result
|
assert_match %r{<em>FIGHT!</em>}, @result
|
||||||
assert_match %r{<em>FINISH HIM</em>}, @result
|
assert_match %r!<em>FINISH HIM</em>!, @result
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -418,13 +515,13 @@ CONTENT
|
||||||
end
|
end
|
||||||
|
|
||||||
create_post(@content, {
|
create_post(@content, {
|
||||||
'markdown' => 'redcarpet'
|
"markdown" => "redcarpet"
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
should "parse correctly" do
|
should "parse correctly" do
|
||||||
assert_match %r{<em>FIGHT!</em>}, @result
|
assert_match %r{<em>FIGHT!</em>}, @result
|
||||||
assert_match %r{<em>FINISH HIM</em>}, @result
|
assert_match %r!<em>FINISH HIM</em>!, @result
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -438,7 +535,12 @@ title: Post linking
|
||||||
|
|
||||||
{% post_url 2008-11-21-complex %}
|
{% post_url 2008-11-21-complex %}
|
||||||
CONTENT
|
CONTENT
|
||||||
create_post(content, {'permalink' => 'pretty', 'source' => source_dir, 'destination' => dest_dir, 'read_posts' => true})
|
create_post(content, {
|
||||||
|
"permalink" => "pretty",
|
||||||
|
"source" => source_dir,
|
||||||
|
"destination" => dest_dir,
|
||||||
|
"read_posts" => true
|
||||||
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
should "not cause an error" do
|
should "not cause an error" do
|
||||||
|
@ -446,7 +548,7 @@ CONTENT
|
||||||
end
|
end
|
||||||
|
|
||||||
should "have the url to the \"complex\" post from 2008-11-21" do
|
should "have the url to the \"complex\" post from 2008-11-21" do
|
||||||
assert_match %r{/2008/11/21/complex/}, @result
|
assert_match %r!/2008/11/21/complex/!, @result
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -462,7 +564,12 @@ title: Post linking
|
||||||
- 3 {% post_url es/2008-11-21-nested %}
|
- 3 {% post_url es/2008-11-21-nested %}
|
||||||
- 4 {% post_url /es/2008-11-21-nested %}
|
- 4 {% post_url /es/2008-11-21-nested %}
|
||||||
CONTENT
|
CONTENT
|
||||||
create_post(content, {'permalink' => 'pretty', 'source' => source_dir, 'destination' => dest_dir, 'read_posts' => true})
|
create_post(content, {
|
||||||
|
"permalink" => "pretty",
|
||||||
|
"source" => source_dir,
|
||||||
|
"destination" => dest_dir,
|
||||||
|
"read_posts" => true
|
||||||
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
should "not cause an error" do
|
should "not cause an error" do
|
||||||
|
@ -470,13 +577,13 @@ CONTENT
|
||||||
end
|
end
|
||||||
|
|
||||||
should "have the url to the \"complex\" post from 2008-11-21" do
|
should "have the url to the \"complex\" post from 2008-11-21" do
|
||||||
assert_match %r{1\s/2008/11/21/complex/}, @result
|
assert_match %r!1\s/2008/11/21/complex/!, @result
|
||||||
assert_match %r{2\s/2008/11/21/complex/}, @result
|
assert_match %r!2\s/2008/11/21/complex/!, @result
|
||||||
end
|
end
|
||||||
|
|
||||||
should "have the url to the \"nested\" post from 2008-11-21" do
|
should "have the url to the \"nested\" post from 2008-11-21" do
|
||||||
assert_match %r{3\s/2008/11/21/nested/}, @result
|
assert_match %r!3\s/2008/11/21/nested/!, @result
|
||||||
assert_match %r{4\s/2008/11/21/nested/}, @result
|
assert_match %r!4\s/2008/11/21/nested/!, @result
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -492,10 +599,10 @@ CONTENT
|
||||||
|
|
||||||
assert_raises Jekyll::Errors::PostURLError do
|
assert_raises Jekyll::Errors::PostURLError do
|
||||||
create_post(content, {
|
create_post(content, {
|
||||||
'permalink' => 'pretty',
|
"permalink" => "pretty",
|
||||||
'source' => source_dir,
|
"source" => source_dir,
|
||||||
'destination' => dest_dir,
|
"destination" => dest_dir,
|
||||||
'read_posts' => true
|
"read_posts" => true
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -511,10 +618,10 @@ CONTENT
|
||||||
|
|
||||||
assert_raises Jekyll::Errors::InvalidDateError do
|
assert_raises Jekyll::Errors::InvalidDateError do
|
||||||
create_post(content, {
|
create_post(content, {
|
||||||
'permalink' => 'pretty',
|
"permalink" => "pretty",
|
||||||
'source' => source_dir,
|
"source" => source_dir,
|
||||||
'destination' => dest_dir,
|
"destination" => dest_dir,
|
||||||
'read_posts' => true
|
"read_posts" => true
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -529,15 +636,20 @@ title: linking
|
||||||
|
|
||||||
{% link _methods/yaml_with_dots.md %}
|
{% link _methods/yaml_with_dots.md %}
|
||||||
CONTENT
|
CONTENT
|
||||||
create_post(content, {'source' => source_dir, 'destination' => dest_dir, 'collections' => { 'methods' => { 'output' => true }}, 'read_collections' => true})
|
create_post(content, {
|
||||||
|
"source" => source_dir,
|
||||||
|
"destination" => dest_dir,
|
||||||
|
"collections" => { "methods" => { "output" => true } },
|
||||||
|
"read_collections" => true
|
||||||
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
should "not cause an error" do
|
should "not cause an error" do
|
||||||
refute_match /markdown\-html\-error/, @result
|
refute_match(/markdown\-html\-error/, @result)
|
||||||
end
|
end
|
||||||
|
|
||||||
should "have the url to the \"yaml_with_dots\" item" do
|
should "have the url to the \"yaml_with_dots\" item" do
|
||||||
assert_match %r{/methods/yaml_with_dots\.html}, @result
|
assert_match(%r!/methods/yaml_with_dots\.html!, @result)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -551,19 +663,24 @@ title: linking
|
||||||
- 1 {% link _methods/sanitized_path.md %}
|
- 1 {% link _methods/sanitized_path.md %}
|
||||||
- 2 {% link _methods/site/generate.md %}
|
- 2 {% link _methods/site/generate.md %}
|
||||||
CONTENT
|
CONTENT
|
||||||
create_post(content, {'source' => source_dir, 'destination' => dest_dir, 'collections' => { 'methods' => { 'output' => true }}, 'read_collections' => true})
|
create_post(content, {
|
||||||
|
"source" => source_dir,
|
||||||
|
"destination" => dest_dir,
|
||||||
|
"collections" => { "methods" => { "output" => true } },
|
||||||
|
"read_collections" => true
|
||||||
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
should "not cause an error" do
|
should "not cause an error" do
|
||||||
refute_match /markdown\-html\-error/, @result
|
refute_match(/markdown\-html\-error/, @result)
|
||||||
end
|
end
|
||||||
|
|
||||||
should "have the url to the \"sanitized_path\" item" do
|
should "have the url to the \"sanitized_path\" item" do
|
||||||
assert_match %r{1\s/methods/sanitized_path\.html}, @result
|
assert_match %r!1\s/methods/sanitized_path\.html!, @result
|
||||||
end
|
end
|
||||||
|
|
||||||
should "have the url to the \"site/generate\" item" do
|
should "have the url to the \"site/generate\" item" do
|
||||||
assert_match %r{2\s/methods/site/generate\.html}, @result
|
assert_match %r!2\s/methods/site/generate\.html!, @result
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -578,17 +695,20 @@ title: Invalid linking
|
||||||
CONTENT
|
CONTENT
|
||||||
|
|
||||||
assert_raises ArgumentError do
|
assert_raises ArgumentError do
|
||||||
create_post(content, {'source' => source_dir, 'destination' => dest_dir, 'collections' => { 'methods' => { 'output' => true }}, 'read_collections' => true})
|
create_post(content, {
|
||||||
|
"source" => source_dir,
|
||||||
|
"destination" => dest_dir,
|
||||||
|
"collections" => { "methods" => { "output" => true } },
|
||||||
|
"read_collections" => true
|
||||||
|
})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context "include tag with parameters" do
|
context "include tag with parameters" do
|
||||||
|
|
||||||
context "with symlink'd include" do
|
context "with symlink'd include" do
|
||||||
|
|
||||||
should "not allow symlink includes" do
|
should "not allow symlink includes" do
|
||||||
File.open("tmp/pages-test", 'w') { |file| file.write("SYMLINK TEST") }
|
File.open("tmp/pages-test", "w") { |file| file.write("SYMLINK TEST") }
|
||||||
assert_raises IOError do
|
assert_raises IOError do
|
||||||
content = <<CONTENT
|
content = <<CONTENT
|
||||||
---
|
---
|
||||||
|
@ -598,9 +718,15 @@ title: Include symlink
|
||||||
{% include tmp/pages-test %}
|
{% include tmp/pages-test %}
|
||||||
|
|
||||||
CONTENT
|
CONTENT
|
||||||
create_post(content, {'permalink' => 'pretty', 'source' => source_dir, 'destination' => dest_dir, 'read_posts' => true, 'safe' => true })
|
create_post(content, {
|
||||||
|
"permalink" => "pretty",
|
||||||
|
"source" => source_dir,
|
||||||
|
"destination" => dest_dir,
|
||||||
|
"read_posts" => true,
|
||||||
|
"safe" => true
|
||||||
|
})
|
||||||
end
|
end
|
||||||
@result ||= ''
|
@result ||= ""
|
||||||
refute_match(/SYMLINK TEST/, @result)
|
refute_match(/SYMLINK TEST/, @result)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -614,9 +740,19 @@ title: Include symlink
|
||||||
{% include tmp/pages-test-does-not-exist %}
|
{% include tmp/pages-test-does-not-exist %}
|
||||||
|
|
||||||
CONTENT
|
CONTENT
|
||||||
create_post(content, {'permalink' => 'pretty', 'source' => source_dir, 'destination' => dest_dir, 'read_posts' => true, 'safe' => true })
|
create_post(content, {
|
||||||
|
"permalink" => "pretty",
|
||||||
|
"source" => source_dir,
|
||||||
|
"destination" => dest_dir,
|
||||||
|
"read_posts" => true,
|
||||||
|
"safe" => true
|
||||||
|
})
|
||||||
end
|
end
|
||||||
assert_match "Could not locate the included file 'tmp/pages-test-does-not-exist' in any of [\"#{source_dir}/_includes\"].", ex.message
|
assert_match(
|
||||||
|
"Could not locate the included file 'tmp/pages-test-does-not-exist' " \
|
||||||
|
"in any of [\"#{source_dir}/_includes\"].",
|
||||||
|
ex.message
|
||||||
|
)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -631,7 +767,12 @@ title: Include tag parameters
|
||||||
|
|
||||||
{% include params.html param="value" %}
|
{% include params.html param="value" %}
|
||||||
CONTENT
|
CONTENT
|
||||||
create_post(content, {'permalink' => 'pretty', 'source' => source_dir, 'destination' => dest_dir, 'read_posts' => true})
|
create_post(content, {
|
||||||
|
"permalink" => "pretty",
|
||||||
|
"source" => source_dir,
|
||||||
|
"destination" => dest_dir,
|
||||||
|
"read_posts" => true
|
||||||
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
should "correctly output include variable" do
|
should "correctly output include variable" do
|
||||||
|
@ -652,8 +793,14 @@ title: Invalid parameter syntax
|
||||||
|
|
||||||
{% include params.html param s="value" %}
|
{% include params.html param s="value" %}
|
||||||
CONTENT
|
CONTENT
|
||||||
assert_raises ArgumentError, 'Did not raise exception on invalid "include" syntax' do
|
assert_raises ArgumentError, "Did not raise exception on invalid " \
|
||||||
create_post(content, {'permalink' => 'pretty', 'source' => source_dir, 'destination' => dest_dir, 'read_posts' => true})
|
'"include" syntax' do
|
||||||
|
create_post(content, {
|
||||||
|
"permalink" => "pretty",
|
||||||
|
"source" => source_dir,
|
||||||
|
"destination" => dest_dir,
|
||||||
|
"read_posts" => true
|
||||||
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
content = <<CONTENT
|
content = <<CONTENT
|
||||||
|
@ -663,8 +810,14 @@ title: Invalid parameter syntax
|
||||||
|
|
||||||
{% include params.html params="value %}
|
{% include params.html params="value %}
|
||||||
CONTENT
|
CONTENT
|
||||||
assert_raises ArgumentError, 'Did not raise exception on invalid "include" syntax' do
|
assert_raises ArgumentError, "Did not raise exception on invalid " \
|
||||||
create_post(content, {'permalink' => 'pretty', 'source' => source_dir, 'destination' => dest_dir, 'read_posts' => true})
|
'"include" syntax' do
|
||||||
|
create_post(content, {
|
||||||
|
"permalink" => "pretty",
|
||||||
|
"source" => source_dir,
|
||||||
|
"destination" => dest_dir,
|
||||||
|
"read_posts" => true
|
||||||
|
})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -678,12 +831,17 @@ title: multiple include parameters
|
||||||
|
|
||||||
{% include params.html param1="new_value" param2="another" %}
|
{% include params.html param1="new_value" param2="another" %}
|
||||||
CONTENT
|
CONTENT
|
||||||
create_post(content, {'permalink' => 'pretty', 'source' => source_dir, 'destination' => dest_dir, 'read_posts' => true})
|
create_post(content, {
|
||||||
|
"permalink" => "pretty",
|
||||||
|
"source" => source_dir,
|
||||||
|
"destination" => dest_dir,
|
||||||
|
"read_posts" => true
|
||||||
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
should "list all parameters" do
|
should "list all parameters" do
|
||||||
assert_match '<li>param1 = new_value</li>', @result
|
assert_match "<li>param1 = new_value</li>", @result
|
||||||
assert_match '<li>param2 = another</li>', @result
|
assert_match "<li>param2 = another</li>", @result
|
||||||
end
|
end
|
||||||
|
|
||||||
should "not include previously used parameters" do
|
should "not include previously used parameters" do
|
||||||
|
@ -700,7 +858,12 @@ title: without parameters
|
||||||
|
|
||||||
{% include params.html %}
|
{% include params.html %}
|
||||||
CONTENT
|
CONTENT
|
||||||
create_post(content, {'permalink' => 'pretty', 'source' => source_dir, 'destination' => dest_dir, 'read_posts' => true})
|
create_post(content, {
|
||||||
|
"permalink" => "pretty",
|
||||||
|
"source" => source_dir,
|
||||||
|
"destination" => dest_dir,
|
||||||
|
"read_posts" => true
|
||||||
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
should "include file with empty parameters" do
|
should "include file with empty parameters" do
|
||||||
|
@ -717,7 +880,13 @@ title: custom includes directory
|
||||||
|
|
||||||
{% include custom.html %}
|
{% include custom.html %}
|
||||||
CONTENT
|
CONTENT
|
||||||
create_post(content, {'includes_dir' => '_includes_custom', 'permalink' => 'pretty', 'source' => source_dir, 'destination' => dest_dir, 'read_posts' => true})
|
create_post(content, {
|
||||||
|
"includes_dir" => "_includes_custom",
|
||||||
|
"permalink" => "pretty",
|
||||||
|
"source" => source_dir,
|
||||||
|
"destination" => dest_dir,
|
||||||
|
"read_posts" => true
|
||||||
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
should "include file from custom directory" do
|
should "include file from custom directory" do
|
||||||
|
@ -734,7 +903,12 @@ title: without parameters within if statement
|
||||||
|
|
||||||
{% if true %}{% include params.html %}{% endif %}
|
{% if true %}{% include params.html %}{% endif %}
|
||||||
CONTENT
|
CONTENT
|
||||||
create_post(content, {'permalink' => 'pretty', 'source' => source_dir, 'destination' => dest_dir, 'read_posts' => true})
|
create_post(content, {
|
||||||
|
"permalink" => "pretty",
|
||||||
|
"source" => source_dir,
|
||||||
|
"destination" => dest_dir,
|
||||||
|
"read_posts" => true
|
||||||
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
should "include file with empty parameters within if statement" do
|
should "include file with empty parameters within if statement" do
|
||||||
|
@ -755,72 +929,85 @@ CONTENT
|
||||||
|
|
||||||
should "raise error relative to source directory" do
|
should "raise error relative to source directory" do
|
||||||
exception = assert_raises IOError do
|
exception = assert_raises IOError do
|
||||||
create_post(@content, {'permalink' => 'pretty', 'source' => source_dir, 'destination' => dest_dir, 'read_posts' => true})
|
create_post(@content, {
|
||||||
|
"permalink" => "pretty",
|
||||||
|
"source" => source_dir,
|
||||||
|
"destination" => dest_dir,
|
||||||
|
"read_posts" => true
|
||||||
|
})
|
||||||
end
|
end
|
||||||
assert_match "Could not locate the included file 'missing.html' in any of [\"#{source_dir}/_includes\"].", exception.message
|
assert_match(
|
||||||
|
"Could not locate the included file 'missing.html' in any of " \
|
||||||
|
"[\"#{source_dir}/_includes\"].",
|
||||||
|
exception.message
|
||||||
|
)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context "include tag with variable and liquid filters" do
|
context "include tag with variable and liquid filters" do
|
||||||
setup do
|
setup do
|
||||||
site = fixture_site({'pygments' => true}).tap(&:read).tap(&:render)
|
site = fixture_site({ "pygments" => true }).tap(&:read).tap(&:render)
|
||||||
post = site.posts.docs.find {|p| p.basename.eql? "2013-12-17-include-variable-filters.markdown" }
|
post = site.posts.docs.find do |p|
|
||||||
|
p.basename.eql? "2013-12-17-include-variable-filters.markdown"
|
||||||
|
end
|
||||||
@content = post.output
|
@content = post.output
|
||||||
end
|
end
|
||||||
|
|
||||||
should "include file as variable with liquid filters" do
|
should "include file as variable with liquid filters" do
|
||||||
assert_match %r{1 included}, @content
|
assert_match(/1 included/, @content)
|
||||||
assert_match %r{2 included}, @content
|
assert_match(/2 included/, @content)
|
||||||
assert_match %r{3 included}, @content
|
assert_match(/3 included/, @content)
|
||||||
end
|
end
|
||||||
|
|
||||||
should "include file as variable and liquid filters with arbitrary whitespace" do
|
should "include file as variable and liquid filters with arbitrary whitespace" do
|
||||||
assert_match %r{4 included}, @content
|
assert_match(/4 included/, @content)
|
||||||
assert_match %r{5 included}, @content
|
assert_match(/5 included/, @content)
|
||||||
assert_match %r{6 included}, @content
|
assert_match(/6 included/, @content)
|
||||||
end
|
end
|
||||||
|
|
||||||
should "include file as variable and filters with additional parameters" do
|
should "include file as variable and filters with additional parameters" do
|
||||||
assert_match '<li>var1 = foo</li>', @content
|
assert_match("<li>var1 = foo</li>", @content)
|
||||||
assert_match '<li>var2 = bar</li>', @content
|
assert_match("<li>var2 = bar</li>", @content)
|
||||||
end
|
end
|
||||||
|
|
||||||
should "include file as partial variable" do
|
should "include file as partial variable" do
|
||||||
assert_match %r{8 included}, @content
|
assert_match(/8 included/, @content)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context "relative include tag with variable and liquid filters" do
|
context "relative include tag with variable and liquid filters" do
|
||||||
setup do
|
setup do
|
||||||
site = fixture_site({'pygments' => true}).tap(&:read).tap(&:render)
|
site = fixture_site({ "pygments" => true }).tap(&:read).tap(&:render)
|
||||||
post = site.posts.docs.find {|p| p.basename.eql? "2014-09-02-relative-includes.markdown" }
|
post = site.posts.docs.find do |p|
|
||||||
|
p.basename.eql? "2014-09-02-relative-includes.markdown"
|
||||||
|
end
|
||||||
@content = post.output
|
@content = post.output
|
||||||
end
|
end
|
||||||
|
|
||||||
should "include file as variable with liquid filters" do
|
should "include file as variable with liquid filters" do
|
||||||
assert_match %r{1 relative_include}, @content
|
assert_match(/1 relative_include/, @content)
|
||||||
assert_match %r{2 relative_include}, @content
|
assert_match(/2 relative_include/, @content)
|
||||||
assert_match %r{3 relative_include}, @content
|
assert_match(/3 relative_include/, @content)
|
||||||
end
|
end
|
||||||
|
|
||||||
should "include file as variable and liquid filters with arbitrary whitespace" do
|
should "include file as variable and liquid filters with arbitrary whitespace" do
|
||||||
assert_match %r{4 relative_include}, @content
|
assert_match(/4 relative_include/, @content)
|
||||||
assert_match %r{5 relative_include}, @content
|
assert_match(/5 relative_include/, @content)
|
||||||
assert_match %r{6 relative_include}, @content
|
assert_match(/6 relative_include/, @content)
|
||||||
end
|
end
|
||||||
|
|
||||||
should "include file as variable and filters with additional parameters" do
|
should "include file as variable and filters with additional parameters" do
|
||||||
assert_match '<li>var1 = foo</li>', @content
|
assert_match("<li>var1 = foo</li>", @content)
|
||||||
assert_match '<li>var2 = bar</li>', @content
|
assert_match("<li>var2 = bar</li>", @content)
|
||||||
end
|
end
|
||||||
|
|
||||||
should "include file as partial variable" do
|
should "include file as partial variable" do
|
||||||
assert_match %r{8 relative_include}, @content
|
assert_match(/8 relative_include/, @content)
|
||||||
end
|
end
|
||||||
|
|
||||||
should "include files relative to self" do
|
should "include files relative to self" do
|
||||||
assert_match %r{9 —\ntitle: Test Post Where YAML}, @content
|
assert_match(/9 —\ntitle: Test Post Where YAML/, @content)
|
||||||
end
|
end
|
||||||
|
|
||||||
context "trying to do bad stuff" do
|
context "trying to do bad stuff" do
|
||||||
|
@ -837,9 +1024,15 @@ CONTENT
|
||||||
|
|
||||||
should "raise error relative to source directory" do
|
should "raise error relative to source directory" do
|
||||||
exception = assert_raises IOError do
|
exception = assert_raises IOError do
|
||||||
create_post(@content, {'permalink' => 'pretty', 'source' => source_dir, 'destination' => dest_dir, 'read_posts' => true})
|
create_post(@content, {
|
||||||
|
"permalink" => "pretty",
|
||||||
|
"source" => source_dir,
|
||||||
|
"destination" => dest_dir,
|
||||||
|
"read_posts" => true
|
||||||
|
})
|
||||||
end
|
end
|
||||||
assert_match "Could not locate the included file 'missing.html' in any of [\"#{source_dir}\"].", exception.message
|
assert_match "Could not locate the included file 'missing.html' in any of " \
|
||||||
|
"[\"#{source_dir}\"].", exception.message
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -856,17 +1049,26 @@ CONTENT
|
||||||
|
|
||||||
should "raise error relative to source directory" do
|
should "raise error relative to source directory" do
|
||||||
exception = assert_raises ArgumentError do
|
exception = assert_raises ArgumentError do
|
||||||
create_post(@content, {'permalink' => 'pretty', 'source' => source_dir, 'destination' => dest_dir, 'read_posts' => true})
|
create_post(@content, {
|
||||||
|
"permalink" => "pretty",
|
||||||
|
"source" => source_dir,
|
||||||
|
"destination" => dest_dir,
|
||||||
|
"read_posts" => true
|
||||||
|
})
|
||||||
end
|
end
|
||||||
assert_equal "Invalid syntax for include tag. File contains invalid characters or sequences:\n\n ../README.markdown\n\nValid syntax:\n\n {% include_relative file.ext param='value' param2='value' %}\n\n", exception.message
|
assert_equal(
|
||||||
|
"Invalid syntax for include tag. File contains invalid characters or " \
|
||||||
|
"sequences:\n\n ../README.markdown\n\nValid syntax:\n\n " \
|
||||||
|
"{% include_relative file.ext param='value' param2='value' %}\n\n",
|
||||||
|
exception.message
|
||||||
|
)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context "with symlink'd include" do
|
context "with symlink'd include" do
|
||||||
|
|
||||||
should "not allow symlink includes" do
|
should "not allow symlink includes" do
|
||||||
File.open("tmp/pages-test", 'w') { |file| file.write("SYMLINK TEST") }
|
File.open("tmp/pages-test", "w") { |file| file.write("SYMLINK TEST") }
|
||||||
assert_raises IOError do
|
assert_raises IOError do
|
||||||
content = <<CONTENT
|
content = <<CONTENT
|
||||||
---
|
---
|
||||||
|
@ -876,9 +1078,15 @@ title: Include symlink
|
||||||
{% include_relative tmp/pages-test %}
|
{% include_relative tmp/pages-test %}
|
||||||
|
|
||||||
CONTENT
|
CONTENT
|
||||||
create_post(content, {'permalink' => 'pretty', 'source' => source_dir, 'destination' => dest_dir, 'read_posts' => true, 'safe' => true })
|
create_post(content, {
|
||||||
|
"permalink" => "pretty",
|
||||||
|
"source" => source_dir,
|
||||||
|
"destination" => dest_dir,
|
||||||
|
"read_posts" => true,
|
||||||
|
"safe" => true
|
||||||
|
})
|
||||||
end
|
end
|
||||||
@result ||= ''
|
@result ||= ""
|
||||||
refute_match(/SYMLINK TEST/, @result)
|
refute_match(/SYMLINK TEST/, @result)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -892,9 +1100,19 @@ title: Include symlink
|
||||||
{% include_relative tmp/pages-test-does-not-exist %}
|
{% include_relative tmp/pages-test-does-not-exist %}
|
||||||
|
|
||||||
CONTENT
|
CONTENT
|
||||||
create_post(content, {'permalink' => 'pretty', 'source' => source_dir, 'destination' => dest_dir, 'read_posts' => true, 'safe' => true })
|
create_post(content, {
|
||||||
|
"permalink" => "pretty",
|
||||||
|
"source" => source_dir,
|
||||||
|
"destination" => dest_dir,
|
||||||
|
"read_posts" => true,
|
||||||
|
"safe" => true
|
||||||
|
})
|
||||||
end
|
end
|
||||||
assert_match /Ensure it exists in one of those directories and, if it is a symlink, does not point outside your site source./, ex.message
|
assert_match(
|
||||||
|
"Ensure it exists in one of those directories and, if it is a symlink, does " \
|
||||||
|
"not point outside your site source.",
|
||||||
|
ex.message
|
||||||
|
)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
require 'helper'
|
require "helper"
|
||||||
|
|
||||||
class TestUtils < JekyllUnitTest
|
class TestUtils < JekyllUnitTest
|
||||||
context "The \`Utils.deep_merge_hashes\` method" do
|
context "The \`Utils.deep_merge_hashes\` method" do
|
||||||
|
@ -27,66 +27,64 @@ class TestUtils < JekyllUnitTest
|
||||||
end
|
end
|
||||||
|
|
||||||
context "hash" do
|
context "hash" do
|
||||||
|
|
||||||
context "pluralized_array" do
|
context "pluralized_array" do
|
||||||
|
|
||||||
should "return empty array with no values" do
|
should "return empty array with no values" do
|
||||||
data = {}
|
data = {}
|
||||||
assert_equal [], Utils.pluralized_array_from_hash(data, 'tag', 'tags')
|
assert_equal [], Utils.pluralized_array_from_hash(data, "tag", "tags")
|
||||||
end
|
end
|
||||||
|
|
||||||
should "return empty array with no matching values" do
|
should "return empty array with no matching values" do
|
||||||
data = { 'foo' => 'bar' }
|
data = { "foo" => "bar" }
|
||||||
assert_equal [], Utils.pluralized_array_from_hash(data, 'tag', 'tags')
|
assert_equal [], Utils.pluralized_array_from_hash(data, "tag", "tags")
|
||||||
end
|
end
|
||||||
|
|
||||||
should "return plural array with nil singular" do
|
should "return plural array with nil singular" do
|
||||||
data = { 'foo' => 'bar', 'tag' => nil, 'tags' => ['dog', 'cat'] }
|
data = { "foo" => "bar", "tag" => nil, "tags" => %w(dog cat) }
|
||||||
assert_equal ['dog', 'cat'], Utils.pluralized_array_from_hash(data, 'tag', 'tags')
|
assert_equal %w(dog cat), Utils.pluralized_array_from_hash(data, "tag", "tags")
|
||||||
end
|
end
|
||||||
|
|
||||||
should "return single value array with matching singular" do
|
should "return single value array with matching singular" do
|
||||||
data = { 'foo' => 'bar', 'tag' => 'dog', 'tags' => ['dog', 'cat'] }
|
data = { "foo" => "bar", "tag" => "dog", "tags" => %w(dog cat) }
|
||||||
assert_equal ['dog'], Utils.pluralized_array_from_hash(data, 'tag', 'tags')
|
assert_equal ["dog"], Utils.pluralized_array_from_hash(data, "tag", "tags")
|
||||||
end
|
end
|
||||||
|
|
||||||
should "return single value array with matching singular with spaces" do
|
should "return single value array with matching singular with spaces" do
|
||||||
data = { 'foo' => 'bar', 'tag' => 'dog cat', 'tags' => ['dog', 'cat'] }
|
data = { "foo" => "bar", "tag" => "dog cat", "tags" => %w(dog cat) }
|
||||||
assert_equal ['dog cat'], Utils.pluralized_array_from_hash(data, 'tag', 'tags')
|
assert_equal ["dog cat"], Utils.pluralized_array_from_hash(data, "tag", "tags")
|
||||||
end
|
end
|
||||||
|
|
||||||
should "return empty array with matching nil plural" do
|
should "return empty array with matching nil plural" do
|
||||||
data = { 'foo' => 'bar', 'tags' => nil }
|
data = { "foo" => "bar", "tags" => nil }
|
||||||
assert_equal [], Utils.pluralized_array_from_hash(data, 'tag', 'tags')
|
assert_equal [], Utils.pluralized_array_from_hash(data, "tag", "tags")
|
||||||
end
|
end
|
||||||
|
|
||||||
should "return empty array with matching empty array" do
|
should "return empty array with matching empty array" do
|
||||||
data = { 'foo' => 'bar', 'tags' => [] }
|
data = { "foo" => "bar", "tags" => [] }
|
||||||
assert_equal [], Utils.pluralized_array_from_hash(data, 'tag', 'tags')
|
assert_equal [], Utils.pluralized_array_from_hash(data, "tag", "tags")
|
||||||
end
|
end
|
||||||
|
|
||||||
should "return single value array with matching plural with single string value" do
|
should "return single value array with matching plural with single string value" do
|
||||||
data = { 'foo' => 'bar', 'tags' => 'dog' }
|
data = { "foo" => "bar", "tags" => "dog" }
|
||||||
assert_equal ['dog'], Utils.pluralized_array_from_hash(data, 'tag', 'tags')
|
assert_equal ["dog"], Utils.pluralized_array_from_hash(data, "tag", "tags")
|
||||||
end
|
end
|
||||||
|
|
||||||
should "return multiple value array with matching plural with single string value with spaces" do
|
should "return multiple value array with matching plural with " \
|
||||||
data = { 'foo' => 'bar', 'tags' => 'dog cat' }
|
"single string value with spaces" do
|
||||||
assert_equal ['dog', 'cat'], Utils.pluralized_array_from_hash(data, 'tag', 'tags')
|
data = { "foo" => "bar", "tags" => "dog cat" }
|
||||||
|
assert_equal %w(dog cat), Utils.pluralized_array_from_hash(data, "tag", "tags")
|
||||||
end
|
end
|
||||||
|
|
||||||
should "return single value array with matching plural with single value array" do
|
should "return single value array with matching plural with single value array" do
|
||||||
data = { 'foo' => 'bar', 'tags' => ['dog'] }
|
data = { "foo" => "bar", "tags" => ["dog"] }
|
||||||
assert_equal ['dog'], Utils.pluralized_array_from_hash(data, 'tag', 'tags')
|
assert_equal ["dog"], Utils.pluralized_array_from_hash(data, "tag", "tags")
|
||||||
end
|
end
|
||||||
|
|
||||||
should "return multiple value array with matching plural with multiple value array" do
|
should "return multiple value array with matching plural with " \
|
||||||
data = { 'foo' => 'bar', 'tags' => ['dog', 'cat'] }
|
"multiple value array" do
|
||||||
assert_equal ['dog', 'cat'], Utils.pluralized_array_from_hash(data, 'tag', 'tags')
|
data = { "foo" => "bar", "tags" => %w(dog cat) }
|
||||||
|
assert_equal %w(dog cat), Utils.pluralized_array_from_hash(data, "tag", "tags")
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
context "The \`Utils.parse_date\` method" do
|
context "The \`Utils.parse_date\` method" do
|
||||||
|
@ -108,7 +106,10 @@ class TestUtils < JekyllUnitTest
|
||||||
|
|
||||||
should "throw an error with the default message if no message is passed in" do
|
should "throw an error with the default message if no message is passed in" do
|
||||||
date = "Blah this is invalid"
|
date = "Blah this is invalid"
|
||||||
assert_raises Jekyll::Errors::InvalidDateError, "Invalid date '#{date}': Input could not be parsed." do
|
assert_raises(
|
||||||
|
Jekyll::Errors::InvalidDateError,
|
||||||
|
"Invalid date '#{date}': Input could not be parsed."
|
||||||
|
) do
|
||||||
Utils.parse_date(date)
|
Utils.parse_date(date)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -116,7 +117,10 @@ class TestUtils < JekyllUnitTest
|
||||||
should "throw an error with the provided message if a message is passed in" do
|
should "throw an error with the provided message if a message is passed in" do
|
||||||
date = "Blah this is invalid"
|
date = "Blah this is invalid"
|
||||||
message = "Aaaah, the world has exploded!"
|
message = "Aaaah, the world has exploded!"
|
||||||
assert_raises Jekyll::Errors::InvalidDateError, "Invalid date '#{date}': #{message}" do
|
assert_raises(
|
||||||
|
Jekyll::Errors::InvalidDateError,
|
||||||
|
"Invalid date '#{date}': #{message}"
|
||||||
|
) do
|
||||||
Utils.parse_date(date, message)
|
Utils.parse_date(date, message)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -144,7 +148,10 @@ class TestUtils < JekyllUnitTest
|
||||||
end
|
end
|
||||||
|
|
||||||
should "drop trailing punctuation" do
|
should "drop trailing punctuation" do
|
||||||
assert_equal "so-what-is-jekyll-exactly", Utils.slugify("So what is Jekyll, exactly?")
|
assert_equal(
|
||||||
|
"so-what-is-jekyll-exactly",
|
||||||
|
Utils.slugify("So what is Jekyll, exactly?")
|
||||||
|
)
|
||||||
assert_equal "كيف-حالك", Utils.slugify("كيف حالك؟")
|
assert_equal "كيف-حالك", Utils.slugify("كيف حالك؟")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -157,7 +164,10 @@ class TestUtils < JekyllUnitTest
|
||||||
end
|
end
|
||||||
|
|
||||||
should "combine adjacent hyphens and spaces" do
|
should "combine adjacent hyphens and spaces" do
|
||||||
assert_equal "customizing-git-git-hooks", Utils.slugify("Customizing Git - Git Hooks")
|
assert_equal(
|
||||||
|
"customizing-git-git-hooks",
|
||||||
|
Utils.slugify("Customizing Git - Git Hooks")
|
||||||
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
should "replace punctuation in any scripts by hyphens" do
|
should "replace punctuation in any scripts by hyphens" do
|
||||||
|
@ -171,7 +181,10 @@ class TestUtils < JekyllUnitTest
|
||||||
end
|
end
|
||||||
|
|
||||||
should "not change behaviour if mode is default" do
|
should "not change behaviour if mode is default" do
|
||||||
assert_equal "the-config-yml-file", Utils.slugify("The _config.yml file?", mode: "default")
|
assert_equal(
|
||||||
|
"the-config-yml-file",
|
||||||
|
Utils.slugify("The _config.yml file?", :mode => "default")
|
||||||
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
should "not change behaviour if mode is nil" do
|
should "not change behaviour if mode is nil" do
|
||||||
|
@ -179,53 +192,128 @@ class TestUtils < JekyllUnitTest
|
||||||
end
|
end
|
||||||
|
|
||||||
should "not replace period and underscore if mode is pretty" do
|
should "not replace period and underscore if mode is pretty" do
|
||||||
assert_equal "the-_config.yml-file", Utils.slugify("The _config.yml file?", mode: "pretty")
|
assert_equal(
|
||||||
|
"the-_config.yml-file",
|
||||||
|
Utils.slugify("The _config.yml file?", :mode => "pretty")
|
||||||
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
should "only replace whitespace if mode is raw" do
|
should "only replace whitespace if mode is raw" do
|
||||||
assert_equal "the-_config.yml-file?", Utils.slugify("The _config.yml file?", mode: "raw")
|
assert_equal(
|
||||||
|
"the-_config.yml-file?",
|
||||||
|
Utils.slugify("The _config.yml file?", :mode => "raw")
|
||||||
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
should "return the given string if mode is none" do
|
should "return the given string if mode is none" do
|
||||||
assert_equal "the _config.yml file?", Utils.slugify("The _config.yml file?", mode: "none")
|
assert_equal(
|
||||||
|
"the _config.yml file?",
|
||||||
|
Utils.slugify("The _config.yml file?", :mode => "none")
|
||||||
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
should "Keep all uppercase letters if cased is true" do
|
should "Keep all uppercase letters if cased is true" do
|
||||||
assert_equal "Working-with-drafts", Utils.slugify("Working with drafts", cased: true)
|
assert_equal(
|
||||||
assert_equal "Basic-Usage", Utils.slugify("Basic Usage", cased: true)
|
"Working-with-drafts",
|
||||||
assert_equal "Working-with-drafts", Utils.slugify(" Working with drafts ", cased: true)
|
Utils.slugify("Working with drafts", :cased => true)
|
||||||
assert_equal "So-what-is-Jekyll-exactly", Utils.slugify("So what is Jekyll, exactly?", cased: true)
|
)
|
||||||
assert_equal "Pre-releases", Utils.slugify("Pre-releases", cased: true)
|
assert_equal(
|
||||||
assert_equal "The-config-yml-file", Utils.slugify("The _config.yml file", cased: true)
|
"Basic-Usage",
|
||||||
assert_equal "Customizing-Git-Git-Hooks", Utils.slugify("Customizing Git - Git Hooks", cased: true)
|
Utils.slugify("Basic Usage", :cased => true)
|
||||||
assert_equal "The-config-yml-file", Utils.slugify("The _config.yml file?", mode: "default", cased: true)
|
)
|
||||||
assert_equal "The-config-yml-file", Utils.slugify("The _config.yml file?", cased: true)
|
assert_equal(
|
||||||
assert_equal "The-_config.yml-file", Utils.slugify("The _config.yml file?", mode: "pretty", cased: true)
|
"Working-with-drafts",
|
||||||
assert_equal "The-_config.yml-file?", Utils.slugify("The _config.yml file?", mode: "raw", cased: true)
|
Utils.slugify(" Working with drafts ", :cased => true)
|
||||||
assert_equal "The _config.yml file?", Utils.slugify("The _config.yml file?", mode: "none", cased: true)
|
)
|
||||||
|
assert_equal(
|
||||||
|
"So-what-is-Jekyll-exactly",
|
||||||
|
Utils.slugify("So what is Jekyll, exactly?", :cased => true)
|
||||||
|
)
|
||||||
|
assert_equal(
|
||||||
|
"Pre-releases",
|
||||||
|
Utils.slugify("Pre-releases", :cased => true)
|
||||||
|
)
|
||||||
|
assert_equal(
|
||||||
|
"The-config-yml-file",
|
||||||
|
Utils.slugify("The _config.yml file", :cased => true)
|
||||||
|
)
|
||||||
|
assert_equal(
|
||||||
|
"Customizing-Git-Git-Hooks",
|
||||||
|
Utils.slugify("Customizing Git - Git Hooks", :cased => true)
|
||||||
|
)
|
||||||
|
assert_equal(
|
||||||
|
"The-config-yml-file",
|
||||||
|
Utils.slugify("The _config.yml file?", :mode => "default", :cased => true)
|
||||||
|
)
|
||||||
|
assert_equal(
|
||||||
|
"The-config-yml-file",
|
||||||
|
Utils.slugify("The _config.yml file?", :cased => true)
|
||||||
|
)
|
||||||
|
assert_equal(
|
||||||
|
"The-_config.yml-file",
|
||||||
|
Utils.slugify("The _config.yml file?", :mode => "pretty", :cased => true)
|
||||||
|
)
|
||||||
|
assert_equal(
|
||||||
|
"The-_config.yml-file?",
|
||||||
|
Utils.slugify("The _config.yml file?", :mode => "raw", :cased => true)
|
||||||
|
)
|
||||||
|
assert_equal(
|
||||||
|
"The _config.yml file?",
|
||||||
|
Utils.slugify("The _config.yml file?", :mode => "none", :cased => true)
|
||||||
|
)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context "The \`Utils.titleize_slug\` method" do
|
context "The \`Utils.titleize_slug\` method" do
|
||||||
should "capitalize all words and not drop any words" do
|
should "capitalize all words and not drop any words" do
|
||||||
assert_equal "This Is A Long Title With Mixed Capitalization", Utils.titleize_slug("This-is-a-Long-title-with-Mixed-capitalization")
|
assert_equal(
|
||||||
assert_equal "This Is A Title With Just The Initial Word Capitalized", Utils.titleize_slug("This-is-a-title-with-just-the-initial-word-capitalized")
|
"This Is A Long Title With Mixed Capitalization",
|
||||||
assert_equal "This Is A Title With No Capitalization", Utils.titleize_slug("this-is-a-title-with-no-capitalization")
|
Utils.titleize_slug("This-is-a-Long-title-with-Mixed-capitalization")
|
||||||
|
)
|
||||||
|
assert_equal(
|
||||||
|
"This Is A Title With Just The Initial Word Capitalized",
|
||||||
|
Utils.titleize_slug("This-is-a-title-with-just-the-initial-word-capitalized")
|
||||||
|
)
|
||||||
|
assert_equal(
|
||||||
|
"This Is A Title With No Capitalization",
|
||||||
|
Utils.titleize_slug("this-is-a-title-with-no-capitalization")
|
||||||
|
)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context "The \`Utils.add_permalink_suffix\` method" do
|
context "The \`Utils.add_permalink_suffix\` method" do
|
||||||
should "handle built-in permalink styles" do
|
should "handle built-in permalink styles" do
|
||||||
assert_equal "/:basename/", Utils.add_permalink_suffix("/:basename", :pretty)
|
assert_equal(
|
||||||
assert_equal "/:basename:output_ext", Utils.add_permalink_suffix("/:basename", :date)
|
"/:basename/",
|
||||||
assert_equal "/:basename:output_ext", Utils.add_permalink_suffix("/:basename", :ordinal)
|
Utils.add_permalink_suffix("/:basename", :pretty)
|
||||||
assert_equal "/:basename:output_ext", Utils.add_permalink_suffix("/:basename", :none)
|
)
|
||||||
|
assert_equal(
|
||||||
|
"/:basename:output_ext",
|
||||||
|
Utils.add_permalink_suffix("/:basename", :date)
|
||||||
|
)
|
||||||
|
assert_equal(
|
||||||
|
"/:basename:output_ext",
|
||||||
|
Utils.add_permalink_suffix("/:basename", :ordinal)
|
||||||
|
)
|
||||||
|
assert_equal(
|
||||||
|
"/:basename:output_ext",
|
||||||
|
Utils.add_permalink_suffix("/:basename", :none)
|
||||||
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
should "handle custom permalink styles" do
|
should "handle custom permalink styles" do
|
||||||
assert_equal "/:basename/", Utils.add_permalink_suffix("/:basename", "/:title/")
|
assert_equal(
|
||||||
assert_equal "/:basename:output_ext", Utils.add_permalink_suffix("/:basename", "/:title:output_ext")
|
"/:basename/",
|
||||||
assert_equal "/:basename", Utils.add_permalink_suffix("/:basename", "/:title")
|
Utils.add_permalink_suffix("/:basename", "/:title/")
|
||||||
|
)
|
||||||
|
assert_equal(
|
||||||
|
"/:basename:output_ext",
|
||||||
|
Utils.add_permalink_suffix("/:basename", "/:title:output_ext")
|
||||||
|
)
|
||||||
|
assert_equal(
|
||||||
|
"/:basename",
|
||||||
|
Utils.add_permalink_suffix("/:basename", "/:title")
|
||||||
|
)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -270,17 +358,17 @@ class TestUtils < JekyllUnitTest
|
||||||
context "The \`Utils.has_yaml_header?\` method" do
|
context "The \`Utils.has_yaml_header?\` method" do
|
||||||
should "accept files with yaml front matter" do
|
should "accept files with yaml front matter" do
|
||||||
file = source_dir("_posts", "2008-10-18-foo-bar.markdown")
|
file = source_dir("_posts", "2008-10-18-foo-bar.markdown")
|
||||||
assert_equal "---\n", File.open(file, 'rb') { |f| f.read(4) }
|
assert_equal "---\n", File.open(file, "rb") { |f| f.read(4) }
|
||||||
assert Utils.has_yaml_header?(file)
|
assert Utils.has_yaml_header?(file)
|
||||||
end
|
end
|
||||||
should "accept files with extraneous spaces after yaml front matter" do
|
should "accept files with extraneous spaces after yaml front matter" do
|
||||||
file = source_dir("_posts", "2015-12-27-extra-spaces.markdown")
|
file = source_dir("_posts", "2015-12-27-extra-spaces.markdown")
|
||||||
assert_equal "--- \n", File.open(file, 'rb') { |f| f.read(6) }
|
assert_equal "--- \n", File.open(file, "rb") { |f| f.read(6) }
|
||||||
assert Utils.has_yaml_header?(file)
|
assert Utils.has_yaml_header?(file)
|
||||||
end
|
end
|
||||||
should "reject pgp files and the like which resemble front matter" do
|
should "reject pgp files and the like which resemble front matter" do
|
||||||
file = source_dir("pgp.key")
|
file = source_dir("pgp.key")
|
||||||
assert_equal "-----B", File.open(file, 'rb') { |f| f.read(6) }
|
assert_equal "-----B", File.open(file, "rb") { |f| f.read(6) }
|
||||||
refute Utils.has_yaml_header?(file)
|
refute Utils.has_yaml_header?(file)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue