Skip to content

Commit

Permalink
DOTScript ignores types with empty data
Browse files Browse the repository at this point in the history
  • Loading branch information
markus1189 committed Jul 7, 2012
1 parent 9c0898a commit 7504cb2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
6 changes: 4 additions & 2 deletions lib/graphviz/dot_script.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -10,19 +10,21 @@ def initialize
end end


def append(line) def append(line)
@script << assure_ends_with(line, "\n") @script << assure_ends_with(line.to_s,"\n")


self self
end end
alias :<< :append alias :<< :append


def prepend(line) def prepend(line)
@script = assure_ends_with(line,"\n") + @script @script = assure_ends_with(line.to_s,"\n") + @script


self self
end end


def add_type(type, data) def add_type(type, data)
return self if data.empty?

case type case type
when "graph_attr" when "graph_attr"
append_statement(" " + data) append_statement(" " + data)
Expand Down
7 changes: 6 additions & 1 deletion test/test_dot_script.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -32,7 +32,12 @@
script.to_s.must_match(/\s*node\s*\[\s*#{data}\s*\]\s*/m) script.to_s.must_match(/\s*node\s*\[\s*#{data}\s*\]\s*/m)
end end


it "does nothing if data is empty" do
script.add_type("anything", "")
script.to_s.must_be :empty?
end

it "raises an argument error on unknown types" do it "raises an argument error on unknown types" do
-> { script.add_type("invalid", "") }.must_raise(ArgumentError) -> { script.add_type("invalid", "some data") }.must_raise(ArgumentError)
end end
end end

0 comments on commit 7504cb2

Please sign in to comment.