diff -Nru nanoc-4.7.13/bin/nanoc nanoc-4.8.0/bin/nanoc --- nanoc-4.7.13/bin/nanoc 2017-07-02 09:44:22.000000000 +0000 +++ nanoc-4.8.0/bin/nanoc 2017-07-20 14:46:01.000000000 +0000 @@ -2,6 +2,13 @@ # frozen_string_literal: true require 'nanoc' + +begin + require 'nanoc-rust' + NanocRust.activate! +rescue LoadError +end + require 'nanoc/cli' if File.file?('Gemfile') && !defined?(Bundler) diff -Nru nanoc-4.7.13/debian/changelog nanoc-4.8.0/debian/changelog --- nanoc-4.7.13/debian/changelog 2017-07-02 09:45:10.000000000 +0000 +++ nanoc-4.8.0/debian/changelog 2017-07-20 15:08:05.000000000 +0000 @@ -1,3 +1,12 @@ +nanoc (4.8.0-1) unstable; urgency=medium + + * New upstream version 4.8.0 + + Adds support for asciidoctor filter + * Bump Debhelper compatibility version to 10 + * Refresh skip_tests_autopkgtest.patch + + -- Cédric Boutillier Thu, 20 Jul 2017 17:08:05 +0200 + nanoc (4.7.13-1) unstable; urgency=medium * New upstream version 4.7.13 diff -Nru nanoc-4.7.13/debian/compat nanoc-4.8.0/debian/compat --- nanoc-4.7.13/debian/compat 2017-07-02 09:45:10.000000000 +0000 +++ nanoc-4.8.0/debian/compat 2017-07-20 15:08:05.000000000 +0000 @@ -1 +1 @@ -9 +10 diff -Nru nanoc-4.7.13/debian/control nanoc-4.8.0/debian/control --- nanoc-4.7.13/debian/control 2017-07-02 09:45:10.000000000 +0000 +++ nanoc-4.8.0/debian/control 2017-07-20 15:08:05.000000000 +0000 @@ -4,8 +4,9 @@ Maintainer: Debian Ruby Extras Maintainers Uploaders: Cédric Boutillier Build-Depends: asciidoc-base, + asciidoctor, coderay, - debhelper (>= 9~), + debhelper (>= 10~), gem2deb, git, highlight, @@ -69,6 +70,7 @@ ${misc:Depends}, ${shlibs:Depends} Recommends: asciidoc-base, + asciidoctor, ruby-builder, ruby-coffee-script, ruby-compass, diff -Nru nanoc-4.7.13/debian/patches/skip_tests_autopkgtest.patch nanoc-4.8.0/debian/patches/skip_tests_autopkgtest.patch --- nanoc-4.7.13/debian/patches/skip_tests_autopkgtest.patch 2017-07-02 09:45:10.000000000 +0000 +++ nanoc-4.8.0/debian/patches/skip_tests_autopkgtest.patch 2017-07-20 15:08:05.000000000 +0000 @@ -1,7 +1,7 @@ Description: skip tests which are failing in autopkgtest because of missing context Author: Cédric Boutillier Forwarded: no -Last-Update: 2017-05-14 +Last-Update: 2017-07-20 --- a/test/base/test_context.rb +++ b/test/base/test_context.rb @@ -16,7 +16,7 @@ context = Nanoc::Int::Context.new({}) --- a/test/base/test_directed_graph.rb +++ b/test/base/test_directed_graph.rb -@@ -328,5 +328,5 @@ +@@ -72,5 +72,5 @@ def test_example YARD.parse(LIB_DIR + '/nanoc/base/entities/directed_graph.rb') assert_examples_correct 'Nanoc::Int::DirectedGraph' diff -Nru nanoc-4.7.13/Gemfile nanoc-4.8.0/Gemfile --- nanoc-4.7.13/Gemfile 2017-07-02 09:44:22.000000000 +0000 +++ nanoc-4.8.0/Gemfile 2017-07-20 14:46:01.000000000 +0000 @@ -32,6 +32,7 @@ group :plugins do gem 'adsf' + gem 'asciidoctor' gem 'bluecloth', platforms: :ruby gem 'builder' gem 'coderay' diff -Nru nanoc-4.7.13/lib/nanoc/base/entities/code_snippet.rb nanoc-4.8.0/lib/nanoc/base/entities/code_snippet.rb --- nanoc-4.7.13/lib/nanoc/base/entities/code_snippet.rb 2017-07-02 09:44:22.000000000 +0000 +++ nanoc-4.8.0/lib/nanoc/base/entities/code_snippet.rb 2017-07-20 14:46:01.000000000 +0000 @@ -43,7 +43,7 @@ # # @return [Object] An unique reference to this object def reference - [:code_snippet, filename] + "code_snippet:#{filename}" end def inspect diff -Nru nanoc-4.7.13/lib/nanoc/base/entities/configuration.rb nanoc-4.8.0/lib/nanoc/base/entities/configuration.rb --- nanoc-4.7.13/lib/nanoc/base/entities/configuration.rb 2017-07-02 09:44:22.000000000 +0000 +++ nanoc-4.8.0/lib/nanoc/base/entities/configuration.rb 2017-07-20 14:46:01.000000000 +0000 @@ -164,7 +164,7 @@ # # @return [Object] An unique reference to this object def reference - :config + 'configuration' end def inspect diff -Nru nanoc-4.7.13/lib/nanoc/base/entities/directed_graph.rb nanoc-4.8.0/lib/nanoc/base/entities/directed_graph.rb --- nanoc-4.7.13/lib/nanoc/base/entities/directed_graph.rb 2017-07-02 09:44:22.000000000 +0000 +++ nanoc-4.8.0/lib/nanoc/base/entities/directed_graph.rb 2017-07-20 14:46:01.000000000 +0000 @@ -7,27 +7,28 @@ # @example Creating and using a directed graph # # # Create a graph with three vertices - # graph = Nanoc::Int::DirectedGraph.new(%w( a b c d )) + # graph = Nanoc::Int::DirectedGraph.new(%w( a b c d e )) # # # Add edges # graph.add_edge('a', 'b') # graph.add_edge('b', 'c') # graph.add_edge('c', 'd') + # graph.add_edge('b', 'e') # - # # Get (direct) predecessors - # graph.direct_predecessors_of('d').sort - # # => %w( c ) - # graph.predecessors_of('d').sort - # # => %w( a b c ) + # # Get (direct) successors + # graph.direct_successors_of('a').sort + # # => %w( b ) + # graph.successors_of('a').sort + # # => %w( b c d e ) # # # Modify edges - # graph.delete_edge('a', 'b') + # graph.delete_edges_to('c') # - # # Get (direct) predecessors again - # graph.direct_predecessors_of('d').sort - # # => %w( c ) - # graph.predecessors_of('d').sort - # # => %w( b c ) + # # Get (direct) successors again + # graph.direct_successors_of('a').sort + # # => %w( b ) + # graph.successors_of('a').sort + # # => %w( b e ) # # @api private class DirectedGraph @@ -36,8 +37,9 @@ # Creates a new directed graph with the given vertices. def initialize(vertices) @vertices = {} - vertices.each_with_index do |v, i| - @vertices[v] = i + @next_vertex_idx = 0 + vertices.each do |v| + @vertices[v] = @next_vertex_idx.tap { @next_vertex_idx += 1 } end @from_graph = {} @@ -45,8 +47,6 @@ @edge_props = {} - @roots = Set.new(@vertices.keys) - invalidate_caches end @@ -85,30 +85,6 @@ @edge_props[[from, to]] = props end - @roots.delete(to) - - invalidate_caches - end - - # Removes the edge from the first vertex to the second vertex. If the - # edge does not exist, nothing is done. - # - # @param from Start vertex of the edge - # - # @param to End vertex of the edge - # - # @return [void] - def delete_edge(from, to) - @from_graph[from] ||= Set.new - @from_graph[from].delete(to) - - @to_graph[to] ||= Set.new - @to_graph[to].delete(from) - - @edge_props.delete([from, to]) - - @roots.add(to) if @to_graph[to].empty? - invalidate_caches end @@ -120,25 +96,7 @@ def add_vertex(v) return if @vertices.key?(v) - @vertices[v] = @vertices.size - - @roots << v - end - - # Deletes all edges coming from the given vertex. - # - # @param from Vertex from which all edges should be removed - # - # @return [void] - def delete_edges_from(from) - return if @from_graph[from].nil? - - @from_graph[from].each do |to| - @to_graph[to].delete(from) - @edge_props.delete([from, to]) - @roots.add(to) if @to_graph[to].empty? - end - @from_graph.delete(from) + @vertices[v] = @next_vertex_idx.tap { @next_vertex_idx += 1 } end # Deletes all edges going to the given vertex. @@ -154,64 +112,12 @@ @edge_props.delete([from, to]) end @to_graph.delete(to) - @roots.add(to) - end - - # Removes the given vertex from the graph. - # - # @param v Vertex to remove from the graph - # - # @return [void] - def delete_vertex(v) - delete_edges_to(v) - delete_edges_from(v) - @vertices.delete(v) - @roots.delete(v) + invalidate_caches end # @group Querying the graph - # Returns a cycle if there is any. - def any_cycle - all_paths.lazy.map { |path| cycle_in_path(path) }.find(&:itself) - end - - # Given a potentially closed path, returns a cycle if there is any. - def cycle_in_path(path) - vertex = path.last - index = path.index(vertex) - - if index < path.size - 1 - path[index..-2] - end - end - - # Yields all paths (including potentially closed ones). - def all_paths - Enumerator.new do |y| - @vertices.keys.each do |vertex| - dfs_from(vertex) do |path| - y << path - end - end - end - end - - # Yields all paths (including potentially closed ones) starting from the given vertex. - def dfs_from(vertex, path_so_far = []) - new_path = path_so_far + [vertex] - yield(new_path) - - unless path_so_far.include?(vertex) - direct_successors_of(vertex).each do |next_vertex| - dfs_from(next_vertex, new_path) do |path| - yield(path) - end - end - end - end - # Returns the direct predecessors of the given vertex, i.e. the vertices # x where there is an edge from x to the given vertex y. # @@ -275,13 +181,6 @@ result end - # Returns all root vertices, i.e. vertices where no edge points to. - # - # @return [Set] The set of all root vertices in this graph. - def roots - @roots - end - private # Invalidates cached data. This method should be called when the internal diff -Nru nanoc-4.7.13/lib/nanoc/base/entities/item_collection.rb nanoc-4.8.0/lib/nanoc/base/entities/item_collection.rb --- nanoc-4.7.13/lib/nanoc/base/entities/item_collection.rb 2017-07-02 09:44:22.000000000 +0000 +++ nanoc-4.8.0/lib/nanoc/base/entities/item_collection.rb 2017-07-20 14:46:01.000000000 +0000 @@ -8,7 +8,7 @@ end def reference - :items + 'items' end end end diff -Nru nanoc-4.7.13/lib/nanoc/base/entities/item.rb nanoc-4.8.0/lib/nanoc/base/entities/item.rb --- nanoc-4.7.13/lib/nanoc/base/entities/item.rb 2017-07-02 09:44:22.000000000 +0000 +++ nanoc-4.8.0/lib/nanoc/base/entities/item.rb 2017-07-20 14:46:01.000000000 +0000 @@ -4,7 +4,7 @@ # @api private class Item < ::Nanoc::Int::Document def reference - [:item, identifier.to_s] + "item:#{identifier}" end end end diff -Nru nanoc-4.7.13/lib/nanoc/base/entities/item_rep.rb nanoc-4.8.0/lib/nanoc/base/entities/item_rep.rb --- nanoc-4.7.13/lib/nanoc/base/entities/item_rep.rb 2017-07-02 09:44:22.000000000 +0000 +++ nanoc-4.8.0/lib/nanoc/base/entities/item_rep.rb 2017-07-20 14:46:01.000000000 +0000 @@ -79,7 +79,7 @@ # Returns an object that can be used for uniquely identifying objects. def reference - [:item_rep, item.identifier, name] + "item_rep:#{item.identifier}:#{name}" end def inspect diff -Nru nanoc-4.7.13/lib/nanoc/base/entities/layout_collection.rb nanoc-4.8.0/lib/nanoc/base/entities/layout_collection.rb --- nanoc-4.7.13/lib/nanoc/base/entities/layout_collection.rb 2017-07-02 09:44:22.000000000 +0000 +++ nanoc-4.8.0/lib/nanoc/base/entities/layout_collection.rb 2017-07-20 14:46:01.000000000 +0000 @@ -8,7 +8,7 @@ end def reference - :layouts + 'layouts' end end end diff -Nru nanoc-4.7.13/lib/nanoc/base/entities/layout.rb nanoc-4.8.0/lib/nanoc/base/entities/layout.rb --- nanoc-4.7.13/lib/nanoc/base/entities/layout.rb 2017-07-02 09:44:22.000000000 +0000 +++ nanoc-4.8.0/lib/nanoc/base/entities/layout.rb 2017-07-20 14:46:01.000000000 +0000 @@ -4,7 +4,7 @@ # @api private class Layout < ::Nanoc::Int::Document def reference - [:layout, identifier.to_s] + "layout:#{identifier}" end end end diff -Nru nanoc-4.7.13/lib/nanoc/base/errors.rb nanoc-4.8.0/lib/nanoc/base/errors.rb --- nanoc-4.7.13/lib/nanoc/base/errors.rb 2017-07-02 09:44:22.000000000 +0000 +++ nanoc-4.8.0/lib/nanoc/base/errors.rb 2017-07-20 14:46:01.000000000 +0000 @@ -71,13 +71,14 @@ # Error that is raised during site compilation when an item (directly or # indirectly) includes its own item content, leading to endless recursion. class DependencyCycle < Generic - def initialize(graph) - cycle = graph.any_cycle + def initialize(stack) + start_idx = stack.index(stack.last) + cycle = stack[start_idx..-2] msg_bits = [] msg_bits << 'The site cannot be compiled because there is a dependency cycle:' msg_bits << '' - cycle.reverse_each.with_index do |r, i| + cycle.each.with_index do |r, i| msg_bits << " (#{i + 1}) item #{r.item.identifier}, rep #{r.name.inspect}, uses compiled content of" end msg_bits << msg_bits.pop + ' (1)' diff -Nru nanoc-4.7.13/lib/nanoc/base/feature.rb nanoc-4.8.0/lib/nanoc/base/feature.rb --- nanoc-4.7.13/lib/nanoc/base/feature.rb 2017-07-02 09:44:22.000000000 +0000 +++ nanoc-4.8.0/lib/nanoc/base/feature.rb 2017-07-20 14:46:01.000000000 +0000 @@ -90,5 +90,3 @@ end end end - -Nanoc::Feature.define('profiler', version: '4.7') diff -Nru nanoc-4.7.13/lib/nanoc/base/services/item_rep_selector.rb nanoc-4.8.0/lib/nanoc/base/services/item_rep_selector.rb --- nanoc-4.7.13/lib/nanoc/base/services/item_rep_selector.rb 2017-07-02 09:44:22.000000000 +0000 +++ nanoc-4.8.0/lib/nanoc/base/services/item_rep_selector.rb 2017-07-20 14:46:01.000000000 +0000 @@ -9,79 +9,58 @@ @reps = reps end - NONE = Object.new - - def each - graph = Nanoc::Int::DirectedGraph.new(@reps) - - prio_dependent = Set.new - prio_in_progress = Set.new - loop do - rep = find(graph, prio_dependent, prio_in_progress) - break if NONE.equal?(rep) - - begin - prio_in_progress << rep - yield(rep) - prio_in_progress.delete(rep) - graph.delete_vertex(rep) - rescue => e - handle_error(e, rep, graph, prio_dependent) - end + class MicroGraph + def initialize(reps) + @reps = Set.new(reps) + @stack = [] end - # Check whether everything was compiled - unless graph.vertices.empty? - raise Nanoc::Int::Errors::DependencyCycle.new(graph) - end - end - - def find(graph, prio_dependent, prio_in_progress) - if graph.roots.empty? - NONE - elsif prio_dependent.any? - find_prio(graph, prio_dependent, prio_dependent, prio_in_progress) - elsif prio_in_progress.any? - find_prio(graph, prio_in_progress, prio_dependent, prio_in_progress) - else - graph.roots.each { |e| break e } - end - end - - def find_prio(graph, prio, prio_dependent, prio_in_progress) - until prio.empty? - rep = prio.each { |e| break e } - if graph.roots.include?(rep) - return rep + def next + if @stack.any? + @stack.last + elsif @reps.any? + @reps.each { |rep| break rep }.tap do |rep| + @reps.delete(rep) + @stack.push(rep) + end else - prio.delete(rep) + nil end end - find(graph, prio_dependent, prio_in_progress) - end + def mark_ok + @stack.pop + end - def handle_error(e, rep, graph, prio_dependent) - actual_error = - if e.is_a?(Nanoc::Int::Errors::CompilationError) - e.unwrap - else - e + def mark_failed(dep) + if @stack.include?(dep) + raise Nanoc::Int::Errors::DependencyCycle.new(@stack + [dep]) end - if actual_error.is_a?(Nanoc::Int::Errors::UnmetDependency) - handle_dependency_error(actual_error, rep, graph, prio_dependent) - else - raise(e) + @reps.delete(dep) + @stack.push(dep) end end - def handle_dependency_error(e, rep, graph, prio_dependent) - other_rep = e.rep - prio_dependent << other_rep - graph.add_edge(other_rep, rep) - unless graph.vertices.include?(other_rep) - graph.add_vertex(other_rep) + def each + mg = MicroGraph.new(@reps) + + loop do + rep = mg.next + break if rep.nil? + + begin + yield(rep) + mg.mark_ok + rescue => e + actual_error = e.is_a?(Nanoc::Int::Errors::CompilationError) ? e.unwrap : e + + if actual_error.is_a?(Nanoc::Int::Errors::UnmetDependency) + mg.mark_failed(actual_error.rep) + else + raise(e) + end + end end end end diff -Nru nanoc-4.7.13/lib/nanoc/cli/commands/compile_listeners/stack_prof_profiler.rb nanoc-4.8.0/lib/nanoc/cli/commands/compile_listeners/stack_prof_profiler.rb --- nanoc-4.7.13/lib/nanoc/cli/commands/compile_listeners/stack_prof_profiler.rb 2017-07-02 09:44:22.000000000 +0000 +++ nanoc-4.8.0/lib/nanoc/cli/commands/compile_listeners/stack_prof_profiler.rb 1970-01-01 00:00:00.000000000 +0000 @@ -1,24 +0,0 @@ -# frozen_string_literal: true - -module Nanoc::CLI::Commands::CompileListeners - class StackProfProfiler < Abstract - PROFILE_FILE = 'tmp/stackprof_profile' - - # @see Listener#enable_for? - def self.enable_for?(command_runner) - command_runner.options.fetch(:profile, false) - end - - # @see Listener#start - def start - require 'stackprof' - StackProf.start(mode: :cpu) - end - - # @see Listener#stop - def stop - StackProf.stop - StackProf.results(PROFILE_FILE) - end - end -end diff -Nru nanoc-4.7.13/lib/nanoc/cli/commands/compile.rb nanoc-4.8.0/lib/nanoc/cli/commands/compile.rb --- nanoc-4.7.13/lib/nanoc/cli/commands/compile.rb 2017-07-02 09:44:22.000000000 +0000 +++ nanoc-4.8.0/lib/nanoc/cli/commands/compile.rb 2017-07-20 14:46:01.000000000 +0000 @@ -5,14 +5,12 @@ description <<~EOS Compile all items of the current site. EOS -flag nil, :profile, 'profile compilation' if Nanoc::Feature.enabled?(Nanoc::Feature::PROFILER) flag nil, :diff, 'generate diff' require_relative 'compile_listeners/abstract' require_relative 'compile_listeners/debug_printer' require_relative 'compile_listeners/diff_generator' require_relative 'compile_listeners/file_action_printer' -require_relative 'compile_listeners/stack_prof_profiler' require_relative 'compile_listeners/timing_recorder' module Nanoc::CLI::Commands @@ -43,7 +41,6 @@ def default_listener_classes [ - Nanoc::CLI::Commands::CompileListeners::StackProfProfiler, Nanoc::CLI::Commands::CompileListeners::DiffGenerator, Nanoc::CLI::Commands::CompileListeners::DebugPrinter, Nanoc::CLI::Commands::CompileListeners::TimingRecorder, diff -Nru nanoc-4.7.13/lib/nanoc/data_sources/filesystem.rb nanoc-4.8.0/lib/nanoc/data_sources/filesystem.rb --- nanoc-4.7.13/lib/nanoc/data_sources/filesystem.rb 2017-07-02 09:44:22.000000000 +0000 +++ nanoc-4.8.0/lib/nanoc/data_sources/filesystem.rb 2017-07-20 14:46:01.000000000 +0000 @@ -183,7 +183,7 @@ def attributes_checksum_data_for(proto_doc, content_filename, meta_filename) Digest::SHA1.digest( - YAML.dump( + Marshal.dump( attributes: proto_doc.attributes_checksum_data, extra_attributes: extra_attributes_for(content_filename, meta_filename), ), diff -Nru nanoc-4.7.13/lib/nanoc/filters/asciidoctor.rb nanoc-4.8.0/lib/nanoc/filters/asciidoctor.rb --- nanoc-4.7.13/lib/nanoc/filters/asciidoctor.rb 1970-01-01 00:00:00.000000000 +0000 +++ nanoc-4.8.0/lib/nanoc/filters/asciidoctor.rb 2017-07-20 14:46:01.000000000 +0000 @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +module Nanoc::Filters + class Asciidoctor < Nanoc::Filter + identifier :asciidoctor + + requires 'asciidoctor' + + def run(content, params = {}) + ::Asciidoctor.render(content, params) + end + end +end diff -Nru nanoc-4.7.13/lib/nanoc/filters.rb nanoc-4.8.0/lib/nanoc/filters.rb --- nanoc-4.7.13/lib/nanoc/filters.rb 2017-07-02 09:44:22.000000000 +0000 +++ nanoc-4.8.0/lib/nanoc/filters.rb 2017-07-20 14:46:01.000000000 +0000 @@ -5,6 +5,7 @@ end require_relative 'filters/asciidoc' +require_relative 'filters/asciidoctor' require_relative 'filters/bluecloth' require_relative 'filters/colorize_syntax' require_relative 'filters/coffeescript' diff -Nru nanoc-4.7.13/lib/nanoc/rule_dsl/rules_collection.rb nanoc-4.8.0/lib/nanoc/rule_dsl/rules_collection.rb --- nanoc-4.7.13/lib/nanoc/rule_dsl/rules_collection.rb 2017-07-02 09:44:22.000000000 +0000 +++ nanoc-4.8.0/lib/nanoc/rule_dsl/rules_collection.rb 2017-07-20 14:46:01.000000000 +0000 @@ -112,7 +112,7 @@ # # @return [Object] An unique reference to this object def reference - :rules + 'rules' end def inspect diff -Nru nanoc-4.7.13/lib/nanoc/version.rb nanoc-4.8.0/lib/nanoc/version.rb --- nanoc-4.7.13/lib/nanoc/version.rb 2017-07-02 09:44:22.000000000 +0000 +++ nanoc-4.8.0/lib/nanoc/version.rb 2017-07-20 14:46:01.000000000 +0000 @@ -2,5 +2,5 @@ module Nanoc # The current Nanoc version. - VERSION = '4.7.13' + VERSION = '4.8.0' end diff -Nru nanoc-4.7.13/NEWS.md nanoc-4.8.0/NEWS.md --- nanoc-4.7.13/NEWS.md 2017-07-02 09:44:22.000000000 +0000 +++ nanoc-4.8.0/NEWS.md 2017-07-20 14:46:01.000000000 +0000 @@ -1,5 +1,17 @@ # Nanoc news +## 4.8.0 (2017-07-17) + +Featured: + +* Added `asciidoctor` filter (#1199) + +## 4.7.14 (2017-07-16) + +Enhancements: + +* Various speed improvements (#1195, #1198) + ## 4.7.13 (2017-07-02) Enhancements: diff -Nru nanoc-4.7.13/spec/nanoc/base/directed_graph_spec.rb nanoc-4.8.0/spec/nanoc/base/directed_graph_spec.rb --- nanoc-4.7.13/spec/nanoc/base/directed_graph_spec.rb 2017-07-02 09:44:22.000000000 +0000 +++ nanoc-4.8.0/spec/nanoc/base/directed_graph_spec.rb 2017-07-20 14:46:01.000000000 +0000 @@ -1,401 +1,228 @@ # frozen_string_literal: true describe Nanoc::Int::DirectedGraph do - subject(:graph) { described_class.new([1, 2, 3]) } + subject(:graph) { described_class.new(%w[1 2 3]) } - describe '#inspect' do - subject { graph.inspect } + describe '#edges' do + subject { graph.edges } context 'empty graph' do - it { is_expected.to eq('Nanoc::Int::DirectedGraph()') } + it { is_expected.to be_empty } end - context 'one edge, no props' do + context 'graph with vertices, but no edges' do before do - graph.add_edge(1, 2) + graph.add_vertex('1') + graph.add_vertex('2') end - it { is_expected.to eq('Nanoc::Int::DirectedGraph(1 -> 2 props=nil)') } + it { is_expected.to be_empty } end - context 'two edges, no props' do + context 'graph with edges from previously added vertices' do before do - graph.add_edge(1, 2) - graph.add_edge(2, 3) + graph.add_vertex('1') + graph.add_vertex('2') + graph.add_vertex('3') + + graph.add_edge('1', '2') + graph.add_edge('1', '3') end - it { is_expected.to eq('Nanoc::Int::DirectedGraph(1 -> 2 props=nil, 2 -> 3 props=nil)') } + it { is_expected.to match_array([[0, 1, nil], [0, 2, nil]]) } end - context 'one edge, props' do + context 'graph with edges from new vertices' do before do - graph.add_edge(1, 2, props: 'giraffe') + graph.add_edge('1', '2') + graph.add_edge('1', '3') end - it { is_expected.to eq('Nanoc::Int::DirectedGraph(1 -> 2 props="giraffe")') } + it { is_expected.to match_array([[0, 1, nil], [0, 2, nil]]) } end - context 'two edges, props' do + context 'graph with edge props' do before do - graph.add_edge(1, 2, props: 'donkey') - graph.add_edge(2, 3, props: 'zebra') + graph.add_edge('1', '2', props: { name: 'Mr. C' }) + graph.add_edge('1', '3', props: { name: 'Cooper' }) end - it { is_expected.to eq('Nanoc::Int::DirectedGraph(1 -> 2 props="donkey", 2 -> 3 props="zebra")') } + it { is_expected.to match_array([[0, 1, { name: 'Mr. C' }], [0, 2, { name: 'Cooper' }]]) } end end - describe '#any_cycle' do - subject { graph.any_cycle } + describe '#props_for' do + subject { graph.props_for('1', '2') } - context 'no cycles' do + context 'no edge' do it { is_expected.to be_nil } end - context 'one cycle without head' do - before do - graph.add_edge(1, 2) - graph.add_edge(2, 1) + context 'edge, but no props' do + before { graph.add_edge('1', '2') } + it { is_expected.to be_nil } + end + + context 'edge with props' do + before { graph.add_edge('1', '2', props: { name: 'Mr. C' }) } + it { is_expected.to eq(name: 'Mr. C') } + + context 'deleted edge (#delete_edges_to)' do + before { graph.delete_edges_to('2') } + it { is_expected.to be_nil } end + end + end - it { is_expected.to eq([1, 2]) } + describe '#direct_predecessors_of' do + subject { graph.direct_predecessors_of('2') } + + context 'no edges' do + it { is_expected.to be_empty } + end + + context 'one edge to' do + before { graph.add_edge('1', '2') } + it { is_expected.to eq(['1']) } end - context 'one cycle with head' do + context 'two edges to' do before do - graph.add_edge(1, 2) - graph.add_edge(2, 3) - graph.add_edge(3, 2) + graph.add_edge('1', '2') + graph.add_edge('3', '2') end - it { is_expected.to eq([2, 3]) } + it { is_expected.to match_array(%w[1 3]) } end - context 'one cycle with tail' do - before do - graph.add_edge(1, 2) - graph.add_edge(2, 20) - graph.add_edge(20, 21) - graph.add_edge(2, 3) - graph.add_edge(3, 1) - end + context 'edge from' do + before { graph.add_edge('2', '3') } + it { is_expected.to be_empty } + end + end - it { is_expected.to eq([1, 2, 3]) } + describe '#direct_successors_of' do + subject { graph.direct_successors_of('2') } + + context 'no edges' do + it { is_expected.to be_empty } end - context 'large cycle' do - before do - graph.add_edge(1, 2) - graph.add_edge(2, 3) - graph.add_edge(3, 4) - graph.add_edge(4, 5) - graph.add_edge(5, 1) - end + context 'one edge to' do + before { graph.add_edge('1', '2') } + it { is_expected.to be_empty } + end - it { is_expected.to eq([1, 2, 3, 4, 5]) } + context 'one edge from' do + before { graph.add_edge('2', '3') } + it { is_expected.to eq(['3']) } end - context 'large cycle with head' do + context 'two edges from' do before do - graph.add_edge(1, 2) - graph.add_edge(2, 3) - graph.add_edge(3, 4) - graph.add_edge(4, 5) - graph.add_edge(5, 2) + graph.add_edge('2', '1') + graph.add_edge('2', '3') end - it { is_expected.to eq([2, 3, 4, 5]) } + it { is_expected.to match_array(%w[1 3]) } end end - describe '#all_paths' do - subject { graph.all_paths.to_a } + describe '#predecessors_of' do + subject { graph.predecessors_of('2') } - context 'no cycles' do - example do - expect(subject).to contain_exactly( - [1], - [2], - [3], - ) - end - end - - context 'one cycle without head' do - before do - graph.add_edge(1, 2) - graph.add_edge(2, 1) - end - - example do - expect(subject).to contain_exactly( - [1], - [1, 2], - [1, 2, 1], - [2], - [2, 1], - [2, 1, 2], - [3], - ) - end - end - - context 'one cycle with head' do - before do - graph.add_edge(1, 2) - graph.add_edge(2, 3) - graph.add_edge(3, 2) - end - - example do - expect(subject).to contain_exactly( - [1], - [1, 2], - [1, 2, 3], - [1, 2, 3, 2], - [2], - [2, 3], - [2, 3, 2], - [3], - [3, 2], - [3, 2, 3], - ) - end - end - - context 'one cycle with tail' do - before do - graph.add_edge(1, 2) - graph.add_edge(2, 20) - graph.add_edge(20, 21) - graph.add_edge(2, 3) - graph.add_edge(3, 1) - end - - example do - expect(subject).to contain_exactly( - [1], - [1, 2], - [1, 2, 20], - [1, 2, 20, 21], - [1, 2, 3], - [1, 2, 3, 1], - [2], - [2, 20], - [2, 20, 21], - [2, 3], - [2, 3, 1], - [2, 3, 1, 2], - [3], - [3, 1], - [3, 1, 2], - [3, 1, 2, 20], - [3, 1, 2, 20, 21], - [3, 1, 2, 3], - [20], - [20, 21], - [21], - ) - end - end - - context 'large cycle' do - before do - graph.add_edge(1, 2) - graph.add_edge(2, 3) - graph.add_edge(3, 4) - graph.add_edge(4, 5) - graph.add_edge(5, 1) - end - - example do - expect(subject).to contain_exactly( - [1], - [1, 2], - [1, 2, 3], - [1, 2, 3, 4], - [1, 2, 3, 4, 5], - [1, 2, 3, 4, 5, 1], - [2], - [2, 3], - [2, 3, 4], - [2, 3, 4, 5], - [2, 3, 4, 5, 1], - [2, 3, 4, 5, 1, 2], - [3], - [3, 4], - [3, 4, 5], - [3, 4, 5, 1], - [3, 4, 5, 1, 2], - [3, 4, 5, 1, 2, 3], - [4], - [4, 5], - [4, 5, 1], - [4, 5, 1, 2], - [4, 5, 1, 2, 3], - [4, 5, 1, 2, 3, 4], - [5], - [5, 1], - [5, 1, 2], - [5, 1, 2, 3], - [5, 1, 2, 3, 4], - [5, 1, 2, 3, 4, 5], - ) - end - end - - context 'large cycle with head' do - before do - graph.add_edge(1, 2) - graph.add_edge(2, 3) - graph.add_edge(3, 4) - graph.add_edge(4, 5) - graph.add_edge(5, 2) - end - - example do - expect(subject).to contain_exactly( - [1], - [1, 2], - [1, 2, 3], - [1, 2, 3, 4], - [1, 2, 3, 4, 5], - [1, 2, 3, 4, 5, 2], - [2], - [2, 3], - [2, 3, 4], - [2, 3, 4, 5], - [2, 3, 4, 5, 2], - [3], - [3, 4], - [3, 4, 5], - [3, 4, 5, 2], - [3, 4, 5, 2, 3], - [4], - [4, 5], - [4, 5, 2], - [4, 5, 2, 3], - [4, 5, 2, 3, 4], - [5], - [5, 2], - [5, 2, 3], - [5, 2, 3, 4], - [5, 2, 3, 4, 5], - ) + context 'no predecessors' do + before do + graph.add_edge('2', '3') end + + it { is_expected.to be_empty } end - end - describe '#dfs_from' do - subject do - [].tap do |ps| - graph.dfs_from(1) do |p| - ps << p - end + context 'direct predecessor' do + before do + graph.add_edge('2', '3') + graph.add_edge('1', '2') + end + + context 'no indirect predecessors' do + it { is_expected.to match_array(['1']) } end - end - context 'no cycles' do - example do - expect(subject).to contain_exactly( - [1], - ) + context 'indirect predecessors' do + before { graph.add_edge('3', '1') } + it { is_expected.to match_array(%w[1 2 3]) } end end + end + + describe '#successors_of' do + subject { graph.successors_of('2') } - context 'one cycle without head' do + context 'no successors' do before do - graph.add_edge(1, 2) - graph.add_edge(2, 1) + graph.add_edge('1', '2') end - example do - expect(subject).to contain_exactly( - [1], - [1, 2], - [1, 2, 1], - ) - end + it { is_expected.to be_empty } end - context 'one cycle with head' do + context 'direct predecessor' do before do - graph.add_edge(1, 2) - graph.add_edge(2, 3) - graph.add_edge(3, 2) + graph.add_edge('1', '2') + graph.add_edge('2', '3') end - example do - expect(subject).to contain_exactly( - [1], - [1, 2], - [1, 2, 3], - [1, 2, 3, 2], - ) + context 'no indirect successors' do + it { is_expected.to match_array(['3']) } + end + + context 'indirect successors' do + before { graph.add_edge('3', '1') } + it { is_expected.to match_array(%w[1 2 3]) } end end + end - context 'one cycle with tail' do + describe '#inspect' do + subject { graph.inspect } + + context 'empty graph' do + it { is_expected.to eq('Nanoc::Int::DirectedGraph()') } + end + + context 'one edge, no props' do before do - graph.add_edge(1, 2) - graph.add_edge(2, 20) - graph.add_edge(20, 21) - graph.add_edge(2, 3) - graph.add_edge(3, 1) + graph.add_edge('1', '2') end - example do - expect(subject).to contain_exactly( - [1], - [1, 2], - [1, 2, 20], - [1, 2, 20, 21], - [1, 2, 3], - [1, 2, 3, 1], - ) - end + it { is_expected.to eq('Nanoc::Int::DirectedGraph("1" -> "2" props=nil)') } end - context 'large cycle' do + context 'two edges, no props' do before do - graph.add_edge(1, 2) - graph.add_edge(2, 3) - graph.add_edge(3, 4) - graph.add_edge(4, 5) - graph.add_edge(5, 1) + graph.add_edge('1', '2') + graph.add_edge('2', '3') end - example do - expect(subject).to contain_exactly( - [1], - [1, 2], - [1, 2, 3], - [1, 2, 3, 4], - [1, 2, 3, 4, 5], - [1, 2, 3, 4, 5, 1], - ) - end + it { is_expected.to eq('Nanoc::Int::DirectedGraph("1" -> "2" props=nil, "2" -> "3" props=nil)') } end - context 'large cycle with head' do + context 'one edge, props' do before do - graph.add_edge(1, 2) - graph.add_edge(2, 3) - graph.add_edge(3, 4) - graph.add_edge(4, 5) - graph.add_edge(5, 2) + graph.add_edge('1', '2', props: 'giraffe') end - example do - expect(subject).to contain_exactly( - [1], - [1, 2], - [1, 2, 3], - [1, 2, 3, 4], - [1, 2, 3, 4, 5], - [1, 2, 3, 4, 5, 2], - ) + it { is_expected.to eq('Nanoc::Int::DirectedGraph("1" -> "2" props="giraffe")') } + end + + context 'two edges, props' do + before do + graph.add_edge('1', '2', props: 'donkey') + graph.add_edge('2', '3', props: 'zebra') end + + it { is_expected.to eq('Nanoc::Int::DirectedGraph("1" -> "2" props="donkey", "2" -> "3" props="zebra")') } end end end diff -Nru nanoc-4.7.13/spec/nanoc/base/entities/identifiable_collection_spec.rb nanoc-4.8.0/spec/nanoc/base/entities/identifiable_collection_spec.rb --- nanoc-4.7.13/spec/nanoc/base/entities/identifiable_collection_spec.rb 2017-07-02 09:44:22.000000000 +0000 +++ nanoc-4.8.0/spec/nanoc/base/entities/identifiable_collection_spec.rb 2017-07-20 14:46:01.000000000 +0000 @@ -139,12 +139,12 @@ end describe Nanoc::Int::ItemCollection do - let(:expected_reference) { :items } + let(:expected_reference) { 'items' } it_behaves_like 'a generic identifiable collection' end describe Nanoc::Int::LayoutCollection do - let(:expected_reference) { :layouts } + let(:expected_reference) { 'layouts' } it_behaves_like 'a generic identifiable collection' end end diff -Nru nanoc-4.7.13/spec/nanoc/base/entities/item_spec.rb nanoc-4.8.0/spec/nanoc/base/entities/item_spec.rb --- nanoc-4.7.13/spec/nanoc/base/entities/item_spec.rb 2017-07-02 09:44:22.000000000 +0000 +++ nanoc-4.8.0/spec/nanoc/base/entities/item_spec.rb 2017-07-20 14:46:01.000000000 +0000 @@ -7,7 +7,7 @@ let(:item) { described_class.new('hi', {}, '/foo.md') } it 'has the proper reference' do - expect(item.reference).to eql([:item, '/foo.md']) + expect(item.reference).to eql('item:/foo.md') end end end diff -Nru nanoc-4.7.13/spec/nanoc/base/entities/layout_spec.rb nanoc-4.8.0/spec/nanoc/base/entities/layout_spec.rb --- nanoc-4.7.13/spec/nanoc/base/entities/layout_spec.rb 2017-07-02 09:44:22.000000000 +0000 +++ nanoc-4.8.0/spec/nanoc/base/entities/layout_spec.rb 2017-07-20 14:46:01.000000000 +0000 @@ -7,7 +7,7 @@ let(:layout) { described_class.new('hi', {}, '/foo.md') } it 'has the proper reference' do - expect(layout.reference).to eql([:layout, '/foo.md']) + expect(layout.reference).to eql('layout:/foo.md') end end end diff -Nru nanoc-4.7.13/spec/nanoc/base/errors/dependency_cycle_spec.rb nanoc-4.8.0/spec/nanoc/base/errors/dependency_cycle_spec.rb --- nanoc-4.7.13/spec/nanoc/base/errors/dependency_cycle_spec.rb 2017-07-02 09:44:22.000000000 +0000 +++ nanoc-4.8.0/spec/nanoc/base/errors/dependency_cycle_spec.rb 2017-07-20 14:46:01.000000000 +0000 @@ -1,16 +1,17 @@ # frozen_string_literal: true describe Nanoc::Int::Errors::DependencyCycle do - subject(:error) { described_class.new(graph) } + subject(:error) { described_class.new(stack) } - let(:graph) do - Nanoc::Int::DirectedGraph.new([]).tap do |g| - g.add_edge(rep_a, rep_b) - g.add_edge(rep_b, rep_c) - g.add_edge(rep_c, rep_d) - g.add_edge(rep_d, rep_e) - g.add_edge(rep_e, rep_b) - end + let(:stack) do + [ + rep_a, + rep_b, + rep_c, + rep_d, + rep_e, + rep_b, + ] end let(:rep_a) { Nanoc::Int::ItemRep.new(Nanoc::Int::Item.new('a', {}, '/a.md'), :default) } @@ -23,10 +24,10 @@ expected = <<~EOS The site cannot be compiled because there is a dependency cycle: - (1) item /e.md, rep :default, uses compiled content of - (2) item /d.md, rep :default, uses compiled content of - (3) item /c.md, rep :default, uses compiled content of - (4) item /b.md, rep :default, uses compiled content of (1) + (1) item /b.md, rep :default, uses compiled content of + (2) item /c.md, rep :default, uses compiled content of + (3) item /d.md, rep :default, uses compiled content of + (4) item /e.md, rep :default, uses compiled content of (1) EOS expect(error.message).to eql(expected) diff -Nru nanoc-4.7.13/spec/nanoc/base/services/item_rep_selector_spec.rb nanoc-4.8.0/spec/nanoc/base/services/item_rep_selector_spec.rb --- nanoc-4.7.13/spec/nanoc/base/services/item_rep_selector_spec.rb 2017-07-02 09:44:22.000000000 +0000 +++ nanoc-4.8.0/spec/nanoc/base/services/item_rep_selector_spec.rb 2017-07-20 14:46:01.000000000 +0000 @@ -111,6 +111,47 @@ end end + describe 'cycle' do + context 'dependency on self' do + subject do + selector.each { |r| raise Nanoc::Int::Errors::UnmetDependency.new(r) } + end + + example do + expect { subject }.to raise_error(Nanoc::Int::Errors::DependencyCycle, <<~EOS) + The site cannot be compiled because there is a dependency cycle: + + (1) item /foo.md, rep :a, uses compiled content of (1) + EOS + end + end + + context 'cycle with three dependencies' do + subject do + selector.each do |r| + case r + when reps_array[0] + raise Nanoc::Int::Errors::UnmetDependency.new(reps_array[1]) + when reps_array[1] + raise Nanoc::Int::Errors::UnmetDependency.new(reps_array[2]) + when reps_array[2] + raise Nanoc::Int::Errors::UnmetDependency.new(reps_array[0]) + end + end + end + + example do + expect { subject }.to raise_error(Nanoc::Int::Errors::DependencyCycle, <<~EOS) + The site cannot be compiled because there is a dependency cycle: + + (1) item /foo.md, rep :a, uses compiled content of + (2) item /foo.md, rep :b, uses compiled content of + (3) item /foo.md, rep :c, uses compiled content of (1) + EOS + end + end + end + describe 'yield order' do context 'linear dependencies' do let(:dependencies) do diff -Nru nanoc-4.7.13/spec/nanoc/filters/asciidoctor_spec.rb nanoc-4.8.0/spec/nanoc/filters/asciidoctor_spec.rb --- nanoc-4.7.13/spec/nanoc/filters/asciidoctor_spec.rb 1970-01-01 00:00:00.000000000 +0000 +++ nanoc-4.8.0/spec/nanoc/filters/asciidoctor_spec.rb 2017-07-20 14:46:01.000000000 +0000 @@ -0,0 +1,12 @@ +# frozen_string_literal: true + +describe Nanoc::Filters::Asciidoctor do + subject { filter.setup_and_run(input, params) } + + let(:filter) { described_class.new } + + let(:input) { '== Blah blah' } + let(:params) { {} } + + it { is_expected.to match(%r{

Blah blah

}) } +end diff -Nru nanoc-4.7.13/test/base/test_directed_graph.rb nanoc-4.8.0/test/base/test_directed_graph.rb --- nanoc-4.7.13/test/base/test_directed_graph.rb 2017-07-02 09:44:22.000000000 +0000 +++ nanoc-4.8.0/test/base/test_directed_graph.rb 2017-07-20 14:46:01.000000000 +0000 @@ -3,108 +3,6 @@ require 'helper' class Nanoc::Int::DirectedGraphTest < Nanoc::TestCase - def test_direct_predecessors - graph = Nanoc::Int::DirectedGraph.new([1, 2, 3]) - graph.add_edge(1, 2) - graph.add_edge(2, 3) - - assert_equal [], graph.direct_predecessors_of(1) - assert_equal [1], graph.direct_predecessors_of(2) - assert_equal [2], graph.direct_predecessors_of(3) - end - - def test_predecessors - graph = Nanoc::Int::DirectedGraph.new([1, 2, 3]) - graph.add_edge(1, 2) - graph.add_edge(2, 3) - - assert_equal [], graph.predecessors_of(1).sort - assert_equal [1], graph.predecessors_of(2).sort - assert_equal [1, 2], graph.predecessors_of(3).sort - end - - def test_direct_successors - graph = Nanoc::Int::DirectedGraph.new([1, 2, 3]) - graph.add_edge(1, 2) - graph.add_edge(2, 3) - - assert_equal [2], graph.direct_successors_of(1) - assert_equal [3], graph.direct_successors_of(2) - assert_equal [], graph.direct_successors_of(3) - end - - def test_successors - graph = Nanoc::Int::DirectedGraph.new([1, 2, 3]) - graph.add_edge(1, 2) - graph.add_edge(2, 3) - - assert_equal [2, 3], graph.successors_of(1).sort - assert_equal [3], graph.successors_of(2).sort - assert_equal [], graph.successors_of(3).sort - end - - def test_edges - graph = Nanoc::Int::DirectedGraph.new([1, 2, 3]) - graph.add_edge(1, 2) - graph.add_edge(2, 3) - - assert_equal [[0, 1, nil], [1, 2, nil]], graph.edges.sort - end - - def test_edges_with_new_vertices - graph = Nanoc::Int::DirectedGraph.new([1]) - assert_equal [1], graph.vertices - graph.add_edge(1, 2) - assert_equal [1, 2], graph.vertices - graph.add_edge(3, 2) - assert_equal [1, 2, 3], graph.vertices - - assert_equal [[0, 1, nil], [2, 1, nil]], graph.edges.sort - end - - def test_edge_with_props - graph = Nanoc::Int::DirectedGraph.new([1, 2, 3]) - graph.add_edge(1, 2, props: { donkey: 14 }) - graph.add_edge(2, 3, props: { giraffe: 3 }) - - assert_equal [[0, 1, { donkey: 14 }], [1, 2, { giraffe: 3 }]], graph.edges.sort - end - - def test_props_for - graph = Nanoc::Int::DirectedGraph.new([1, 2, 3, 4]) - graph.add_edge(1, 2, props: { donkey: 14 }) - graph.add_edge(2, 3, props: { giraffe: 3 }) - graph.add_edge(3, 4) - - assert_equal({ donkey: 14 }, graph.props_for(1, 2)) - assert_equal({ giraffe: 3 }, graph.props_for(2, 3)) - assert_equal(nil, graph.props_for(3, 4)) - end - - def test_props_for_with_deleted_edge - graph = Nanoc::Int::DirectedGraph.new([1, 2]) - graph.add_edge(1, 2, props: { donkey: 14 }) - graph.delete_edge(1, 2) - - assert_equal(nil, graph.props_for(1, 2)) - end - - def test_props_for_with_deleted_edges_from - graph = Nanoc::Int::DirectedGraph.new([1, 2]) - graph.add_edge(1, 2, props: { donkey: 14 }) - graph.delete_edges_from(1) - - assert_equal(nil, graph.props_for(1, 2)) - end - - def test_props_for_with_deleted_edges_to - graph = Nanoc::Int::DirectedGraph.new([1, 2]) - graph.add_edge(1, 2, props: { donkey: 14 }) - graph.delete_edges_to(2) - - assert_equal(nil, graph.props_for(1, 2)) - end - def test_add_edge graph = Nanoc::Int::DirectedGraph.new([1, 2, 3]) @@ -126,58 +24,6 @@ assert graph.vertices.include?(3) end - def test_delete_edge - graph = Nanoc::Int::DirectedGraph.new([1, 2, 3]) - graph.add_edge(1, 2) - - assert_equal [2], graph.successors_of(1) - assert_equal [1], graph.predecessors_of(2) - - graph.delete_edge(1, 2) - - assert_equal [], graph.successors_of(1) - assert_equal [], graph.predecessors_of(2) - end - - def test_delete_edges_from - graph = Nanoc::Int::DirectedGraph.new([1, 2, 3]) - - graph.add_edge(1, 2) - graph.add_edge(2, 1) - graph.add_edge(2, 3) - graph.add_edge(3, 2) - graph.add_edge(1, 3) - graph.add_edge(3, 1) - - assert_equal [2, 3], graph.direct_predecessors_of(1).sort - assert_equal [2, 3], graph.direct_successors_of(1).sort - assert_equal [1, 3], graph.direct_predecessors_of(2).sort - assert_equal [1, 3], graph.direct_successors_of(2).sort - assert_equal [1, 2], graph.direct_predecessors_of(3).sort - assert_equal [1, 2], graph.direct_successors_of(3).sort - assert_equal Set.new([]), graph.roots - - graph.delete_edges_from(1) - - assert_equal [2, 3], graph.direct_predecessors_of(1).sort - assert_equal [], graph.direct_successors_of(1).sort - assert_equal [3], graph.direct_predecessors_of(2).sort - assert_equal [1, 3], graph.direct_successors_of(2).sort - assert_equal [2], graph.direct_predecessors_of(3).sort - assert_equal [1, 2], graph.direct_successors_of(3).sort - assert_equal Set.new([]), graph.roots - - graph.delete_edges_from(2) - - assert_equal [3], graph.direct_predecessors_of(1).sort - assert_equal [], graph.direct_successors_of(1).sort - assert_equal [3], graph.direct_predecessors_of(2).sort - assert_equal [], graph.direct_successors_of(2).sort - assert_equal [], graph.direct_predecessors_of(3).sort - assert_equal [1, 2], graph.direct_successors_of(3).sort - assert_equal Set.new([3]), graph.roots - end - def test_delete_edges_to graph = Nanoc::Int::DirectedGraph.new([1, 2, 3]) @@ -194,7 +40,6 @@ assert_equal [1, 3], graph.direct_successors_of(2).sort assert_equal [1, 2], graph.direct_predecessors_of(3).sort assert_equal [1, 2], graph.direct_successors_of(3).sort - assert_equal Set.new([]), graph.roots graph.delete_edges_to(1) @@ -204,7 +49,6 @@ assert_equal [3], graph.direct_successors_of(2).sort assert_equal [1, 2], graph.direct_predecessors_of(3).sort assert_equal [2], graph.direct_successors_of(3).sort - assert_equal Set.new([1]), graph.roots graph.delete_edges_to(2) @@ -214,38 +58,6 @@ assert_equal [3], graph.direct_successors_of(2).sort assert_equal [1, 2], graph.direct_predecessors_of(3).sort assert_equal [], graph.direct_successors_of(3).sort - assert_equal Set.new([1, 2]), graph.roots - end - - def test_delete_vertex - graph = Nanoc::Int::DirectedGraph.new([1, 2, 3]) - - graph.add_edge(1, 2) - graph.add_edge(2, 1) - graph.add_edge(2, 3) - graph.add_edge(3, 2) - graph.add_edge(1, 3) - graph.add_edge(3, 1) - - graph.delete_vertex(2) - - assert_equal [3], graph.direct_predecessors_of(1).sort - assert_equal [3], graph.direct_successors_of(1).sort - assert_equal [1], graph.direct_predecessors_of(3).sort - assert_equal [1], graph.direct_successors_of(3).sort - assert_equal Set.new([]), graph.roots - end - - def test_delete_vertex_resulting_roots - graph = Nanoc::Int::DirectedGraph.new([1, 2, 3]) - assert_equal Set.new([1, 2, 3]), graph.roots - - graph.add_edge(1, 2) - graph.add_edge(2, 3) - assert_equal Set.new([1]), graph.roots - - graph.delete_vertex(2) - assert_equal Set.new([1, 3]), graph.roots end def test_should_return_empty_array_for_nonexistant_vertices @@ -257,74 +69,6 @@ assert_equal [], graph.successors_of(4) end - def test_roots_after_init - graph = Nanoc::Int::DirectedGraph.new([1, 2, 3]) - - assert_equal Set.new([1, 2, 3]), graph.roots - end - - def test_roots_after_adding_edge - graph = Nanoc::Int::DirectedGraph.new([1, 2, 3]) - graph.add_edge(1, 2) - assert_equal Set.new([1, 3]), graph.roots - - graph = Nanoc::Int::DirectedGraph.new([1, 2, 3]) - graph.add_edge(1, 3) - assert_equal Set.new([1, 2]), graph.roots - - graph = Nanoc::Int::DirectedGraph.new([1, 2, 3]) - graph.add_edge(2, 1) - assert_equal Set.new([2, 3]), graph.roots - - graph = Nanoc::Int::DirectedGraph.new([1, 2, 3]) - graph.add_edge(1, 2) - graph.add_edge(2, 3) - assert_equal Set.new([1]), graph.roots - - graph = Nanoc::Int::DirectedGraph.new([1, 2, 3]) - graph.add_edge(1, 2) - graph.add_edge(2, 3) - graph.add_edge(3, 1) - assert_equal Set.new([]), graph.roots - end - - def test_roots_after_removing_edge - graph = Nanoc::Int::DirectedGraph.new([1, 2, 3]) - graph.add_edge(1, 2) - graph.delete_edge(1, 2) - assert_equal Set.new([1, 2, 3]), graph.roots - - graph = Nanoc::Int::DirectedGraph.new([1, 2, 3]) - graph.add_edge(1, 3) - assert_equal Set.new([1, 2]), graph.roots - graph.delete_edge(1, 2) # no such edge - assert_equal Set.new([1, 2]), graph.roots - - graph = Nanoc::Int::DirectedGraph.new([1, 2, 3]) - graph.add_edge(2, 1) - graph.delete_edge(2, 1) - assert_equal Set.new([1, 2, 3]), graph.roots - - graph = Nanoc::Int::DirectedGraph.new([1, 2, 3]) - graph.add_edge(1, 2) - graph.add_edge(2, 3) - graph.delete_edge(1, 2) - assert_equal Set.new([1, 2]), graph.roots - graph.delete_edge(2, 3) - assert_equal Set.new([1, 2, 3]), graph.roots - - graph = Nanoc::Int::DirectedGraph.new([1, 2, 3]) - graph.add_edge(1, 2) - graph.add_edge(2, 3) - graph.add_edge(3, 1) - graph.delete_edge(1, 2) - assert_equal Set.new([2]), graph.roots - graph.delete_edge(2, 3) - assert_equal Set.new([2, 3]), graph.roots - graph.delete_edge(3, 1) - assert_equal Set.new([1, 2, 3]), graph.roots - end - def test_example YARD.parse(LIB_DIR + '/nanoc/base/entities/directed_graph.rb') assert_examples_correct 'Nanoc::Int::DirectedGraph'