nanoc 4.8.12 → 4.8.13
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/NEWS.md +6 -0
- data/lib/nanoc/base/entities/document.rb +16 -1
- data/lib/nanoc/base/feature.rb +1 -1
- data/lib/nanoc/base/repos/action_sequence_store.rb +3 -3
- data/lib/nanoc/base/repos/checksum_store.rb +3 -3
- data/lib/nanoc/base/repos/compiled_content_cache.rb +3 -3
- data/lib/nanoc/base/repos/dependency_store.rb +3 -3
- data/lib/nanoc/base/repos/outdatedness_store.rb +3 -3
- data/lib/nanoc/base/repos/store.rb +3 -5
- data/lib/nanoc/base/services/compiler_loader.rb +5 -5
- data/lib/nanoc/base/views/mixins/mutable_document_view_mixin.rb +2 -14
- data/lib/nanoc/cli/commands/compile.rb +18 -0
- data/lib/nanoc/cli/commands/live.rb +1 -0
- data/lib/nanoc/cli/commands/view.rb +12 -35
- data/lib/nanoc/filters/redcarpet.rb +26 -65
- data/lib/nanoc/version.rb +1 -1
- metadata +2 -293
- data/.rspec +0 -3
- data/.rubocop.yml +0 -173
- data/Rakefile +0 -25
- data/nanoc.gemspec +0 -44
- data/nanoc.manifest +0 -543
- data/spec/contributors_spec.rb +0 -20
- data/spec/gem_spec.rb +0 -21
- data/spec/manifest_spec.rb +0 -22
- data/spec/nanoc/base/changes_stream_spec.rb +0 -45
- data/spec/nanoc/base/checksummer_spec.rb +0 -419
- data/spec/nanoc/base/compiler_spec.rb +0 -149
- data/spec/nanoc/base/core_ext/array_spec.rb +0 -35
- data/spec/nanoc/base/core_ext/hash_spec.rb +0 -41
- data/spec/nanoc/base/core_ext/string_spec.rb +0 -23
- data/spec/nanoc/base/directed_graph_spec.rb +0 -258
- data/spec/nanoc/base/entities/action_sequence_spec.rb +0 -297
- data/spec/nanoc/base/entities/code_snippet_spec.rb +0 -60
- data/spec/nanoc/base/entities/configuration_spec.rb +0 -132
- data/spec/nanoc/base/entities/content_spec.rb +0 -195
- data/spec/nanoc/base/entities/context_spec.rb +0 -26
- data/spec/nanoc/base/entities/document_spec.rb +0 -258
- data/spec/nanoc/base/entities/identifiable_collection_spec.rb +0 -209
- data/spec/nanoc/base/entities/identifier_spec.rb +0 -472
- data/spec/nanoc/base/entities/item_rep_spec.rb +0 -26
- data/spec/nanoc/base/entities/item_spec.rb +0 -13
- data/spec/nanoc/base/entities/layout_spec.rb +0 -13
- data/spec/nanoc/base/entities/lazy_value_spec.rb +0 -108
- data/spec/nanoc/base/entities/outdatedness_status_spec.rb +0 -115
- data/spec/nanoc/base/entities/pattern_spec.rb +0 -133
- data/spec/nanoc/base/entities/processing_action_spec.rb +0 -11
- data/spec/nanoc/base/entities/processing_actions/filter_spec.rb +0 -20
- data/spec/nanoc/base/entities/processing_actions/layout_spec.rb +0 -20
- data/spec/nanoc/base/entities/processing_actions/snapshot_spec.rb +0 -40
- data/spec/nanoc/base/entities/props_spec.rb +0 -413
- data/spec/nanoc/base/entities/site_spec.rb +0 -80
- data/spec/nanoc/base/errors/dependency_cycle_spec.rb +0 -35
- data/spec/nanoc/base/feature_spec.rb +0 -109
- data/spec/nanoc/base/filter_spec.rb +0 -166
- data/spec/nanoc/base/item_rep_writer_spec.rb +0 -140
- data/spec/nanoc/base/memoization_spec.rb +0 -108
- data/spec/nanoc/base/repos/aggregate_data_source_spec.rb +0 -87
- data/spec/nanoc/base/repos/checksum_store_spec.rb +0 -155
- data/spec/nanoc/base/repos/compiled_content_cache_spec.rb +0 -65
- data/spec/nanoc/base/repos/config_loader_spec.rb +0 -245
- data/spec/nanoc/base/repos/data_source_spec.rb +0 -95
- data/spec/nanoc/base/repos/dependency_store_spec.rb +0 -515
- data/spec/nanoc/base/repos/in_mem_data_source_spec.rb +0 -39
- data/spec/nanoc/base/repos/outdatedness_store_spec.rb +0 -72
- data/spec/nanoc/base/repos/prefixed_data_source_spec.rb +0 -39
- data/spec/nanoc/base/repos/site_loader_spec.rb +0 -264
- data/spec/nanoc/base/repos/snapshot_repo_spec.rb +0 -316
- data/spec/nanoc/base/repos/store_spec.rb +0 -93
- data/spec/nanoc/base/services/compiler/phases/abstract_spec.rb +0 -63
- data/spec/nanoc/base/services/compiler/phases/cache_spec.rb +0 -156
- data/spec/nanoc/base/services/compiler/stages/calculate_checksums_spec.rb +0 -74
- data/spec/nanoc/base/services/compiler/stages/cleanup_spec.rb +0 -88
- data/spec/nanoc/base/services/compiler/stages/compile_reps_spec.rb +0 -142
- data/spec/nanoc/base/services/compiler/stages/determine_outdatedness_spec.rb +0 -148
- data/spec/nanoc/base/services/compiler/stages/preprocess_spec.rb +0 -110
- data/spec/nanoc/base/services/dependency_tracker_spec.rb +0 -245
- data/spec/nanoc/base/services/executor_spec.rb +0 -686
- data/spec/nanoc/base/services/item_rep_router_spec.rb +0 -198
- data/spec/nanoc/base/services/item_rep_selector_spec.rb +0 -227
- data/spec/nanoc/base/services/notification_center_spec.rb +0 -25
- data/spec/nanoc/base/services/outdatedness_checker_spec.rb +0 -778
- data/spec/nanoc/base/services/outdatedness_rules_spec.rb +0 -495
- data/spec/nanoc/base/services/pruner_spec.rb +0 -116
- data/spec/nanoc/base/services/temp_filename_factory_spec.rb +0 -89
- data/spec/nanoc/base/views/basic_item_rep_collection_view_spec.rb +0 -8
- data/spec/nanoc/base/views/basic_item_rep_view_spec.rb +0 -9
- data/spec/nanoc/base/views/compilation_item_rep_collection_view_spec.rb +0 -8
- data/spec/nanoc/base/views/compilation_item_rep_view_spec.rb +0 -136
- data/spec/nanoc/base/views/config_view_spec.rb +0 -144
- data/spec/nanoc/base/views/item_collection_with_reps_view_spec.rb +0 -23
- data/spec/nanoc/base/views/item_collection_without_reps_view_spec.rb +0 -23
- data/spec/nanoc/base/views/item_view_spec.rb +0 -376
- data/spec/nanoc/base/views/layout_collection_view_spec.rb +0 -23
- data/spec/nanoc/base/views/layout_view_spec.rb +0 -18
- data/spec/nanoc/base/views/mutable_config_view_spec.rb +0 -18
- data/spec/nanoc/base/views/mutable_item_collection_view_spec.rb +0 -60
- data/spec/nanoc/base/views/mutable_item_view_spec.rb +0 -26
- data/spec/nanoc/base/views/mutable_layout_collection_view_spec.rb +0 -60
- data/spec/nanoc/base/views/mutable_layout_view_spec.rb +0 -17
- data/spec/nanoc/base/views/post_compile_item_rep_collection_view_spec.rb +0 -8
- data/spec/nanoc/base/views/post_compile_item_rep_view_spec.rb +0 -216
- data/spec/nanoc/base/views/post_compile_item_view_spec.rb +0 -58
- data/spec/nanoc/base/views/support/document_view_examples.rb +0 -340
- data/spec/nanoc/base/views/support/identifiable_collection_view_examples.rb +0 -277
- data/spec/nanoc/base/views/support/item_rep_collection_view_examples.rb +0 -140
- data/spec/nanoc/base/views/support/item_rep_view_examples.rb +0 -308
- data/spec/nanoc/base/views/support/mutable_document_view_examples.rb +0 -188
- data/spec/nanoc/base/views/support/mutable_identifiable_collection_view_examples.rb +0 -44
- data/spec/nanoc/checking/runner_spec.rb +0 -26
- data/spec/nanoc/cli/command_runner_spec.rb +0 -107
- data/spec/nanoc/cli/commands/compile/abstract_spec.rb +0 -80
- data/spec/nanoc/cli/commands/compile/diff_generator_spec.rb +0 -44
- data/spec/nanoc/cli/commands/compile/file_action_printer_spec.rb +0 -112
- data/spec/nanoc/cli/commands/compile/timing_recorder_spec.rb +0 -287
- data/spec/nanoc/cli/commands/compile_spec.rb +0 -45
- data/spec/nanoc/cli/commands/deploy_spec.rb +0 -329
- data/spec/nanoc/cli/commands/shell_spec.rb +0 -77
- data/spec/nanoc/cli/commands/show_data_spec.rb +0 -286
- data/spec/nanoc/cli/commands/show_plugins_spec.rb +0 -20
- data/spec/nanoc/cli/commands/show_rules_spec.rb +0 -118
- data/spec/nanoc/cli/commands/view_spec.rb +0 -75
- data/spec/nanoc/cli/error_handler_spec.rb +0 -43
- data/spec/nanoc/cli/stack_trace_writer_spec.rb +0 -156
- data/spec/nanoc/cli/stream_cleaners/utf8_spec.rb +0 -9
- data/spec/nanoc/cli_spec.rb +0 -44
- data/spec/nanoc/data_sources/filesystem_spec.rb +0 -128
- data/spec/nanoc/deploying/fog_spec.rb +0 -199
- data/spec/nanoc/deploying/git_spec.rb +0 -305
- data/spec/nanoc/extra/live_recompiler_spec.rb +0 -129
- data/spec/nanoc/extra/parallel_collection_spec.rb +0 -110
- data/spec/nanoc/filters/asciidoctor_spec.rb +0 -12
- data/spec/nanoc/filters/colorize_syntax/rouge_spec.rb +0 -155
- data/spec/nanoc/filters/less_spec.rb +0 -122
- data/spec/nanoc/helpers/blogging_spec.rb +0 -219
- data/spec/nanoc/helpers/breadcrumbs_spec.rb +0 -135
- data/spec/nanoc/helpers/capturing_spec.rb +0 -256
- data/spec/nanoc/helpers/child_parent_spec.rb +0 -76
- data/spec/nanoc/helpers/filtering_spec.rb +0 -77
- data/spec/nanoc/helpers/html_escape_spec.rb +0 -37
- data/spec/nanoc/helpers/link_to_spec.rb +0 -320
- data/spec/nanoc/helpers/rendering_spec.rb +0 -144
- data/spec/nanoc/helpers/tagging_spec.rb +0 -106
- data/spec/nanoc/helpers/text_spec.rb +0 -60
- data/spec/nanoc/integration/compile_command_spec.rb +0 -33
- data/spec/nanoc/integration/outdatedness_integration_spec.rb +0 -269
- data/spec/nanoc/integration/partial_recompilation_spec.rb +0 -50
- data/spec/nanoc/regressions/gh_1015_spec.rb +0 -19
- data/spec/nanoc/regressions/gh_1022_spec.rb +0 -26
- data/spec/nanoc/regressions/gh_1031_spec.rb +0 -56
- data/spec/nanoc/regressions/gh_1035_spec.rb +0 -35
- data/spec/nanoc/regressions/gh_1037a_spec.rb +0 -31
- data/spec/nanoc/regressions/gh_1037b_spec.rb +0 -20
- data/spec/nanoc/regressions/gh_1040_spec.rb +0 -24
- data/spec/nanoc/regressions/gh_1045_spec.rb +0 -50
- data/spec/nanoc/regressions/gh_1047_spec.rb +0 -30
- data/spec/nanoc/regressions/gh_1064_spec.rb +0 -20
- data/spec/nanoc/regressions/gh_1067_spec.rb +0 -36
- data/spec/nanoc/regressions/gh_1082a_spec.rb +0 -20
- data/spec/nanoc/regressions/gh_1082b_spec.rb +0 -22
- data/spec/nanoc/regressions/gh_1082c_spec.rb +0 -21
- data/spec/nanoc/regressions/gh_1082d_spec.rb +0 -19
- data/spec/nanoc/regressions/gh_1093_spec.rb +0 -51
- data/spec/nanoc/regressions/gh_1094_spec.rb +0 -24
- data/spec/nanoc/regressions/gh_1097_spec.rb +0 -23
- data/spec/nanoc/regressions/gh_1100_spec.rb +0 -22
- data/spec/nanoc/regressions/gh_1102_spec.rb +0 -28
- data/spec/nanoc/regressions/gh_1107_spec.rb +0 -15
- data/spec/nanoc/regressions/gh_1130_spec.rb +0 -21
- data/spec/nanoc/regressions/gh_1134_spec.rb +0 -29
- data/spec/nanoc/regressions/gh_1145_spec.rb +0 -18
- data/spec/nanoc/regressions/gh_1171_spec.rb +0 -57
- data/spec/nanoc/regressions/gh_1185_spec.rb +0 -22
- data/spec/nanoc/regressions/gh_1216_spec.rb +0 -91
- data/spec/nanoc/regressions/gh_1248_spec.rb +0 -24
- data/spec/nanoc/regressions/gh_761_spec.rb +0 -25
- data/spec/nanoc/regressions/gh_767_spec.rb +0 -21
- data/spec/nanoc/regressions/gh_769_spec.rb +0 -32
- data/spec/nanoc/regressions/gh_776_spec.rb +0 -42
- data/spec/nanoc/regressions/gh_787_spec.rb +0 -21
- data/spec/nanoc/regressions/gh_795_spec.rb +0 -21
- data/spec/nanoc/regressions/gh_804_spec.rb +0 -28
- data/spec/nanoc/regressions/gh_807_spec.rb +0 -19
- data/spec/nanoc/regressions/gh_809_spec.rb +0 -19
- data/spec/nanoc/regressions/gh_813_spec.rb +0 -24
- data/spec/nanoc/regressions/gh_815_spec.rb +0 -20
- data/spec/nanoc/regressions/gh_828_spec.rb +0 -25
- data/spec/nanoc/regressions/gh_833_spec.rb +0 -16
- data/spec/nanoc/regressions/gh_841_spec.rb +0 -17
- data/spec/nanoc/regressions/gh_867_spec.rb +0 -17
- data/spec/nanoc/regressions/gh_882_spec.rb +0 -31
- data/spec/nanoc/regressions/gh_885_spec.rb +0 -32
- data/spec/nanoc/regressions/gh_891_spec.rb +0 -28
- data/spec/nanoc/regressions/gh_913_spec.rb +0 -26
- data/spec/nanoc/regressions/gh_924_spec.rb +0 -91
- data/spec/nanoc/regressions/gh_928_spec.rb +0 -7
- data/spec/nanoc/regressions/gh_937_spec.rb +0 -27
- data/spec/nanoc/regressions/gh_942_spec.rb +0 -23
- data/spec/nanoc/regressions/gh_947_spec.rb +0 -23
- data/spec/nanoc/regressions/gh_948_spec.rb +0 -18
- data/spec/nanoc/regressions/gh_951_spec.rb +0 -21
- data/spec/nanoc/regressions/gh_954_spec.rb +0 -35
- data/spec/nanoc/regressions/gh_970a_spec.rb +0 -19
- data/spec/nanoc/regressions/gh_970b_spec.rb +0 -52
- data/spec/nanoc/regressions/gh_974_spec.rb +0 -19
- data/spec/nanoc/regressions/gh_981_spec.rb +0 -23
- data/spec/nanoc/rule_dsl/action_sequence_calculator_spec.rb +0 -230
- data/spec/nanoc/rule_dsl/recording_executor_spec.rb +0 -145
- data/spec/nanoc/rule_dsl/rule_context_spec.rb +0 -251
- data/spec/nanoc/rule_dsl/rule_spec.rb +0 -111
- data/spec/nanoc/rule_dsl/rules_collection_spec.rb +0 -301
- data/spec/nanoc/spec_spec.rb +0 -70
- data/spec/nanoc/telemetry/counter_spec.rb +0 -20
- data/spec/nanoc/telemetry/labelled_counter_spec.rb +0 -94
- data/spec/nanoc/telemetry/labelled_summary_spec.rb +0 -78
- data/spec/nanoc/telemetry/stopwatch_spec.rb +0 -63
- data/spec/nanoc/telemetry/summary_spec.rb +0 -68
- data/spec/nanoc/telemetry/table_spec.rb +0 -22
- data/spec/nanoc/telemetry_spec.rb +0 -28
- data/spec/regression_filenames_spec.rb +0 -18
- data/spec/spec_helper.rb +0 -371
- data/test/base/test_compiler.rb +0 -389
- data/test/base/test_filter.rb +0 -73
- data/test/base/test_site.rb +0 -146
- data/test/checking/checks/test_css.rb +0 -66
- data/test/checking/checks/test_external_links.rb +0 -88
- data/test/checking/checks/test_html.rb +0 -47
- data/test/checking/checks/test_internal_links.rb +0 -118
- data/test/checking/checks/test_mixed_content.rb +0 -190
- data/test/checking/checks/test_stale.rb +0 -69
- data/test/checking/test_check.rb +0 -22
- data/test/checking/test_dsl.rb +0 -35
- data/test/checking/test_runner.rb +0 -45
- data/test/cli/commands/test_check.rb +0 -20
- data/test/cli/commands/test_compile.rb +0 -199
- data/test/cli/commands/test_create_site.rb +0 -126
- data/test/cli/commands/test_help.rb +0 -10
- data/test/cli/commands/test_prune.rb +0 -157
- data/test/cli/test_cleaning_stream.rb +0 -97
- data/test/cli/test_cli.rb +0 -195
- data/test/cli/test_error_handler.rb +0 -102
- data/test/cli/test_logger.rb +0 -7
- data/test/data_sources/test_filesystem.rb +0 -1033
- data/test/data_sources/test_filesystem_tools.rb +0 -146
- data/test/deploying/test_fog.rb +0 -117
- data/test/deploying/test_git.rb +0 -263
- data/test/deploying/test_rsync.rb +0 -94
- data/test/extra/core_ext/test_time.rb +0 -17
- data/test/extra/test_link_collector.rb +0 -110
- data/test/extra/test_piper.rb +0 -48
- data/test/filters/colorize_syntax/test_coderay.rb +0 -247
- data/test/filters/colorize_syntax/test_common.rb +0 -109
- data/test/filters/colorize_syntax/test_pygmentize.rb +0 -39
- data/test/filters/colorize_syntax/test_pygments.rb +0 -21
- data/test/filters/colorize_syntax/test_simon.rb +0 -24
- data/test/filters/test_asciidoc.rb +0 -16
- data/test/filters/test_bluecloth.rb +0 -16
- data/test/filters/test_coffeescript.rb +0 -16
- data/test/filters/test_erb.rb +0 -107
- data/test/filters/test_erubi.rb +0 -75
- data/test/filters/test_erubis.rb +0 -76
- data/test/filters/test_haml.rb +0 -94
- data/test/filters/test_handlebars.rb +0 -61
- data/test/filters/test_kramdown.rb +0 -56
- data/test/filters/test_markaby.rb +0 -16
- data/test/filters/test_maruku.rb +0 -16
- data/test/filters/test_mustache.rb +0 -43
- data/test/filters/test_pandoc.rb +0 -47
- data/test/filters/test_rainpress.rb +0 -27
- data/test/filters/test_rdiscount.rb +0 -30
- data/test/filters/test_rdoc.rb +0 -14
- data/test/filters/test_redcarpet.rb +0 -111
- data/test/filters/test_redcloth.rb +0 -31
- data/test/filters/test_relativize_paths.rb +0 -887
- data/test/filters/test_rubypants.rb +0 -16
- data/test/filters/test_sass.rb +0 -315
- data/test/filters/test_slim.rb +0 -59
- data/test/filters/test_typogruby.rb +0 -18
- data/test/filters/test_uglify_js.rb +0 -30
- data/test/filters/test_xsl.rb +0 -192
- data/test/filters/test_yui_compressor.rb +0 -42
- data/test/fixtures/vcr_cassettes/css_run_error.yml +0 -70
- data/test/fixtures/vcr_cassettes/css_run_ok.yml +0 -60
- data/test/fixtures/vcr_cassettes/css_run_parse_error.yml +0 -70
- data/test/fixtures/vcr_cassettes/html_run_error.yml +0 -56
- data/test/fixtures/vcr_cassettes/html_run_ok.yml +0 -58
- data/test/helper.rb +0 -255
- data/test/helpers/test_blogging.rb +0 -684
- data/test/helpers/test_capturing.rb +0 -184
- data/test/helpers/test_link_to.rb +0 -57
- data/test/helpers/test_xml_sitemap.rb +0 -246
- data/test/rule_dsl/test_action_provider.rb +0 -80
- data/test/rule_dsl/test_compiler_dsl.rb +0 -448
- data/test/rule_dsl/test_rules_collection.rb +0 -93
@@ -1,102 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'helper'
|
4
|
-
|
5
|
-
class Nanoc::CLI::ErrorHandlerTest < Nanoc::TestCase
|
6
|
-
def setup
|
7
|
-
super
|
8
|
-
@handler = Nanoc::CLI::ErrorHandler.new
|
9
|
-
end
|
10
|
-
|
11
|
-
def test_resolution_for_with_unknown_gem
|
12
|
-
error = LoadError.new('no such file to load -- afjlrestjlsgrshter')
|
13
|
-
assert_nil @handler.send(:resolution_for, error)
|
14
|
-
end
|
15
|
-
|
16
|
-
def test_resolution_for_with_known_gem_without_bundler
|
17
|
-
def @handler.using_bundler?
|
18
|
-
false
|
19
|
-
end
|
20
|
-
error = LoadError.new('no such file to load -- kramdown')
|
21
|
-
assert_match(/^Install the 'kramdown' gem using `gem install kramdown`./, @handler.send(:resolution_for, error))
|
22
|
-
end
|
23
|
-
|
24
|
-
def test_resolution_for_with_known_gem_with_bundler
|
25
|
-
def @handler.using_bundler?
|
26
|
-
true
|
27
|
-
end
|
28
|
-
error = LoadError.new('no such file to load -- kramdown')
|
29
|
-
assert_match(/^Make sure the gem is added to Gemfile/, @handler.send(:resolution_for, error))
|
30
|
-
end
|
31
|
-
|
32
|
-
def test_resolution_for_with_not_load_error
|
33
|
-
error = RuntimeError.new('nuclear meltdown detected')
|
34
|
-
assert_nil @handler.send(:resolution_for, error)
|
35
|
-
end
|
36
|
-
|
37
|
-
def test_write_stack_trace_verbose
|
38
|
-
error = new_error(20)
|
39
|
-
|
40
|
-
stream = StringIO.new
|
41
|
-
@handler.send(:write_stack_trace, stream, error, verbose: false)
|
42
|
-
assert_match(/ lines omitted \(see crash\.log for details\)/, stream.string)
|
43
|
-
|
44
|
-
stream = StringIO.new
|
45
|
-
@handler.send(:write_stack_trace, stream, error, verbose: false)
|
46
|
-
assert_match(/ lines omitted \(see crash\.log for details\)/, stream.string)
|
47
|
-
|
48
|
-
stream = StringIO.new
|
49
|
-
@handler.send(:write_stack_trace, stream, error, verbose: true)
|
50
|
-
refute_match(/ lines omitted \(see crash\.log for details\)/, stream.string)
|
51
|
-
end
|
52
|
-
|
53
|
-
def test_write_error_message_wrapped
|
54
|
-
stream = StringIO.new
|
55
|
-
@handler.send(:write_error_message, stream, new_wrapped_error(new_error), verbose: true)
|
56
|
-
refute_match(/CompilationError/, stream.string)
|
57
|
-
end
|
58
|
-
|
59
|
-
def test_write_stack_trace_wrapped
|
60
|
-
stream = StringIO.new
|
61
|
-
@handler.send(:write_stack_trace, stream, new_wrapped_error(new_error), verbose: false)
|
62
|
-
assert_match(/new_error/, stream.string)
|
63
|
-
end
|
64
|
-
|
65
|
-
def test_write_item_rep
|
66
|
-
stream = StringIO.new
|
67
|
-
@handler.send(:write_item_rep, stream, new_wrapped_error(new_error), verbose: false)
|
68
|
-
assert_match(/^Current item: \/about\.md \(:latex representation\)$/, stream.string)
|
69
|
-
end
|
70
|
-
|
71
|
-
def test_resolution_for_wrapped
|
72
|
-
def @handler.using_bundler?
|
73
|
-
true
|
74
|
-
end
|
75
|
-
error = new_wrapped_error(LoadError.new('no such file to load -- kramdown'))
|
76
|
-
assert_match(/^Make sure the gem is added to Gemfile/, @handler.send(:resolution_for, error))
|
77
|
-
end
|
78
|
-
|
79
|
-
def new_wrapped_error(wrapped)
|
80
|
-
item = Nanoc::Int::Item.new('asdf', {}, '/about.md')
|
81
|
-
item_rep = Nanoc::Int::ItemRep.new(item, :latex)
|
82
|
-
raise Nanoc::Int::Errors::CompilationError.new(wrapped, item_rep)
|
83
|
-
rescue => e
|
84
|
-
return e
|
85
|
-
end
|
86
|
-
|
87
|
-
def new_error(amount_factor = 1)
|
88
|
-
backtrace_generator = lambda do |af|
|
89
|
-
if af.zero?
|
90
|
-
raise 'finally!'
|
91
|
-
else
|
92
|
-
backtrace_generator.call(af - 1)
|
93
|
-
end
|
94
|
-
end
|
95
|
-
|
96
|
-
begin
|
97
|
-
backtrace_generator.call(amount_factor)
|
98
|
-
rescue => e
|
99
|
-
return e
|
100
|
-
end
|
101
|
-
end
|
102
|
-
end
|
data/test/cli/test_logger.rb
DELETED
@@ -1,1033 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'helper'
|
4
|
-
|
5
|
-
class Nanoc::DataSources::FilesystemTest < Nanoc::TestCase
|
6
|
-
def new_data_source(params = nil)
|
7
|
-
# Mock site
|
8
|
-
site = Nanoc::Int::SiteLoader.new.new_empty
|
9
|
-
|
10
|
-
# Create data source
|
11
|
-
data_source = Nanoc::DataSources::Filesystem.new(site.config, nil, nil, params)
|
12
|
-
|
13
|
-
# Done
|
14
|
-
data_source
|
15
|
-
end
|
16
|
-
|
17
|
-
def test_load_objects
|
18
|
-
# Create data source
|
19
|
-
data_source = new_data_source
|
20
|
-
|
21
|
-
# Create a fake class
|
22
|
-
klass = Class.new do
|
23
|
-
attr_reader :stuff
|
24
|
-
def initialize(*stuff)
|
25
|
-
@stuff = stuff
|
26
|
-
end
|
27
|
-
|
28
|
-
def ==(other)
|
29
|
-
@stuff == other.stuff
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
# Create sample files
|
34
|
-
FileUtils.mkdir_p('foo')
|
35
|
-
FileUtils.mkdir_p('foo/a/b')
|
36
|
-
File.open('foo/bar.html', 'w') { |io| io.write("---\nnum: 1\n---\ntest 1") }
|
37
|
-
File.open('foo/b.c.html', 'w') { |io| io.write("---\nnum: 2\n---\ntest 2") }
|
38
|
-
File.open('foo/a/b/c.html', 'w') { |io| io.write("---\nnum: 3\n---\ntest 3") }
|
39
|
-
File.open('foo/ugly.html~', 'w') { |io| io.write("---\nnum: 4\n---\ntest 4") }
|
40
|
-
File.open('foo/ugly.html.orig', 'w') { |io| io.write("---\nnum: 5\n---\ntest 5") }
|
41
|
-
File.open('foo/ugly.html.rej', 'w') { |io| io.write("---\nnum: 6\n---\ntest 6") }
|
42
|
-
File.open('foo/ugly.html.bak', 'w') { |io| io.write("---\nnum: 7\n---\ntest 7") }
|
43
|
-
|
44
|
-
# Get expected and actual output
|
45
|
-
expected_out = [
|
46
|
-
klass.new(
|
47
|
-
'test 1',
|
48
|
-
{ 'num' => 1, :filename => 'foo/bar.html', :extension => 'html', mtime: File.mtime('foo/bar.html') },
|
49
|
-
'/bar/',
|
50
|
-
),
|
51
|
-
klass.new(
|
52
|
-
'test 2',
|
53
|
-
{ 'num' => 2, :filename => 'foo/b.c.html', :extension => 'c.html', mtime: File.mtime('foo/b.c.html') },
|
54
|
-
'/b/',
|
55
|
-
),
|
56
|
-
klass.new(
|
57
|
-
'test 3',
|
58
|
-
{ 'num' => 3, :filename => 'foo/a/b/c.html', :extension => 'html', mtime: File.mtime('foo/a/b/c.html') },
|
59
|
-
'/a/b/c/',
|
60
|
-
),
|
61
|
-
]
|
62
|
-
actual_out = data_source.send(:load_objects, 'foo', klass).sort_by { |i| i.stuff[0].string }
|
63
|
-
|
64
|
-
# Check
|
65
|
-
(0..expected_out.size - 1).each do |i|
|
66
|
-
assert_equal expected_out[i].stuff[0], actual_out[i].stuff[0].string, 'content must match'
|
67
|
-
assert_equal expected_out[i].stuff[2], actual_out[i].stuff[2], 'identifier must match'
|
68
|
-
['num', :filename, :extension, :mtime].each do |key|
|
69
|
-
assert_equal expected_out[i].stuff[1][key], actual_out[i].stuff[1][key], "attribute key #{key} must match"
|
70
|
-
end
|
71
|
-
end
|
72
|
-
end
|
73
|
-
|
74
|
-
def test_load_objects_with_same_extensions
|
75
|
-
# Create data source
|
76
|
-
data_source = new_data_source(identifier_type: 'full')
|
77
|
-
|
78
|
-
# Create a fake class
|
79
|
-
klass = Class.new do
|
80
|
-
attr_reader :stuff
|
81
|
-
def initialize(*stuff)
|
82
|
-
@stuff = stuff
|
83
|
-
end
|
84
|
-
|
85
|
-
def ==(other)
|
86
|
-
@stuff == other.stuff
|
87
|
-
end
|
88
|
-
end
|
89
|
-
|
90
|
-
# Create sample files
|
91
|
-
FileUtils.mkdir_p('foo')
|
92
|
-
File.open('foo/bar.html', 'w') { |io| io.write("---\nnum: 1\n---\ntest 1") }
|
93
|
-
File.open('foo/bar.md', 'w') { |io| io.write("---\nnum: 1\n---\ntest 1") }
|
94
|
-
|
95
|
-
# Check
|
96
|
-
actual_out = data_source.send(:load_objects, 'foo', klass)
|
97
|
-
assert_equal 2, actual_out.size
|
98
|
-
end
|
99
|
-
|
100
|
-
def test_load_binary_objects
|
101
|
-
# Create data source
|
102
|
-
data_source = new_data_source
|
103
|
-
|
104
|
-
# Create sample files
|
105
|
-
FileUtils.mkdir_p('foo')
|
106
|
-
File.open('foo/stuff.dat', 'w') { |io| io.write('random binary data') }
|
107
|
-
|
108
|
-
# Load
|
109
|
-
items = data_source.send(:load_objects, 'foo', Nanoc::Int::Item)
|
110
|
-
|
111
|
-
# Check
|
112
|
-
assert_equal 1, items.size
|
113
|
-
assert items[0].content.binary?
|
114
|
-
assert_equal "#{Dir.getwd}/foo/stuff.dat", items[0].content.filename
|
115
|
-
assert_equal Nanoc::Int::BinaryContent, items[0].content.class
|
116
|
-
end
|
117
|
-
|
118
|
-
def test_load_layouts_with_nil_dir_name
|
119
|
-
# Create data source
|
120
|
-
data_source = new_data_source(layouts_dir: nil)
|
121
|
-
|
122
|
-
# Create sample files
|
123
|
-
FileUtils.mkdir_p('layouts')
|
124
|
-
File.write('layouts/stuff.txt', 'blah blah')
|
125
|
-
|
126
|
-
# Load
|
127
|
-
layouts = data_source.layouts
|
128
|
-
|
129
|
-
# Check
|
130
|
-
assert_empty(layouts)
|
131
|
-
end
|
132
|
-
|
133
|
-
def test_load_binary_layouts
|
134
|
-
# Create data source
|
135
|
-
data_source = new_data_source
|
136
|
-
|
137
|
-
# Create sample files
|
138
|
-
FileUtils.mkdir_p('foo')
|
139
|
-
File.open('foo/stuff.dat', 'w') { |io| io.write('random binary data') }
|
140
|
-
|
141
|
-
# Load
|
142
|
-
assert_raises(Nanoc::DataSources::Filesystem::Errors::BinaryLayout) do
|
143
|
-
data_source.send(:load_objects, 'foo', Nanoc::Int::Layout)
|
144
|
-
end
|
145
|
-
end
|
146
|
-
|
147
|
-
def test_identifier_for_filename_with_full_style_identifier
|
148
|
-
# Create data source
|
149
|
-
data_source = new_data_source(identifier_type: 'full')
|
150
|
-
|
151
|
-
# Get input and expected output
|
152
|
-
expected = {
|
153
|
-
'/foo' => Nanoc::Identifier.new('/foo', type: :full),
|
154
|
-
'/foo.html' => Nanoc::Identifier.new('/foo.html', type: :full),
|
155
|
-
'/foo/index.html' => Nanoc::Identifier.new('/foo/index.html', type: :full),
|
156
|
-
'/foo.html.erb' => Nanoc::Identifier.new('/foo.html.erb', type: :full),
|
157
|
-
}
|
158
|
-
|
159
|
-
# Check
|
160
|
-
expected.each_pair do |input, expected_output|
|
161
|
-
actual_output = data_source.send(:identifier_for_filename, input)
|
162
|
-
assert_equal(
|
163
|
-
expected_output, actual_output,
|
164
|
-
"identifier_for_filename(#{input.inspect}) should equal #{expected_output.inspect}, not #{actual_output.inspect}"
|
165
|
-
)
|
166
|
-
end
|
167
|
-
end
|
168
|
-
|
169
|
-
def test_identifier_for_filename_allowing_periods_in_identifiers
|
170
|
-
# Create data source
|
171
|
-
data_source = new_data_source(allow_periods_in_identifiers: true)
|
172
|
-
|
173
|
-
# Get input and expected output
|
174
|
-
expected = {
|
175
|
-
'/foo' => '/foo/',
|
176
|
-
'/foo.html' => '/foo/',
|
177
|
-
'/foo/index.html' => '/foo/',
|
178
|
-
'/foo.entry.html' => '/foo.entry/',
|
179
|
-
}
|
180
|
-
|
181
|
-
# Check
|
182
|
-
expected.each_pair do |input, expected_output|
|
183
|
-
actual_output = data_source.send(:identifier_for_filename, input)
|
184
|
-
assert_equal(
|
185
|
-
expected_output, actual_output,
|
186
|
-
"identifier_for_filename(#{input.inspect}) should equal #{expected_output.inspect}, not #{actual_output.inspect}"
|
187
|
-
)
|
188
|
-
end
|
189
|
-
end
|
190
|
-
|
191
|
-
def test_identifier_for_filename_disallowing_periods_in_identifiers
|
192
|
-
# Create data source
|
193
|
-
data_source = new_data_source
|
194
|
-
|
195
|
-
# Get input and expected output
|
196
|
-
expected = {
|
197
|
-
'/foo' => '/foo/',
|
198
|
-
'/foo.html' => '/foo/',
|
199
|
-
'/foo/index.html' => '/foo/',
|
200
|
-
'/foo.html.erb' => '/foo/',
|
201
|
-
}
|
202
|
-
|
203
|
-
# Check
|
204
|
-
expected.each_pair do |input, expected_output|
|
205
|
-
actual_output = data_source.send(:identifier_for_filename, input)
|
206
|
-
assert_equal(
|
207
|
-
expected_output, actual_output,
|
208
|
-
"identifier_for_filename(#{input.inspect}) should equal #{expected_output.inspect}, not #{actual_output.inspect}"
|
209
|
-
)
|
210
|
-
end
|
211
|
-
end
|
212
|
-
|
213
|
-
def test_identifier_for_filename_with_subfilename_allowing_periods_in_identifiers
|
214
|
-
expectations = {
|
215
|
-
'foo/bar.yaml' => '/foo/bar/',
|
216
|
-
'foo/quxbar.yaml' => '/foo/quxbar/',
|
217
|
-
'foo/barqux.yaml' => '/foo/barqux/',
|
218
|
-
'foo/quxbarqux.yaml' => '/foo/quxbarqux/',
|
219
|
-
'foo/qux.bar.yaml' => '/foo/qux.bar/',
|
220
|
-
'foo/bar.qux.yaml' => '/foo/bar.qux/',
|
221
|
-
'foo/qux.bar.qux.yaml' => '/foo/qux.bar.qux/',
|
222
|
-
'foo/index.yaml' => '/foo/',
|
223
|
-
'index.yaml' => '/',
|
224
|
-
'foo/blah_index.yaml' => '/foo/blah_index/',
|
225
|
-
}
|
226
|
-
|
227
|
-
data_source = new_data_source(allow_periods_in_identifiers: true)
|
228
|
-
expectations.each_pair do |meta_filename, expected_identifier|
|
229
|
-
content_filename = meta_filename.sub(/yaml$/, 'html')
|
230
|
-
[meta_filename, content_filename].each do |filename|
|
231
|
-
assert_equal(
|
232
|
-
expected_identifier,
|
233
|
-
data_source.instance_eval { identifier_for_filename(filename) },
|
234
|
-
)
|
235
|
-
end
|
236
|
-
end
|
237
|
-
end
|
238
|
-
|
239
|
-
def test_identifier_for_filename_with_subfilename_disallowing_periods_in_identifiers
|
240
|
-
expectations = {
|
241
|
-
'foo/bar.yaml' => '/foo/bar/',
|
242
|
-
'foo/quxbar.yaml' => '/foo/quxbar/',
|
243
|
-
'foo/barqux.yaml' => '/foo/barqux/',
|
244
|
-
'foo/quxbarqux.yaml' => '/foo/quxbarqux/',
|
245
|
-
'foo/qux.bar.yaml' => '/foo/qux/',
|
246
|
-
'foo/bar.qux.yaml' => '/foo/bar/',
|
247
|
-
'foo/qux.bar.qux.yaml' => '/foo/qux/',
|
248
|
-
'foo/index.yaml' => '/foo/',
|
249
|
-
'index.yaml' => '/',
|
250
|
-
'foo/blah_index.yaml' => '/foo/blah_index/',
|
251
|
-
}
|
252
|
-
|
253
|
-
data_source = new_data_source
|
254
|
-
expectations.each_pair do |meta_filename, expected_identifier|
|
255
|
-
content_filename = meta_filename.sub(/yaml$/, 'html')
|
256
|
-
[meta_filename, content_filename].each do |filename|
|
257
|
-
assert_equal(
|
258
|
-
expected_identifier,
|
259
|
-
data_source.instance_eval { identifier_for_filename(filename) },
|
260
|
-
)
|
261
|
-
end
|
262
|
-
end
|
263
|
-
end
|
264
|
-
|
265
|
-
def test_identifier_for_filename_with_index_filenames_allowing_periods_in_identifier
|
266
|
-
expected = {
|
267
|
-
'/index.html.erb' => '/index.html/',
|
268
|
-
'/index.html' => '/',
|
269
|
-
'/index' => '/',
|
270
|
-
'/foo/index.html.erb' => '/foo/index.html/',
|
271
|
-
'/foo/index.html' => '/foo/',
|
272
|
-
'/foo/index' => '/foo/',
|
273
|
-
}
|
274
|
-
|
275
|
-
data_source = new_data_source(allow_periods_in_identifiers: true)
|
276
|
-
expected.each_pair do |input, expected_output|
|
277
|
-
actual_output = data_source.send(:identifier_for_filename, input)
|
278
|
-
assert_equal(
|
279
|
-
expected_output, actual_output,
|
280
|
-
"identifier_for_filename(#{input.inspect}) should equal #{expected_output.inspect}, not #{actual_output.inspect}"
|
281
|
-
)
|
282
|
-
end
|
283
|
-
end
|
284
|
-
|
285
|
-
def test_identifier_for_filename_with_index_filenames_disallowing_periods_in_identifier
|
286
|
-
expected = {
|
287
|
-
'/index.html.erb' => '/',
|
288
|
-
'/index.html' => '/',
|
289
|
-
'/index' => '/',
|
290
|
-
'/foo/index.html.erb' => '/foo/',
|
291
|
-
'/foo/index.html' => '/foo/',
|
292
|
-
'/foo/index' => '/foo/',
|
293
|
-
}
|
294
|
-
|
295
|
-
data_source = new_data_source
|
296
|
-
expected.each_pair do |input, expected_output|
|
297
|
-
actual_output = data_source.send(:identifier_for_filename, input)
|
298
|
-
assert_equal(
|
299
|
-
expected_output, actual_output,
|
300
|
-
"identifier_for_filename(#{input.inspect}) should equal #{expected_output.inspect}, not #{actual_output.inspect}"
|
301
|
-
)
|
302
|
-
end
|
303
|
-
end
|
304
|
-
|
305
|
-
def test_load_objects_allowing_periods_in_identifiers
|
306
|
-
# Create data source
|
307
|
-
data_source = new_data_source(allow_periods_in_identifiers: true)
|
308
|
-
|
309
|
-
# Create a fake class
|
310
|
-
klass = Class.new do
|
311
|
-
attr_reader :stuff
|
312
|
-
def initialize(*stuff)
|
313
|
-
@stuff = stuff
|
314
|
-
end
|
315
|
-
|
316
|
-
def ==(other)
|
317
|
-
@stuff == other.stuff
|
318
|
-
end
|
319
|
-
end
|
320
|
-
|
321
|
-
# Create sample files
|
322
|
-
FileUtils.mkdir_p('foo')
|
323
|
-
FileUtils.mkdir_p('foo/a/b')
|
324
|
-
File.open('foo/a/b/c.yaml', 'w') { |io| io.write("---\nnum: 1\n") }
|
325
|
-
File.open('foo/b.c.yaml', 'w') { |io| io.write("---\nnum: 2\n") }
|
326
|
-
File.open('foo/b.c.html', 'w') { |io| io.write('test 2') }
|
327
|
-
File.open('foo/car.html', 'w') { |io| io.write('test 3') }
|
328
|
-
File.open('foo/ugly.yaml~', 'w') { |io| io.write('blah') }
|
329
|
-
File.open('foo/ugly.html~', 'w') { |io| io.write('blah') }
|
330
|
-
File.open('foo/ugly.html.orig', 'w') { |io| io.write('blah') }
|
331
|
-
File.open('foo/ugly.html.rej', 'w') { |io| io.write('blah') }
|
332
|
-
File.open('foo/ugly.html.bak', 'w') { |io| io.write('blah') }
|
333
|
-
|
334
|
-
# Get expected output
|
335
|
-
expected_out = [
|
336
|
-
klass.new(
|
337
|
-
'',
|
338
|
-
{
|
339
|
-
'num' => 1,
|
340
|
-
:content_filename => nil,
|
341
|
-
:meta_filename => 'foo/a/b/c.yaml',
|
342
|
-
:extension => nil,
|
343
|
-
:file => nil,
|
344
|
-
mtime: File.mtime('foo/a/b/c.yaml'),
|
345
|
-
},
|
346
|
-
'/a/b/c/',
|
347
|
-
),
|
348
|
-
klass.new(
|
349
|
-
'test 2',
|
350
|
-
{
|
351
|
-
'num' => 2,
|
352
|
-
:content_filename => 'foo/b.c.html',
|
353
|
-
:meta_filename => 'foo/b.c.yaml',
|
354
|
-
:extension => 'html',
|
355
|
-
:file => File.open('foo/b.c.html'),
|
356
|
-
mtime: File.mtime('foo/b.c.html') > File.mtime('foo/b.c.yaml') ? File.mtime('foo/b.c.html') : File.mtime('foo/b.c.yaml'),
|
357
|
-
},
|
358
|
-
'/b.c/',
|
359
|
-
),
|
360
|
-
klass.new(
|
361
|
-
'test 3',
|
362
|
-
{
|
363
|
-
content_filename: 'foo/car.html',
|
364
|
-
meta_filename: nil,
|
365
|
-
extension: 'html',
|
366
|
-
file: File.open('foo/car.html'),
|
367
|
-
mtime: File.mtime('foo/car.html'),
|
368
|
-
},
|
369
|
-
'/car/',
|
370
|
-
),
|
371
|
-
]
|
372
|
-
|
373
|
-
# Get actual output ordered by identifier
|
374
|
-
actual_out = data_source.send(:load_objects, 'foo', klass).sort_by { |i| i.stuff[2] }
|
375
|
-
|
376
|
-
# Check
|
377
|
-
(0..expected_out.size - 1).each do |i|
|
378
|
-
assert_equal expected_out[i].stuff[0], actual_out[i].stuff[0].string, 'content must match'
|
379
|
-
assert_equal expected_out[i].stuff[2], actual_out[i].stuff[2], 'identifier must match'
|
380
|
-
|
381
|
-
['num', :content_filename, :meta_filename, :extension, :mtime].each do |key|
|
382
|
-
assert_equal expected_out[i].stuff[1][key], actual_out[i].stuff[1][key], "attribute key #{key} must match"
|
383
|
-
end
|
384
|
-
end
|
385
|
-
end
|
386
|
-
|
387
|
-
def test_load_objects_disallowing_periods_in_identifiers
|
388
|
-
# Create data source
|
389
|
-
data_source = new_data_source
|
390
|
-
|
391
|
-
# Create a fake class
|
392
|
-
klass = Class.new do
|
393
|
-
attr_reader :stuff
|
394
|
-
def initialize(*stuff)
|
395
|
-
@stuff = stuff
|
396
|
-
end
|
397
|
-
|
398
|
-
def ==(other)
|
399
|
-
@stuff == other.stuff
|
400
|
-
end
|
401
|
-
end
|
402
|
-
|
403
|
-
# Create sample files
|
404
|
-
FileUtils.mkdir_p('foo')
|
405
|
-
FileUtils.mkdir_p('foo/a/b')
|
406
|
-
File.open('foo/a/b/c.yaml', 'w') { |io| io.write("---\nnum: 1\n") }
|
407
|
-
File.open('foo/b.yaml', 'w') { |io| io.write("---\nnum: 2\n") }
|
408
|
-
File.open('foo/b.html.erb', 'w') { |io| io.write('test 2') }
|
409
|
-
File.open('foo/car.html', 'w') { |io| io.write('test 3') }
|
410
|
-
File.open('foo/ugly.yaml~', 'w') { |io| io.write('blah') }
|
411
|
-
File.open('foo/ugly.html~', 'w') { |io| io.write('blah') }
|
412
|
-
File.open('foo/ugly.html.orig', 'w') { |io| io.write('blah') }
|
413
|
-
File.open('foo/ugly.html.rej', 'w') { |io| io.write('blah') }
|
414
|
-
File.open('foo/ugly.html.bak', 'w') { |io| io.write('blah') }
|
415
|
-
|
416
|
-
# Get expected output
|
417
|
-
expected_out = [
|
418
|
-
klass.new(
|
419
|
-
'',
|
420
|
-
{
|
421
|
-
'num' => 1,
|
422
|
-
:content_filename => nil,
|
423
|
-
:meta_filename => 'foo/a/b/c.yaml',
|
424
|
-
:extension => nil,
|
425
|
-
:file => nil,
|
426
|
-
mtime: File.mtime('foo/a/b/c.yaml'),
|
427
|
-
},
|
428
|
-
'/a/b/c/',
|
429
|
-
),
|
430
|
-
klass.new(
|
431
|
-
'test 2',
|
432
|
-
{
|
433
|
-
'num' => 2,
|
434
|
-
:content_filename => 'foo/b.html.erb',
|
435
|
-
:meta_filename => 'foo/b.yaml',
|
436
|
-
:extension => 'html.erb',
|
437
|
-
:file => File.open('foo/b.html.erb'),
|
438
|
-
mtime: File.mtime('foo/b.html.erb') > File.mtime('foo/b.yaml') ? File.mtime('foo/b.html.erb') : File.mtime('foo/b.yaml'),
|
439
|
-
},
|
440
|
-
'/b/',
|
441
|
-
),
|
442
|
-
klass.new(
|
443
|
-
'test 3',
|
444
|
-
{
|
445
|
-
content_filename: 'foo/car.html',
|
446
|
-
meta_filename: nil,
|
447
|
-
extension: 'html',
|
448
|
-
file: File.open('foo/car.html'),
|
449
|
-
mtime: File.mtime('foo/car.html'),
|
450
|
-
},
|
451
|
-
'/car/',
|
452
|
-
),
|
453
|
-
]
|
454
|
-
|
455
|
-
# Get actual output ordered by identifier
|
456
|
-
actual_out = data_source.send(:load_objects, 'foo', klass).sort_by { |i| i.stuff[2] }
|
457
|
-
|
458
|
-
# Check
|
459
|
-
(0..expected_out.size - 1).each do |i|
|
460
|
-
assert_equal expected_out[i].stuff[0], actual_out[i].stuff[0].string, 'content must match'
|
461
|
-
assert_equal expected_out[i].stuff[2], actual_out[i].stuff[2], 'identifier must match'
|
462
|
-
|
463
|
-
['num', :content_filename, :meta_filename, :extension, :mtime].each do |key|
|
464
|
-
assert_equal expected_out[i].stuff[1][key], actual_out[i].stuff[1][key], "attribute key #{key} must match"
|
465
|
-
end
|
466
|
-
end
|
467
|
-
end
|
468
|
-
|
469
|
-
def test_load_objects_correct_identifier_with_separate_yaml_file
|
470
|
-
data_source = new_data_source(identifier_type: 'full')
|
471
|
-
|
472
|
-
FileUtils.mkdir_p('foo')
|
473
|
-
File.write('foo/donkey.jpeg', 'data')
|
474
|
-
File.write('foo/donkey.yaml', "---\nalt: Donkey\n")
|
475
|
-
|
476
|
-
objects = data_source.send(:load_objects, 'foo', Nanoc::Int::Item)
|
477
|
-
assert_equal 1, objects.size
|
478
|
-
assert_equal '/donkey.jpeg', objects.first.identifier.to_s
|
479
|
-
end
|
480
|
-
|
481
|
-
def test_filename_for
|
482
|
-
data_source = new_data_source
|
483
|
-
|
484
|
-
assert_equal '/foo.bar', data_source.send(:filename_for, '/foo', 'bar')
|
485
|
-
assert_equal '/foo.bar.baz', data_source.send(:filename_for, '/foo', 'bar.baz')
|
486
|
-
assert_equal '/foo', data_source.send(:filename_for, '/foo', '')
|
487
|
-
assert_equal nil, data_source.send(:filename_for, '/foo', nil)
|
488
|
-
end
|
489
|
-
|
490
|
-
def test_compile_iso_8859_1_site
|
491
|
-
# Create data source
|
492
|
-
data_source = new_data_source
|
493
|
-
|
494
|
-
# Create item
|
495
|
-
FileUtils.mkdir_p('content')
|
496
|
-
File.open('content/foo.md', 'w') { |io| io << 'Hëllö' }
|
497
|
-
|
498
|
-
# Parse
|
499
|
-
begin
|
500
|
-
original_default_external_encoding = Encoding.default_external
|
501
|
-
Encoding.default_external = 'ISO-8859-1'
|
502
|
-
|
503
|
-
items = data_source.items
|
504
|
-
|
505
|
-
assert_equal 1, items.size
|
506
|
-
assert_equal Encoding.find('UTF-8'), items[0].content.string.encoding
|
507
|
-
ensure
|
508
|
-
Encoding.default_external = original_default_external_encoding
|
509
|
-
end
|
510
|
-
end
|
511
|
-
|
512
|
-
def test_compile_iso_8859_1_site_with_explicit_encoding
|
513
|
-
# Create data source
|
514
|
-
data_source = new_data_source({})
|
515
|
-
data_source.config[:encoding] = 'ISO-8859-1'
|
516
|
-
|
517
|
-
# Create item
|
518
|
-
begin
|
519
|
-
original_default_external_encoding = Encoding.default_external
|
520
|
-
Encoding.default_external = 'ISO-8859-1'
|
521
|
-
|
522
|
-
FileUtils.mkdir_p('content')
|
523
|
-
File.open('content/foo.md', 'w') { |io| io << 'Hëllö' }
|
524
|
-
ensure
|
525
|
-
Encoding.default_external = original_default_external_encoding
|
526
|
-
end
|
527
|
-
|
528
|
-
# Parse
|
529
|
-
items = data_source.items
|
530
|
-
assert_equal 1, items.size
|
531
|
-
assert_equal Encoding.find('UTF-8'), items[0].content.string.encoding
|
532
|
-
end
|
533
|
-
|
534
|
-
def test_all_split_files_in_allowing_periods_in_identifiers
|
535
|
-
# Create data source
|
536
|
-
data_source = Nanoc::DataSources::Filesystem.new(nil, nil, nil, allow_periods_in_identifiers: true)
|
537
|
-
|
538
|
-
# Write sample files
|
539
|
-
FileUtils.mkdir_p('foo')
|
540
|
-
%w[foo.html foo.yaml bar.entry.html foo/qux.yaml].each do |filename|
|
541
|
-
File.open(filename, 'w') { |io| io.write('test') }
|
542
|
-
end
|
543
|
-
|
544
|
-
# Write stray files
|
545
|
-
%w[foo.html~ foo.yaml.orig bar.entry.html.bak].each do |filename|
|
546
|
-
File.open(filename, 'w') { |io| io.write('test') }
|
547
|
-
end
|
548
|
-
|
549
|
-
# Get all files
|
550
|
-
output_expected = {
|
551
|
-
'./foo' => ['yaml', ['html']],
|
552
|
-
'./bar.entry' => [nil, ['html']],
|
553
|
-
'./foo/qux' => ['yaml', [nil]],
|
554
|
-
}
|
555
|
-
output_actual = data_source.send :all_split_files_in, '.'
|
556
|
-
|
557
|
-
# Check
|
558
|
-
assert_equal output_expected, output_actual
|
559
|
-
end
|
560
|
-
|
561
|
-
def test_all_split_files_in_disallowing_periods_in_identifiers
|
562
|
-
# Create data source
|
563
|
-
data_source = Nanoc::DataSources::Filesystem.new(nil, nil, nil, nil)
|
564
|
-
|
565
|
-
# Write sample files
|
566
|
-
FileUtils.mkdir_p('foo')
|
567
|
-
%w[foo.html foo.yaml bar.html.erb foo/qux.yaml].each do |filename|
|
568
|
-
File.open(filename, 'w') { |io| io.write('test') }
|
569
|
-
end
|
570
|
-
|
571
|
-
# Write stray files
|
572
|
-
%w[foo.html~ foo.yaml.orig bar.entry.html.bak].each do |filename|
|
573
|
-
File.open(filename, 'w') { |io| io.write('test') }
|
574
|
-
end
|
575
|
-
|
576
|
-
# Get all files
|
577
|
-
output_expected = {
|
578
|
-
'./foo' => ['yaml', ['html']],
|
579
|
-
'./bar' => [nil, ['html.erb']],
|
580
|
-
'./foo/qux' => ['yaml', [nil]],
|
581
|
-
}
|
582
|
-
output_actual = data_source.send :all_split_files_in, '.'
|
583
|
-
|
584
|
-
# Check
|
585
|
-
assert_equal output_expected, output_actual
|
586
|
-
end
|
587
|
-
|
588
|
-
def test_all_split_files_in_with_multiple_dirs
|
589
|
-
# Create data source
|
590
|
-
data_source = Nanoc::DataSources::Filesystem.new(nil, nil, nil, nil)
|
591
|
-
|
592
|
-
# Write sample files
|
593
|
-
%w[aaa/foo.html bbb/foo.html ccc/foo.html].each do |filename|
|
594
|
-
FileUtils.mkdir_p(File.dirname(filename))
|
595
|
-
File.open(filename, 'w') { |io| io.write('test') }
|
596
|
-
end
|
597
|
-
|
598
|
-
# Check
|
599
|
-
expected = {
|
600
|
-
'./aaa/foo' => [nil, ['html']],
|
601
|
-
'./bbb/foo' => [nil, ['html']],
|
602
|
-
'./ccc/foo' => [nil, ['html']],
|
603
|
-
}
|
604
|
-
assert_equal expected, data_source.send(:all_split_files_in, '.')
|
605
|
-
end
|
606
|
-
|
607
|
-
def test_all_split_files_in_with_same_extensions
|
608
|
-
# Create data source
|
609
|
-
config = { identifier_type: 'full' }
|
610
|
-
data_source = Nanoc::DataSources::Filesystem.new(nil, nil, nil, config)
|
611
|
-
|
612
|
-
# Write sample files
|
613
|
-
%w[stuff/foo.html stuff/foo.md stuff/foo.yaml].each do |filename|
|
614
|
-
FileUtils.mkdir_p(File.dirname(filename))
|
615
|
-
File.open(filename, 'w') { |io| io.write('test') }
|
616
|
-
end
|
617
|
-
|
618
|
-
# Check - { './stuff/foo' => ['yaml', ['html', 'md']] }
|
619
|
-
res = data_source.send(:all_split_files_in, '.')
|
620
|
-
assert_equal ['./stuff/foo'], res.keys
|
621
|
-
assert_equal 2, res.values[0].size
|
622
|
-
assert_equal 'yaml', res.values[0][0]
|
623
|
-
assert_equal Array, res.values[0][1].class
|
624
|
-
assert_equal %w[html md], res.values[0][1].sort
|
625
|
-
end
|
626
|
-
|
627
|
-
def test_all_split_files_in_with_multiple_content_files
|
628
|
-
# Create data source
|
629
|
-
data_source = Nanoc::DataSources::Filesystem.new(nil, nil, nil, nil)
|
630
|
-
|
631
|
-
# Write sample files
|
632
|
-
%w[foo.html foo.xhtml foo.txt foo.yaml bar.html qux.yaml].each do |filename|
|
633
|
-
File.open(filename, 'w') { |io| io.write('test') }
|
634
|
-
end
|
635
|
-
|
636
|
-
# Check
|
637
|
-
assert_raises(Nanoc::DataSources::Filesystem::Errors::MultipleContentFiles) do
|
638
|
-
data_source.send(:all_split_files_in, '.')
|
639
|
-
end
|
640
|
-
end
|
641
|
-
|
642
|
-
def test_basename_of_with_full_style_identifiers
|
643
|
-
# Create data source
|
644
|
-
config = { identifier_type: 'full' }
|
645
|
-
data_source = Nanoc::DataSources::Filesystem.new(nil, nil, nil, config)
|
646
|
-
|
647
|
-
# Get input and expected output
|
648
|
-
expected = {
|
649
|
-
'/' => '/',
|
650
|
-
'/foo' => '/foo',
|
651
|
-
'/foo.html' => '/foo',
|
652
|
-
'/foo.xyz.html' => '/foo.xyz',
|
653
|
-
'/foo/bar' => '/foo/bar',
|
654
|
-
'/foo/bar.html' => '/foo/bar',
|
655
|
-
'/foo/bar.xyz.html' => '/foo/bar.xyz',
|
656
|
-
}
|
657
|
-
|
658
|
-
# Check
|
659
|
-
expected.each_pair do |input, expected_output|
|
660
|
-
actual_output = data_source.send(:basename_of, input)
|
661
|
-
assert_equal(
|
662
|
-
expected_output, actual_output,
|
663
|
-
"basename_of(#{input.inspect}) should equal #{expected_output.inspect}, not #{actual_output.inspect}"
|
664
|
-
)
|
665
|
-
end
|
666
|
-
end
|
667
|
-
|
668
|
-
def test_basename_of_allowing_periods_in_identifiers
|
669
|
-
# Create data source
|
670
|
-
data_source = Nanoc::DataSources::Filesystem.new(nil, nil, nil, allow_periods_in_identifiers: true)
|
671
|
-
|
672
|
-
# Get input and expected output
|
673
|
-
expected = {
|
674
|
-
'/' => '/',
|
675
|
-
'/foo' => '/foo',
|
676
|
-
'/foo.html' => '/foo',
|
677
|
-
'/foo.xyz.html' => '/foo.xyz',
|
678
|
-
'/foo/' => '/foo/',
|
679
|
-
'/foo.xyz/' => '/foo.xyz/',
|
680
|
-
'/foo/bar' => '/foo/bar',
|
681
|
-
'/foo/bar.html' => '/foo/bar',
|
682
|
-
'/foo/bar.xyz.html' => '/foo/bar.xyz',
|
683
|
-
'/foo/bar/' => '/foo/bar/',
|
684
|
-
'/foo/bar.xyz/' => '/foo/bar.xyz/',
|
685
|
-
'/foo.xyz/bar.xyz/' => '/foo.xyz/bar.xyz/',
|
686
|
-
}
|
687
|
-
|
688
|
-
# Check
|
689
|
-
expected.each_pair do |input, expected_output|
|
690
|
-
actual_output = data_source.send(:basename_of, input)
|
691
|
-
assert_equal(
|
692
|
-
expected_output, actual_output,
|
693
|
-
"basename_of(#{input.inspect}) should equal #{expected_output.inspect}, not #{actual_output.inspect}"
|
694
|
-
)
|
695
|
-
end
|
696
|
-
end
|
697
|
-
|
698
|
-
def test_basename_of_disallowing_periods_in_identifiers
|
699
|
-
# Create data source
|
700
|
-
data_source = Nanoc::DataSources::Filesystem.new(nil, nil, nil, nil)
|
701
|
-
|
702
|
-
# Get input and expected output
|
703
|
-
expected = {
|
704
|
-
'/' => '/',
|
705
|
-
'/foo' => '/foo',
|
706
|
-
'/foo.html' => '/foo',
|
707
|
-
'/foo.xyz.html' => '/foo',
|
708
|
-
'/foo/' => '/foo/',
|
709
|
-
'/foo.xyz/' => '/foo.xyz/',
|
710
|
-
'/foo/bar' => '/foo/bar',
|
711
|
-
'/foo/bar.html' => '/foo/bar',
|
712
|
-
'/foo/bar.xyz.html' => '/foo/bar',
|
713
|
-
'/foo/bar/' => '/foo/bar/',
|
714
|
-
'/foo/bar.xyz/' => '/foo/bar.xyz/',
|
715
|
-
'/foo.xyz/bar.xyz/' => '/foo.xyz/bar.xyz/',
|
716
|
-
}
|
717
|
-
|
718
|
-
# Check
|
719
|
-
expected.each_pair do |input, expected_output|
|
720
|
-
actual_output = data_source.send(:basename_of, input)
|
721
|
-
assert_equal(
|
722
|
-
expected_output, actual_output,
|
723
|
-
"basename_of(#{input.inspect}) should equal #{expected_output.inspect}, not #{actual_output.inspect}"
|
724
|
-
)
|
725
|
-
end
|
726
|
-
end
|
727
|
-
|
728
|
-
def test_ext_of_allowing_periods_in_identifiers
|
729
|
-
# Create data source
|
730
|
-
data_source = Nanoc::DataSources::Filesystem.new(nil, nil, nil, allow_periods_in_identifiers: true)
|
731
|
-
|
732
|
-
# Get input and expected output
|
733
|
-
expected = {
|
734
|
-
'/' => '',
|
735
|
-
'/foo' => '',
|
736
|
-
'/foo.html' => '.html',
|
737
|
-
'/foo.xyz.html' => '.html',
|
738
|
-
'/foo/' => '',
|
739
|
-
'/foo.xyz/' => '',
|
740
|
-
'/foo/bar' => '',
|
741
|
-
'/foo/bar.html' => '.html',
|
742
|
-
'/foo/bar.xyz.html' => '.html',
|
743
|
-
'/foo/bar/' => '',
|
744
|
-
'/foo/bar.xyz/' => '',
|
745
|
-
'/foo.xyz/bar.xyz/' => '',
|
746
|
-
}
|
747
|
-
|
748
|
-
# Check
|
749
|
-
expected.each_pair do |input, expected_output|
|
750
|
-
actual_output = data_source.send(:ext_of, input)
|
751
|
-
assert_equal(
|
752
|
-
expected_output, actual_output,
|
753
|
-
"basename_of(#{input.inspect}) should equal #{expected_output.inspect}, not #{actual_output.inspect}"
|
754
|
-
)
|
755
|
-
end
|
756
|
-
end
|
757
|
-
|
758
|
-
def test_ext_of_disallowing_periods_in_identifiers
|
759
|
-
# Create data source
|
760
|
-
data_source = Nanoc::DataSources::Filesystem.new(nil, nil, nil, nil)
|
761
|
-
|
762
|
-
# Get input and expected output
|
763
|
-
expected = {
|
764
|
-
'/' => '',
|
765
|
-
'/foo' => '',
|
766
|
-
'/foo.html' => '.html',
|
767
|
-
'/foo.xyz.html' => '.xyz.html',
|
768
|
-
'/foo/' => '',
|
769
|
-
'/foo.xyz/' => '',
|
770
|
-
'/foo/bar' => '',
|
771
|
-
'/foo/bar.html' => '.html',
|
772
|
-
'/foo/bar.xyz.html' => '.xyz.html',
|
773
|
-
'/foo/bar/' => '',
|
774
|
-
'/foo/bar.xyz/' => '',
|
775
|
-
'/foo.xyz/bar.xyz/' => '',
|
776
|
-
}
|
777
|
-
|
778
|
-
# Check
|
779
|
-
expected.each_pair do |input, expected_output|
|
780
|
-
actual_output = data_source.send(:ext_of, input)
|
781
|
-
assert_equal(
|
782
|
-
expected_output, actual_output,
|
783
|
-
"basename_of(#{input.inspect}) should equal #{expected_output.inspect}, not #{actual_output.inspect}"
|
784
|
-
)
|
785
|
-
end
|
786
|
-
end
|
787
|
-
|
788
|
-
def test_parse_embedded_meta_only_1
|
789
|
-
# Create a file
|
790
|
-
File.open('test.html', 'w') do |io|
|
791
|
-
io.write "-----\r\n"
|
792
|
-
io.write "foo: bar\n"
|
793
|
-
io.write "-----\n"
|
794
|
-
end
|
795
|
-
|
796
|
-
# Create data source
|
797
|
-
data_source = Nanoc::DataSources::Filesystem.new(nil, nil, nil, nil)
|
798
|
-
|
799
|
-
# Parse it
|
800
|
-
result = data_source.instance_eval { parse('test.html', nil) }
|
801
|
-
assert_equal({ 'foo' => 'bar' }, result.attributes)
|
802
|
-
assert_equal('', result.content)
|
803
|
-
end
|
804
|
-
|
805
|
-
def test_parse_embedded_meta_only_2
|
806
|
-
# Create a file
|
807
|
-
File.open('test.html', 'w') do |io|
|
808
|
-
io.write "-----\n"
|
809
|
-
io.write "foo: bar\r\n"
|
810
|
-
io.write "-----\r"
|
811
|
-
end
|
812
|
-
|
813
|
-
# Create data source
|
814
|
-
data_source = Nanoc::DataSources::Filesystem.new(nil, nil, nil, nil)
|
815
|
-
|
816
|
-
# Parse it
|
817
|
-
result = data_source.instance_eval { parse('test.html', nil) }
|
818
|
-
assert_equal({ 'foo' => 'bar' }, result.attributes)
|
819
|
-
assert_equal('', result.content)
|
820
|
-
end
|
821
|
-
|
822
|
-
def test_parse_embedded_meta_only_3
|
823
|
-
# Create a file
|
824
|
-
File.open('test.html', 'w') do |io|
|
825
|
-
io.write "-----\r\n"
|
826
|
-
io.write "foo: bar\n"
|
827
|
-
io.write '-----'
|
828
|
-
end
|
829
|
-
|
830
|
-
# Create data source
|
831
|
-
data_source = Nanoc::DataSources::Filesystem.new(nil, nil, nil, nil)
|
832
|
-
|
833
|
-
# Parse it
|
834
|
-
result = data_source.instance_eval { parse('test.html', nil) }
|
835
|
-
assert_equal({ 'foo' => 'bar' }, result.attributes)
|
836
|
-
assert_equal('', result.content)
|
837
|
-
end
|
838
|
-
|
839
|
-
def test_parse_embedded_invalid_2
|
840
|
-
# Create a file
|
841
|
-
File.open('test.html', 'w') do |io|
|
842
|
-
io.write "-----\n"
|
843
|
-
io.write "blah blah\n"
|
844
|
-
end
|
845
|
-
|
846
|
-
# Create data source
|
847
|
-
data_source = Nanoc::DataSources::Filesystem.new(nil, nil, nil, nil)
|
848
|
-
|
849
|
-
# Parse it
|
850
|
-
assert_raises(Nanoc::DataSources::Filesystem::Errors::InvalidFormat) do
|
851
|
-
data_source.instance_eval { parse('test.html', nil) }
|
852
|
-
end
|
853
|
-
end
|
854
|
-
|
855
|
-
def test_parse_embedded_separators_but_not_metadata
|
856
|
-
# Create a file
|
857
|
-
File.open('test.html', 'w') do |io|
|
858
|
-
io.write "blah blah\n"
|
859
|
-
io.write "-----\n"
|
860
|
-
io.write "blah blah\n"
|
861
|
-
end
|
862
|
-
|
863
|
-
# Create data source
|
864
|
-
data_source = Nanoc::DataSources::Filesystem.new(nil, nil, nil, nil)
|
865
|
-
|
866
|
-
# Parse it
|
867
|
-
result = data_source.instance_eval { parse('test.html', nil) }
|
868
|
-
assert_equal(File.read('test.html'), result.content)
|
869
|
-
assert_equal({}, result.attributes)
|
870
|
-
end
|
871
|
-
|
872
|
-
def test_parse_embedded_full_meta
|
873
|
-
# Create a file
|
874
|
-
File.open('test.html', 'w') do |io|
|
875
|
-
io.write "-----\r\n"
|
876
|
-
io.write "foo: bar\n"
|
877
|
-
io.write "-----\n"
|
878
|
-
io.write " \t\n blah blah\n"
|
879
|
-
end
|
880
|
-
|
881
|
-
# Create data source
|
882
|
-
data_source = Nanoc::DataSources::Filesystem.new(nil, nil, nil, nil)
|
883
|
-
|
884
|
-
# Parse it
|
885
|
-
result = data_source.instance_eval { parse('test.html', nil) }
|
886
|
-
assert_equal({ 'foo' => 'bar' }, result.attributes)
|
887
|
-
assert_equal(" \t\n blah blah\n", result.content)
|
888
|
-
end
|
889
|
-
|
890
|
-
def test_parse_embedded_with_extra_spaces
|
891
|
-
# Create a file
|
892
|
-
File.open('test.html', 'w') do |io|
|
893
|
-
io.write "----- \n"
|
894
|
-
io.write "foo: bar\n"
|
895
|
-
io.write "-----\t\t\t\t\t\n"
|
896
|
-
io.write " blah blah\n"
|
897
|
-
end
|
898
|
-
|
899
|
-
# Create data source
|
900
|
-
data_source = Nanoc::DataSources::Filesystem.new(nil, nil, nil, nil)
|
901
|
-
|
902
|
-
# Parse it
|
903
|
-
result = data_source.instance_eval { parse('test.html', nil) }
|
904
|
-
assert_equal({ 'foo' => 'bar' }, result.attributes)
|
905
|
-
assert_equal(" blah blah\n", result.content)
|
906
|
-
end
|
907
|
-
|
908
|
-
def test_parse_embedded_empty_meta
|
909
|
-
# Create a file
|
910
|
-
File.open('test.html', 'w') do |io|
|
911
|
-
io.write "-----\n"
|
912
|
-
io.write "-----\n"
|
913
|
-
io.write "\nblah blah\n"
|
914
|
-
io.write '-----'
|
915
|
-
end
|
916
|
-
|
917
|
-
# Create data source
|
918
|
-
data_source = Nanoc::DataSources::Filesystem.new(nil, nil, nil, nil)
|
919
|
-
|
920
|
-
# Parse it
|
921
|
-
result = data_source.instance_eval { parse('test.html', nil) }
|
922
|
-
assert_equal({}, result.attributes)
|
923
|
-
assert_equal("\nblah blah\n-----", result.content)
|
924
|
-
end
|
925
|
-
|
926
|
-
def test_parse_utf8_bom
|
927
|
-
File.open('test.html', 'w') do |io|
|
928
|
-
io.write [0xEF, 0xBB, 0xBF].map(&:chr).join
|
929
|
-
io.write "-----\n"
|
930
|
-
io.write "utf8bomawareness: high\n"
|
931
|
-
io.write "-----\n"
|
932
|
-
io.write "content goes here\n"
|
933
|
-
end
|
934
|
-
|
935
|
-
data_source = Nanoc::DataSources::Filesystem.new(nil, nil, nil, encoding: 'utf-8')
|
936
|
-
|
937
|
-
result = data_source.instance_eval { parse('test.html', nil) }
|
938
|
-
assert_equal({ 'utf8bomawareness' => 'high' }, result.attributes)
|
939
|
-
assert_equal("content goes here\n", result.content)
|
940
|
-
end
|
941
|
-
|
942
|
-
def test_parse_embedded_no_meta
|
943
|
-
content = "blah\n" \
|
944
|
-
"blah blah blah\n" \
|
945
|
-
"blah blah\n"
|
946
|
-
|
947
|
-
# Create a file
|
948
|
-
File.open('test.html', 'w') { |io| io.write(content) }
|
949
|
-
|
950
|
-
# Create data source
|
951
|
-
data_source = Nanoc::DataSources::Filesystem.new(nil, nil, nil, nil)
|
952
|
-
|
953
|
-
# Parse it
|
954
|
-
result = data_source.instance_eval { parse('test.html', nil) }
|
955
|
-
assert_equal({}, result.attributes)
|
956
|
-
assert_equal(content, result.content)
|
957
|
-
end
|
958
|
-
|
959
|
-
def test_parse_embedded_diff
|
960
|
-
content = \
|
961
|
-
"--- a/foo\n" \
|
962
|
-
"+++ b/foo\n" \
|
963
|
-
"blah blah\n"
|
964
|
-
|
965
|
-
# Create a file
|
966
|
-
File.open('test.html', 'w') { |io| io.write(content) }
|
967
|
-
|
968
|
-
# Create data source
|
969
|
-
data_source = Nanoc::DataSources::Filesystem.new(nil, nil, nil, nil)
|
970
|
-
|
971
|
-
# Parse it
|
972
|
-
result = data_source.instance_eval { parse('test.html', nil) }
|
973
|
-
assert_equal({}, result.attributes)
|
974
|
-
assert_equal(content, result.content)
|
975
|
-
end
|
976
|
-
|
977
|
-
def test_parse_external
|
978
|
-
# Create a file
|
979
|
-
File.open('test.html', 'w') { |io| io.write('blah blah') }
|
980
|
-
File.open('test.yaml', 'w') { |io| io.write('foo: bar') }
|
981
|
-
|
982
|
-
# Create data source
|
983
|
-
data_source = Nanoc::DataSources::Filesystem.new(nil, nil, nil, nil)
|
984
|
-
|
985
|
-
# Parse it
|
986
|
-
result = data_source.instance_eval { parse('test.html', 'test.yaml') }
|
987
|
-
assert_equal({ 'foo' => 'bar' }, result.attributes)
|
988
|
-
assert_equal('blah blah', result.content)
|
989
|
-
end
|
990
|
-
|
991
|
-
def test_parse_internal_bad_metadata
|
992
|
-
content = \
|
993
|
-
"---\n" \
|
994
|
-
"Hello world!\n" \
|
995
|
-
"---\n" \
|
996
|
-
"blah blah\n"
|
997
|
-
|
998
|
-
File.open('test.html', 'w') { |io| io.write(content) }
|
999
|
-
|
1000
|
-
data_source = Nanoc::DataSources::Filesystem.new(nil, nil, nil, nil)
|
1001
|
-
|
1002
|
-
assert_raises(Nanoc::DataSources::Filesystem::Errors::InvalidMetadata) do
|
1003
|
-
data_source.instance_eval { parse('test.html', nil) }
|
1004
|
-
end
|
1005
|
-
end
|
1006
|
-
|
1007
|
-
def test_parse_internal_four_dashes
|
1008
|
-
content = \
|
1009
|
-
"----\n" \
|
1010
|
-
"fav_animal: donkey\n" \
|
1011
|
-
"----\n" \
|
1012
|
-
"blah blah\n"
|
1013
|
-
|
1014
|
-
File.open('test.html', 'w') { |io| io.write(content) }
|
1015
|
-
|
1016
|
-
data_source = Nanoc::DataSources::Filesystem.new(nil, nil, nil, nil)
|
1017
|
-
|
1018
|
-
result = data_source.instance_eval { parse('test.html', nil) }
|
1019
|
-
assert_equal({}, result.attributes)
|
1020
|
-
assert_equal(content, result.content)
|
1021
|
-
end
|
1022
|
-
|
1023
|
-
def test_parse_external_bad_metadata
|
1024
|
-
File.open('test.html', 'w') { |io| io.write('blah blah') }
|
1025
|
-
File.open('test.yaml', 'w') { |io| io.write('Hello world!') }
|
1026
|
-
|
1027
|
-
data_source = Nanoc::DataSources::Filesystem.new(nil, nil, nil, nil)
|
1028
|
-
|
1029
|
-
assert_raises(Nanoc::DataSources::Filesystem::Errors::InvalidMetadata) do
|
1030
|
-
data_source.instance_eval { parse('test.html', 'test.yaml') }
|
1031
|
-
end
|
1032
|
-
end
|
1033
|
-
end
|