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')
Exemple #3
0
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')
Exemple #5
0
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')
Exemple #7
0
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')
Exemple #9
0
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')
Exemple #10
0
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")
Exemple #11
0
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')])
Exemple #12
0
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')
Exemple #13
0
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")
Exemple #14
0
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')]))
Exemple #15
0
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")
Exemple #16
0
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')]))
Exemple #17
0
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')]))
Exemple #18
0
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_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')
Exemple #21
0
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_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')])
Exemple #23
0
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"])
Exemple #24
0
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'])
Exemple #25
0
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'])
Exemple #26
0
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)
Exemple #27
0
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)
Exemple #28
0
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']))
Exemple #29
0
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']))
Exemple #30
0
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']))
Exemple #31
0
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']))
Exemple #32
0
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')
Exemple #34
0
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")],
    )