Permalink
Browse files

Treat numbers with parent nodes as nodes, not labels

This fixes a regression caused by
e450c43, which was fixing #7.
  • Loading branch information...
aroben committed Apr 2, 2012
1 parent 766af71 commit bac6201a675598c77b2ddae0345753a093aa186b
Showing with 16 additions and 2 deletions.
  1. +1 −1 lib/asciidag.rb
  2. +15 −1 test/parser_test.rb
View
@@ -34,7 +34,7 @@ def initialize(nodes)
nodes.each_with_index do |node, i|
node.id = "node#{i}"
end
- @branch_labels, @nodes = nodes.partition { |node| node.label =~ /[a-z]{2,}|\d/ }
+ @branch_labels, @nodes = nodes.partition { |node| node.label =~ /[a-z]{2,}/ || node.label =~ /\d/ && node.parents.length == 0 }
end
def dot
View
@@ -82,6 +82,12 @@
\ /
A---B---C----------------D---E <-- fixed-up topic branch
EOF
+
+ @graph12 = AsciiDag.parse <<'EOF'
+ o---o---o---B
+ /
+ ---o---1---o---o---o---A
+EOF
end
test 'parses nodes' do
@@ -207,12 +213,20 @@
assert_equal [d], h.parents
end
- test 'should treat numbers as labels' do
+ test 'should treat numbers with no parents as labels' do
six = find_branch_label @graph10, '6'
assert_not_nil six
seven = find_node @graph10, '7'
assert_nil seven
+
+ one = find_node @graph12, '1'
+ assert_not_nil one
+ os = find_all_nodes @graph12, 'o'
+ assert_equal 7, os.length
+
+ assert_equal [one], os[1].parents
+ assert_equal [os[0]], one.parents
end
test 'allows hyphens in arrowed branch labels' do

0 comments on commit bac6201

Please sign in to comment.