class TestDotGraph

Tests for DOT::Graph

Public Instance Methods

test_element_containment() click to toggle source
# File test/rdot_test.rb, line 511
def test_element_containment
  node1 = DOT::Node.new('name' => 'test_node1')
  node2 = DOT::Node.new('name' => 'test_node2')

  graph = DOT::Graph.new('name' => 'test_graph')
  assert_nil(graph.pop)
  assert_equal(graph, graph.push(node1))
  assert_equal(graph, graph << node2)
  graph.each_element do |element|
    assert([node1, node2].include?(element))
  end
  assert_equal(node2, graph.pop)
  assert_equal(node1, graph.pop)
  assert_nil(graph.pop)

  graph = DOT::Graph.new('name' => 'test_graph', 'elements' => [node1])
  assert_equal(node1, graph.pop)
  assert_nil(graph.pop)
end
test_graph_statement() click to toggle source
# File test/rdot_test.rb, line 367
def test_graph_statement
  graph = DOT::Graph.new()
  dot   = graph.to_s
  assert_match(dot, /^\s*graph /)
end
test_label_quoting() click to toggle source
# File test/rdot_test.rb, line 419
def test_label_quoting
  node = DOT::Graph.new({ "name" => "test_name", "label" => "Label with spaces" })
  dot  = node.to_s
  assert_match(dot, /label\s*=\s*"Label with spaces"/)

  node = DOT::Graph.new({ "name" => "test_name", "label" => "Label with \"quotes\"" })
  dot  = node.to_s
  assert_match(dot, /label\s*=\s*"Label with \\"quotes\\""/)

  node = DOT::Graph.new({ "name" => "test_name", "label" => "Label with \\backslashes\\" })
  dot  = node.to_s
  assert_match(dot, /label\s*=\s*"Label with \\\\backslashes\\\\"/)

  node = DOT::Graph.new({ "name" => "test_name", "label" => "Label with\nembedded\nnewlines" })
  dot  = node.to_s
  assert_match(dot, /label\s*=\s*"Label with\\nembedded\\nnewlines"/)

  node = DOT::Graph.new({ "name" => "test_name", "label" => "Label_with_a_trailing_newline\n" })
  dot  = node.to_s
  assert_match(dot, /label\s*=\s*"Label_with_a_trailing_newline\\n"/)

  node = DOT::Graph.new({ "name" => "test_name", "label" => "Left justified label\\l" })
  dot  = node.to_s
  assert_match(dot, /label\s*=\s*"Left justified label\\l"/)

  node = DOT::Graph.new({ "name" => "test_name", "label" => "Right justified label\\r" })
  dot  = node.to_s
  assert_match(dot, /label\s*=\s*"Right justified label\\r"/)

  node = DOT::Graph.new({ "name" => "test_name", "label" => "123.456" })
  dot  = node.to_s
  assert_match(dot, /label\s*=\s*123.456/)

  node = DOT::Graph.new({ "name" => "test_name", "label" => ".456" })
  dot  = node.to_s
  assert_match(dot, /label\s*=\s*.456/)

  node = DOT::Graph.new({ "name" => "test_name", "label" => "-.456" })
  dot  = node.to_s
  assert_match(dot, /label\s*=\s*-.456/)

  node = DOT::Graph.new({ "name" => "test_name", "label" => "-456" })
  dot  = node.to_s
  assert_match(dot, /label\s*=\s*-456/)

  node = DOT::Graph.new({ "name" => "test_name", "label" => "-123.456" })
  dot  = node.to_s
  assert_match(dot, /label\s*=\s*-123.456/)

  node = DOT::Graph.new({ "name" => "test_name", "label" => "<html><head><title>test</title></head>\n<body>text</body></html>" })
  dot  = node.to_s
  assert_match(dot, /label\s*=\s*<html><head><title>test<\/title><\/head>\n<body>text<\/body><\/html>/)
end
test_name_quoting() click to toggle source
# File test/rdot_test.rb, line 373
def test_name_quoting
  node = DOT::Graph.new({ "name" => "Name with spaces" })
  dot  = node.to_s
  assert_match(dot, /^graph "Name with spaces" \{$/)

  node = DOT::Graph.new({ "name" => "Name with \"quotes\"" })
  dot  = node.to_s
  assert_match(dot, /^graph "Name with \\"quotes\\"" \{$/)

  node = DOT::Graph.new({ "name" => "Name with \\backslashes\\" })
  dot  = node.to_s
  assert_match(dot, /^graph "Name with \\\\backslashes\\\\" \{$/)

  node = DOT::Graph.new({ "name" => "Name with\nembedded\nnewlines" })
  dot  = node.to_s
  assert_match(dot, /\A.*"Name with\nembedded\nnewlines".*\Z/m)

  node = DOT::Graph.new({ "name" => "Name_with_trailing_newline\n" })
  dot  = node.to_s
  assert_match(dot, /\A.*"Name_with_trailing_newline\n".*\Z/m)

  node = DOT::Graph.new({ "name" => "123.456" })
  dot  = node.to_s
  assert_match(dot, /^graph 123.456 \{$/)

  node = DOT::Graph.new({ "name" => ".456" })
  dot  = node.to_s
  assert_match(dot, /^graph .456 \{$/)

  node = DOT::Graph.new({ "name" => "-.456" })
  dot  = node.to_s
  assert_match(dot, /^graph -.456 \{$/)

  node = DOT::Graph.new({ "name" => "-456" })
  dot  = node.to_s
  assert_match(dot, /^graph -456 \{$/)

  node = DOT::Graph.new({ "name" => "-123.456" })
  dot  = node.to_s
  assert_match(dot, /^graph -123.456 \{$/)

  node = DOT::Graph.new({ "name" => "<html><head><title>test</title></head>\n<body>text</body></html>" })
  dot  = node.to_s
  assert_match(dot, /^graph <html><head><title>test<\/title><\/head>\n<body>text<\/body><\/html> \{$/)
end
test_option_quoting() click to toggle source
# File test/rdot_test.rb, line 473
def test_option_quoting
  node = DOT::Graph.new({ "name" => "test_name", "comment" => "Comment with spaces" })
  dot  = node.to_s
  assert_match(dot, /comment\s*=\s*"Comment with spaces"/)

  node = DOT::Graph.new({ "name" => "test_name", "comment" => "Comment with \"quotes\"" })
  dot  = node.to_s
  assert_match(dot, /comment\s*=\s*"Comment with \\"quotes\\""/)

  node = DOT::Graph.new({ "name" => "test_name", "comment" => "Comment with \\backslashes\\" })
  dot  = node.to_s
  assert_match(dot, /comment\s*=\s*"Comment with \\\\backslashes\\\\"/)

  node = DOT::Graph.new({ "name" => "test_name", "comment" => "123.456" })
  dot  = node.to_s
  assert_match(dot, /comment\s*=\s*123.456/)

  node = DOT::Graph.new({ "name" => "test_name", "comment" => ".456" })
  dot  = node.to_s
  assert_match(dot, /comment\s*=\s*.456/)

  node = DOT::Graph.new({ "name" => "test_name", "comment" => "-.456" })
  dot  = node.to_s
  assert_match(dot, /comment\s*=\s*-.456/)

  node = DOT::Graph.new({ "name" => "test_name", "comment" => "-456" })
  dot  = node.to_s
  assert_match(dot, /comment\s*=\s*-456/)

  node = DOT::Graph.new({ "name" => "test_name", "comment" => "-123.456" })
  dot  = node.to_s
  assert_match(dot, /comment\s*=\s*-123.456/)

  node = DOT::Graph.new({ "name" => "test_name", "comment" => "<html><head><title>test</title></head>\n<body>text</body></html>" })
  dot  = node.to_s
  assert_match(dot, /comment\s*=\s*<html><head><title>test<\/title><\/head>\n<body>text<\/body><\/html>/)
end