예제 #1
0
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")
예제 #2
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')
예제 #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')
예제 #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")
예제 #6
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')
예제 #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")
예제 #8
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')
예제 #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')
예제 #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")
예제 #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')])
예제 #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')
예제 #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")
예제 #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')]))
예제 #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")
예제 #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')]))
예제 #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')]))
예제 #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')
예제 #20
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')
예제 #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')]))
예제 #22
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')])
예제 #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"])
예제 #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'])
예제 #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'])
예제 #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)
예제 #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)
예제 #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']))
예제 #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']))
예제 #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']))
예제 #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']))
예제 #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']))
예제 #33
0
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')
예제 #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")],
    )