class TestDotSubgraph

Tests for DOT::Subgraph

Public Instance Methods

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

  graph = DOT::Subgraph.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::Subgraph.new('name' => 'test_graph', 'elements' => [node1])
  assert_equal(node1, graph.pop)
  assert_nil(graph.pop)
end
test_label_quoting() click to toggle source
# File test/rdot_test.rb, line 753
def test_label_quoting
  node = DOT::Subgraph.new({ "name" => "test_name", "label" => "Label with spaces" })
  dot  = node.to_s
  assert_match(dot, /label\s*=\s*"Label with spaces"/)

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

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

  node = DOT::Subgraph.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::Subgraph.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::Subgraph.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::Subgraph.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::Subgraph.new({ "name" => "test_name", "label" => "123.456" })
  dot  = node.to_s
  assert_match(dot, /label\s*=\s*123.456/)

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

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

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

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

  node = DOT::Subgraph.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 707
def test_name_quoting
  node = DOT::Subgraph.new({ "name" => "Name with spaces" })
  dot  = node.to_s
  assert_match(dot, /^subgraph "Name with spaces" \{$/)

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

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

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

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

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

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

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

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

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

  node = DOT::Subgraph.new({ "name" => "<html><head><title>test</title></head>\n<body>text</body></html>" })
  dot  = node.to_s
  assert_match(dot, /^subgraph <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 807
def test_option_quoting
  node = DOT::Subgraph.new({ "name" => "test_name", "comment" => "Comment with spaces" })
  dot  = node.to_s
  assert_match(dot, /comment\s*=\s*"Comment with spaces"/)

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

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

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

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

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

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

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

  node = DOT::Subgraph.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
test_subgraph_statement() click to toggle source
# File test/rdot_test.rb, line 701
def test_subgraph_statement
  subgraph = DOT::Subgraph.new()
  dot      = subgraph.to_s
  assert_match(dot, /^\s*subgraph /)
end