Exemple #1
0
    def test_import_macros(self):
        self.assertStatements('''@import a.b.c as c;''',[
            ["import","a.b.c","c"]
        ])
        self.assertStatements('''@import a.b.* as *;''',[
            ["starimport","a.b"]
        ])
        
         
         
        g = Grammar("""\
@import a.b.c as c;""")
        result,error = g.apply("statements")
        resolved = expand_macros(result)
        assert resolved == [["statement","var", " ","c","=","resolver",["parenthesis",[]],["parenthesis",['"',"a.b.c",'"']],";"]]
        self.assertStatementsOut(resolved,'var c=resolver()("a.b.c");')
Exemple #2
0
    def test_describe_macros(self):
        """
        @describe
        """
        #TODO lhs_opt_call possibility
        
        self.assertStatements('''
@describe "pagecore browser identification" {}
''',["\n",
        ["describe",None,'"pagecore browser identification"', []], 
        "\n"])

        self.assertStatements('''
@describe Object, "pagecore browser identification" {}
''',["\n",
        ["describe","Object",'"pagecore browser identification"', []], 
        "\n"])

        self.assertStatements('''
@describe String {}
''',["\n",
        ["describe","String",None, []], 
        "\n"])

        self.assertStatements('''
@describe "pagecore browser identification" {
it "should identify" {
}
}
''',["\n",
        ["describe", None,'"pagecore browser identification"',["\n",
            ["it", '"should identify"', [
                "\n"
            ]],
        "\n"]],
        "\n"])

        # Expanding describe and it
        described = expand_macros(["describe", None,'"pagecore browser identification"',["\n", 
            ["it", '"should identify"', [ "\n" ]],
        "\n"]])
        assert described == ["describe", None,'"pagecore browser identification"',["\n", 
            ["it", '"should identify"', [ "\n" ]],
        "\n"]]

        self.assertStatements('''
@describe "pagecore browser identification" {
it "should identify" {
a should == 5;
}
}
''',["\n",
        ["describe", None,'"pagecore browser identification"', ["\n", 
            ["it", '"should identify"', ["\n", 
                ["should", ["a"], ["==", "5"]], 
                "\n" 
            ]],
        "\n"]],
        "\n"])
        
        # Expanding should expression statement
        described = expand_macros(["describe", None,'"pagecore browser identification"', ["\n", 
            ["it", '"should identify"', ["\n", 
                ["should", ["a"], ["==", "5"]], 
                "\n" 
            ]],
        "\n"]])
        assert described == ["describe", None,'"pagecore browser identification"', ["\n", 
            ["it", '"should identify"',["\n", 
                ["should", ["a"], ["==", "5"]], 
                "\n" 
            ]],
        "\n"]]
Exemple #3
0
    def test_scope_macros(self):
        self.assertStatements("""@scope "a/b/c"  { function(){} }""", [
            ["scope", [" "], '"a/b/c"', [" "," "], [
                " ", [ "function", [], [], None, [], [], [], [] ], " "
            ]]
            ])
            
        self.assertStatements('''
@insert();
addExtension(new Extension());
''',["\n", ["insert"], "\n",
"addExtension", ['parenthesis',["new"," ","Extension",['parenthesis',[]] ]], ";",
"\n"
])
        self.assertStatements('''
''',["\n"
])

        
        self.assertStatements('''
(function(window,document,mark,assertion,fail,pagecore,addExtension){

    @insert();

    addExtension(new Extension());

})(window,document,mark,assertion,fail,pagecore,addExtension);
''', [
    "\n",
    ['parenthesis',[ ['function', [], [], None, [], ["window",",","document",",","mark",",","assertion",",","fail",",","pagecore",",","addExtension"], [], [
        "\n","\n"," "," "," "," ",
        ["insert"],
        "\n","\n"," "," "," "," ",
        "addExtension",
        ['parenthesis',["new"," ","Extension",['parenthesis',[]] ]],
        ";","\n","\n"
    ]] ]],
    ['parenthesis',["window",",","document",",","mark",",","assertion",",","fail",",","pagecore",",","addExtension"]],
    ";","\n"
])

        scoped = expand_macros([
            ["scope", [" "], '"a/b/c"', [" "," "], [
                " ", [ "function", [], [], None, [], [], [], [] ], " "
            ]]
        ]) 
        # print 'scoped', scoped
        assert scoped == [
            ["slcomment",'no scope "a/b/c"'],
            " ", [ "function", [], [], None, [], [], [], [] ], " "
        ]
                    
        add_scope("'extension'",'''
(function(window,document,mark,assertion,fail,pagecore,addExtension){
@insert();
addExtension(new Extension());
})(window,document,mark,assertion,fail,pagecore,addExtension);
''')
        assert '"extension"' in scopes
            
        scoped = expand_macros([
            ["scope", [" "], '"extension"', [" "," "], [
                " ", [ "function", [], [], None, [], [], [], [] ], " "
            ]]
        ]) 
        # print 'scoped', scoped
        assert scoped == [
            "\n",
            ['parenthesis',[ ['function', [], [], None, [], ["window",",","document",",","mark",",","assertion",",","fail",",","pagecore",",","addExtension"], [], [
                "\n",
                " ", [ "function", [], [], None, [], [], [], [] ], " ",
                "\n",
                "addExtension", ['parenthesis',["new"," ","Extension",['parenthesis',[]] ]],
                ";","\n"
            ]] ]],
            ['parenthesis',["window",",","document",",","mark",",","assertion",",","fail",",","pagecore",",","addExtension"]],
            ";","\n"
        ]


        add_scope("'named'",'''
var @insert:test = (function(){
@insert();
})();
''')
        assert '"named"' in scopes

        scoped = expand_macros([
            ["scope", [" "], '"named"', [" "," "], [
                "/*before*/", [ "function", [], ["nested"], None, [], [], [], [] ], "/*after*/"
            ]]
        ], insert_vars=dict(test="test_var")) 
        
        print scoped
        
        assert scoped == [
            "\n", "var", " ", "test_var", " ", "=", " ",
            ['parenthesis',[ ['function', [], [], None, [], [], [], [
                "\n",
                "/*before*/", [ "function", [], ["nested"], None, [], [], [], [] ], "/*after*/",
                "\n"
            ]] ]],
            ['parenthesis',[]],
            ";","\n"
        ]