Skip to content
This repository
tree: cd61cb9c3b
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 40 lines (33 sloc) 1.084 kb
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
require "helper"

class DotVisitorTest < Test::Unit::TestCase
  def test_var_foo
    dot = Johnson.parse('var foo;').to_dot
    assert_equal(3, dot.nodes.length)
    assert_equal(2, dot.links.length)
  end

  def test_for
    dot = Johnson.parse('for(var x = 0; x < 10; x++) { }').to_dot
    assert_equal(12, dot.nodes.length)
    assert_equal(11, dot.links.length)
  end

  def test_for_in
    dot = Johnson.parse('for(var x in johnson(1,2,"asdf")) { }').to_dot
    assert_equal(11, dot.nodes.length)
    assert_equal(10, dot.links.length)
  end

  def test_try
    dot = Johnson.parse('try { var x = 10; } finally { var x = 20; }').to_dot
    assert_equal(12, dot.nodes.length)
    assert_equal(11, dot.links.length)
  end

  def test_try_catch
    dot = Johnson.parse('try { var x = 10; } catch(a) { var x = 20; x++; }').to_dot
    assert_equal(16, dot.nodes.length)
    assert_equal(15, dot.links.length)
  end

  def test_function
    dot = Johnson.parse("var foo = function(a,b) { }").to_dot
    assert_equal(6, dot.nodes.length)
    assert_equal(5, dot.links.length)
  end
end
Something went wrong with that request. Please try again.