def test_scope_of_global(): """Make sure the scope of a global is the entire program.""" js = """a = 0;""" ast = parse(js) raise SkipTest assignment = first(assignments(ast)) eq_(assignment.scope_of(assignment["left"]["name"])["type"], "Program")
def test_scope_of_initialized_variable(): js = """function smoo() { var a = 0; }""" ast = parse(js) assignment = first(assignments(ast)) eq_(assignment.scope_of(assignment['id']['name'])['id']['name'], 'smoo')
def test_scope_of_global(): """Make sure the scope of a global is the entire program.""" js = """a = 0;""" ast = parse(js) raise SkipTest assignment = first(assignments(ast)) eq_(assignment.scope_of(assignment['left']['name'])['type'], 'Program')
def test_scope_of_initialized_variable(): js = """function smoo() { var a = 0; }""" ast = parse(js) assignment = first(assignments(ast)) eq_(scope_of(assignment["id"]["name"], assignment)["id"]["name"], "smoo")
def test_scope_of_global_function(): js = """function smoo() { var a; a = 0; }""" ast = parse(js) assignment = first(assignments(ast)) eq_(assignment.scope_of(assignment['left']['name'])['type'], 'FunctionDeclaration')
def test_scope_of_global_function(): js = """function smoo() { var a; a = 0; }""" ast = parse(js) assignment = first(assignments(ast)) eq_(scope_of(assignment["left"]["name"], assignment)["type"], "FunctionDeclaration")
def test_scope_of_inner_function(): js = """function smoo() { function bar() { a = 0; } }""" ast = parse(js) assignment = first(assignments(ast)) eq_(assignment.scope_of(assignment['left']['name'])['type'], 'Program')
def test_scope_of_inner_function(): js = """function smoo() { function bar() { a = 0; } }""" ast = parse(js) assignment = first(assignments(ast)) eq_(scope_of(assignment["left"]["name"], assignment)["type"], "Program")
def test_assignments(): js = """a = 8; b = a; function c() { var d; d = a; }""" eq_([(a['left']['name'], a['right'].get('name', a['right'].get('value'))) for a in assignments(parse(js))], [('a', 8), ('b', 'a'), ('d', 'a')])
def test_scope_of_global_function(): js = """function smoo() { var a; a = 0; }""" ast = parse(js) assignment = first(assignments(ast)) eq_( assignment.scope_of(assignment['left']['name'])['type'], 'FunctionDeclaration')
def test_scope_of_inner_function(): js = """function smoo() { function bar() { var a; a = 0; } }""" ast = parse(js) raise SkipTest assignment = first(assignments(ast)) eq_(assignment.scope_of(assignment["left"]["name"])["id"]["name"], "bar")
def test_simple(): """Assert we notice simple calls to functions stored in global scope.""" js = """function answer() {} function call() { answer(); }""" ast = parse(js) g = call_graph(ast) eq_(set([(get_name(x), get_name(y)) for x, y in g.edges()]), set([('call', 'answer')]))
def test_scope_of_inner_reference(): js = """function smoo() { var a; function bar() { a = 0; } }""" ast = parse(js) assignment = first(assignments(ast)) eq_(scope_of(assignment["left"]["name"], assignment)["id"]["name"], "smoo")
def test_nested(): """Assert we identify calls to functions within the calling scope.""" js = """function call() { function answer() {} answer(); }""" ast = parse(js) g = call_graph(ast) eq_(set([(get_name(x), get_name(y)) for x, y in g.edges()]), set([('call', 'answer')]))
def test_nested(): """Assert we identify calls to functions within the calling scope.""" js = """function call() { function answer() {} answer(); }""" ast = parse(js) g = call_graph(ast) eq_(set([(get_name(x), get_name(y)) for x,y in g.edges()]), set([('call', 'answer')]))
def test_scope_of_inner_reference(): js = """function smoo() { var a; function bar() { a = 0; } }""" ast = parse(js) assignment = first(assignments(ast)) eq_(assignment.scope_of(assignment['left']['name'])['id']['name'], 'smoo')
def test_scope_of_inner_function(): js = """function smoo() { function bar() { var a; a = 0; } }""" ast = parse(js) raise SkipTest assignment = first(assignments(ast)) eq_(assignment.scope_of(assignment['left']['name'])['id']['name'], 'bar')
def test_simple(): """Assert we notice simple calls to functions stored in global scope.""" js = """function answer() {} function call() { answer(); }""" ast = parse(js) g = call_graph(ast) eq_(set([(get_name(x), get_name(y)) for x,y in g.edges()]), set([('call', 'answer')]))
def test_call_sites(): """Make sure we can find all the call sites in a program.""" js = """function answer() {} function call() { answer(); } call(); """ ast = parse(js) eq_([node["callee"]["name"] for node in call_sites(ast)], ["answer", "call"])
def test_call_sites(): """Make sure we can find all the call sites in a program.""" js = """function answer() {} function call() { answer(); } call(); """ ast = parse(js) eq_([node['callee']['name'] for node in call_sites(ast)], ['answer', 'call'])
def test_walk_down_smoke(): """Try it on some real code, and make sure it doesn't crash. Here, some nodes have bodies that are lists and others have bodies that are objects. """ js = """function answer() {} function call() { answer(); } call(); """ ast = parse(js)
def test_walk_down_smoke(): """Try it on some real code, and make sure it doesn't crash. Here, some nodes have bodies that are lists and others have bodies that are objects. """ js = """ function answer() {} function call() { answer(); } call(); """ ast = parse(js)
def test_scope_building(): """Make sure we find all the declarations within a function but don't stray into inner functions.""" js = """function smoo() { var w, x; if (true) { var y; } function bar() { var z; } }""" ast = parse(js) function = first(node for node in ast.walk_down() if node['type'] == 'FunctionDeclaration') eq_(function.scope(), set(['w', 'x', 'y']))
def test_scope_building(): """Make sure we find all the declarations within a function but don't stray into inner functions.""" js = """ function smoo() { var w, x; if (true) { var y; } function bar() { var z; } } function barbar() { } """ ast = parse(js) function = first(node for node in ast.walk_down() if isinstance(node, FunctionDeclaration)) eq_(set(function.scope().keys()), set(['w', 'x', 'y', 'smoo', 'bar'])) eq_(set(ast.scope().keys()), set(['smoo', 'barbar']))
def test_scope_building(): """Make sure we find all the declarations within a function but don't stray into inner functions.""" js = """ function smoo() { var w, x; if (true) { var y; } function bar() { var z; } } function barbar() { } """ ast = parse(js) function = first(node for node in walk_down(ast) if node['type'] == FUNC_DECL) raise SkipTest("Need to reimplement scope") eq_(set(function.scope().keys()), set(['w', 'x', 'y', 'smoo', 'bar'])) eq_(set(ast.scope().keys()), set(['smoo', 'barbar']))
def test_scope_of_global(): """Make sure the scope of a global is the entire program.""" js = """a = 0;""" ast = parse(js) assignment = first(assignments(ast)) eq_(assignment.scope_of(assignment['left']['name'])['type'], 'Program')
def test_assignments(): js = """a = 8; b = a; function c() { var d; d = a; }""" raise SkipTest eq_( [(a["left"]["name"], a["right"].get("name", a["right"].get("value"))) for a in assignments(parse(js))], [("a", 8), ("b", "a"), ("d", "a")], )