File: test_dot_script.rb

package info (click to toggle)
ruby-graphviz 1.2.5-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 1,216 kB
  • sloc: ruby: 7,685; xml: 26; makefile: 17
file content (47 lines) | stat: -rw-r--r-- 1,191 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
require 'helper'

class GraphVizDOTScriptTest < Test::Unit::TestCase
  def setup
    @script = GraphViz::DOTScript.new
  end

  def test_appends_a_newline_character_if_it_is_missing
    str = "Test without newline"
    @script.append(str)
    assert_equal @script.to_s, str + "\n"
  end

  def test_does_not_append_a_newline_if_already_present
    str = "Linebreak follows at my tail:\n"
    @script.append(str)
    assert_equal @script.to_s, str
  end

  def test_can_prepend_lines_to_its_content
    start_content = "I want to be at the top!\n"
    additional_content = "No way!\n"

    @script.append(start_content)
    @script.prepend(additional_content)

    assert_equal @script.to_s, additional_content + start_content
  end

  def test_can_add_types_with_data
    data = "some random data"
    @script.add_type("node_attr", data)
    assert_match(/\s*node\s*\[\s*#{data}\s*\]\s*/, @script.to_s)
  end

  def test_does_nothing_if_data_is_empty
    @script.add_type("anything", "")
    assert_equal true, @script.to_s.empty?
  end

  def test_raises_an_argument_error_on_unknown_types
    assert_raise ArgumentError do
      @script.add_type("invalid", "some data")
    end
  end
end