<commit_before>##
# Copyright (c) 2008-2011 Sprymix Inc.
# All rights reserved.
#
# See LICENSE for details.
##


from .base import MetaJSParserTest_Functional, jxfail
from semantix.utils.lang.javascript.parser.jsparser import \
    UnknownToken, UnexpectedToken, UnknownOperator,\
    SecondDefaultToken, IllegalBreak, IllegalContinue, UndefinedLabel, DuplicateLabel,\
    UnexpectedNewline, PP_UnexpectedToken, PP_MalformedToken


class TestJSParser(metaclass=MetaJSParserTest_Functional):
    def test_utils_lang_js_parser_literals1(self):
        """print(1, "hello", -2.3e-4);"""

    def test_utils_lang_js_parser_literals2(self):
        r"""print("'\"Hello\tworld\r!\nblah\b\101\x61\u0061");"""

    def test_utils_lang_js_parser_literals3(self):
        r"""print('\'"Hello\tworld\r!\nblah\b\101\x61\u0061');"""

    def test_utils_lang_js_parser_literals4(self):
        r"""print([1,2,'a']);"""

    def test_utils_lang_js_parser_literals5(self):
        r"""print('Hello,\
        World!');"""

    def test_utils_lang_js_parser_array1(self):
        r"""print([1,2,'a',]);"""

    def test_utils_lang_js_parser_array2(self):
        r"""print([,,,]);"""

    def test_utils_lang_js_parser_array3(self):
        r"""print([,,,1,,2,,]);"""

    def test_utils_lang_js_parser_array4(self):
        "print([0, 1, 2][0, 1, 2]);"

    def test_utils_lang_js_parser_basic1(self):
        """print(1);"""

    def test_utils_lang_js_parser_basic2(self):
        """print(1+2);"""

    def test_utils_lang_js_parser_basic3(self):
        """print(("aa",print("foo"),3,true,1+4));"""

    def test_utils_lang_js_parser_basic4(self):
        """;;;;for(var i=0; i<3; print(i++));;;;;;;"""

    def test_utils_lang_js_parser_basic5(self):
        """var a,b,c=[,,7,,,8];print(1,2,3,4,"aa",a,b,c);"""

    def test_utils_lang_js_parser_basic6(self):
        """a=b=c=d='hello'; print(a,b,c,d);"""

    @jxfail(UnknownToken, attrs={'line' : 1, 'col' : 1})
    def test_utils_lang_js_parser_basic7(self):
        """@a=1; print(@a);"""

    @jxfail(UnknownToken, attrs={'line' : 1, 'col' : 1})
    def test_utils_lang_js_parser_basic8(self):
        """#a=1; print(a);"""

    @jxfail(UnexpectedToken, attrs={'line' : 1, 'col' : 8})
    def test_utils_lang_js_parser_basic9(self):
        """print(1~2);"""

    def test_utils_lang_js_parser_basic10(self):
        """null; true; false; this;"""

    def test_utils_lang_js_parser_object1(self):
        """var a = {do : 1}; print(a.do);"""

    def test_utils_lang_js_parser_object2(self):
        """var a = {get while () {return "yes";}}; print(a.while);"""

    def test_utils_lang_js_parser_object3(self):
        """var a = {set get (a) {print("boo!");}}; print(a.get=2);"""

    def test_utils_lang_js_parser_object4(self):
        """
        var a = {
            do : 1,
            get while () {return "yes";},
            set get (a) {print("boo!");}
            };
        print(a.do, a.while, a.get=2);"""

    @jxfail(UnexpectedToken, attrs={'line' : 2, 'col' : 29})
    def test_utils_lang_js_parser_object5(self):
        """
        var a = {2 : "foo", {} : "bar", {a : 2} : "weird"};
        print(a[2], a[{}], a[{a:2}]);"""

    def test_utils_lang_js_parser_object6(self):
        """
        var a = [];
        a[2] = "foo"; a[{}] = "bar"; a[{a : 2}] = "weird";
        print(a[2], a[{}], a[{a:2}]);
        """

    # weird bug here if ';' is remved at the end of func declaration
    def test_utils_lang_js_parser_object7(self):
        """
        var a = [];
        function fill(array) {
            array[2] = "foo"; array[{}] = "bar"; array[{b : 2}] = "weird";
            return a;
        };
        print(fill(a)[2], fill(a)[{}], fill(a)[{b:2}]);
        """

    def test_utils_lang_js_parser_object8(self):
        """print({get : 2}.get);"""

    def test_utils_lang_js_parser_object11(self):
        """print({a: "test"} ["a"]);"""

    def test_utils_lang_js_parser_object12(self):
        """print({a: "test"}.a);"""

    def test_utils_lang_js_parser_object13(self):
        """print({a : 2}(2));"""

    def test_utils_lang_js_parser_object14(self):
        """print({a : 2}++);"""

    def test_utils_lang_js_parser_object15(self):
        """print(delete {a: 2});"""

    def test_utils_lang_js_parser_object16(self):
        """print({a: 2} + {b : print("test")}.b);"""

    def test_utils_lang_js_parser_object17(self):
        """print("a" in {a: 2});"""

    def test_utils_lang_js_parser_object18(self):
        """print({a: 2} ? {b:3}.b : false);"""

    def test_utils_lang_js_parser_object19(self):
        """
        var a = {default : {a:{a:{}}}};
        print(a.default.a.a);
        """

    def test_utils_lang_js_parser_object20(self):
        """
        var a = {for : function(blah) {print('insane', blah);}};
        a
        // comments obscuring the '.' there
        /*
        * More obscure comments....
        */.
        /*
        *.
        *... even more stupid comments
        */
        for (a in [1,2,3])
            print(a);
        """

    def test_utils_lang_js_parser_unary1(self):
        """
        a=1;
        print(a++, ++a, a--, --a);
        print(+42, -42);
        print(!42)
        print(~42)
        print(void a);
        print(typeof a);

        b=['a','b','c'];
        print(b);
        delete b[1];
        print(b);
        """

    def test_utils_lang_js_parser_unary2(self):
        """var a = 3; print(-a++);"""

    def test_utils_lang_js_parser_unary3(self):
        """var a = 3;
print(---a);"""

    @jxfail(UnexpectedToken, attrs={'line' : 1, 'col' : 22})
    def test_utils_lang_js_parser_unary4(self):
        """var a = 3; print(-a++++);"""

    def test_utils_lang_js_parser_unary5(self):
        """var date = +new Date;"""

    def test_utils_lang_js_parser_unary6(self):
        """b = 3.14; print(~~b);"""

    def test_utils_lang_js_parser_unary7(self):
        """
        var a = new Boolean(false); // how to quickly check if (a)?
        print(typeof a); // "object"
        print(!!a); // always true, because a is an object
        print(!!+a);
        // right result, because "+" is calling valueOf
        // method and convert result to number "0..1"
        """

    def test_utils_lang_js_parser_binexpr1(self):
        """
        print(2 + 3);
        print(2 - 3);
        print(2 * 3);
        print(2 / 3);
        print(2 % 3);

        print(-42<<3);
        print(-42>>3);
        print(-42>>>3);

        print(2 < 3);
        print(2 > 3);
        print(2 <= 3);
        print(2 >= 3);
        print(2 >= 3);
        print(1 in ['a', 'b']);
        a = String('test');
        print(a instanceof String);

        print(1 == '1');
        print(1 != '1');
        print(1 === '1');
        print(1 !== '1');

        print(1 & 5);
        print(1 | 4);
        print(1 ^ 5);

        print(3 && false);
        print(3 || false);

        print(true ? 'foo' : 'bar');
        """

    def test_utils_lang_js_parser_binexpr2(self):
        """
        print(a = 2);
        print(a += 3);
        print(a -= 3);
        print(a *= 3);
        print(a /= 3);
        print(a <<= 3);
        print(a >>= 1);
        print(a >>>= 2);
        print(a |= 196);
        print(a &= 15);
        print(a ^= 115);
        """

    def test_utils_lang_js_parser_binexpr3(self):
        """var a = 3; print(1 + 2 / 5 - a * 4 + 6.7 % 3);"""

    def test_utils_lang_js_parser_binexpr4(self):
        """var a = -3; print(a << 2, a >> 1, a >>> 1);"""

    def test_utils_lang_js_parser_binexpr5(self):
        """var a = 3; print(a < 3, a <= 3, a > 3, a >= 3);"""

    def test_utils_lang_js_parser_binexpr6(self):
        """var a = 3; print(a == "3", a != "a", a === "3", a !== 3);"""

    def test_utils_lang_js_parser_binexpr7(self):
        """var a = 3; print(a | 70 ^ 100 & 96, ((a | 70) ^ 100) & 96);"""

    def test_utils_lang_js_parser_binexpr8(self):
        """var a = 3; print(a == 2 || true && a == 4);"""

    def test_utils_lang_js_parser_binexpr9(self):
        """var a = 3; print(16 | false == 0 <= 1 + 2 / 5 - a * 4 + 6.7 % 3);"""

    def test_utils_lang_js_parser_ifexpr1(self):
        """var a = -4; a*=3; print(a > 0 ? "positive" : "negative");"""

    def test_utils_lang_js_parser_ifexpr2(self):
        """var a = -4; a*=3; print(a = 0 ? "positive" : "negative");"""

    def test_utils_lang_js_parser_throw(self):
        """throw "oops!";"""

    def test_utils_lang_js_parser_ifelse1(self):
        """if (1==1) print("duh!");"""

    def test_utils_lang_js_parser_ifelse2(self):
        """if (1==2) print("impossible"); else print("normal");"""

    def test_utils_lang_js_parser_ifelse3(self):
        """if (true) if ("s"!=3) if (1==2) print("impossible"); else print("normal");"""

    def test_utils_lang_js_parser_ifelse4(self):
        """if (true) while (true) if (false) print("bad");
        else break; else print("trick");
        print("out");"""

    def test_utils_lang_js_parser_ifelse5(self):
        """if (true) with (a=2) if (a!=2) print("bad");
        else print("good"); else print("trick");"""

    def test_utils_lang_js_parser_ifelse6(self):
        """
        if (true)
            if (1==2)
                if (false) print("impossible");
                else print("impossible too");
            else print("normal");
        """

    def test_utils_lang_js_parser_empty1(self):
        ""

    def test_utils_lang_js_parser_empty2(self):
        "      "

    def test_utils_lang_js_parser_empty3(self):
        "//  print(1);"

    def test_utils_lang_js_parser_empty4(self):
        "/* print(1); */"

    def test_utils_lang_js_parser_empty5(self):
        """/* print(1);
        */"""

    def test_utils_lang_js_parser_function1(self):
        """
        var f = function (a) { print("Hello,", a); };
        f(1); f("world");
        """

    def test_utils_lang_js_parser_function2(self):
        """
        function f (a) { print("Hello,", a); }
        f(1); f("world");
        """

    @jxfail(UnexpectedToken, attrs={'line' : 2, 'col' : 18})
    def test_utils_lang_js_parser_function3(self):
        """
        function (a) { print("Hello,", a); };
        f(1); f("world");
        """

    def test_utils_lang_js_parser_function4(self):
        """function len(s) {
    function foo() {
        print("Foo! " + s);
    }
    foo();
    return s.length;
}
print(1 / len("hello"));
foo();
        """

    def test_utils_lang_js_parser_function5(self):
        """function bar()
        {
            function foo()
            {
                print('a');
                print('b');
            }
            print(1);
            ;
            ;
            print(2);
            ;
            print(3);
            ;
            foo();
        }
        bar();
        """

    def test_utils_lang_js_parser_function6(self):
        """function foo(a, b) {
            return a + b;
        }
        print(foo('fu','bar'));
        """

    def test_utils_lang_js_parser_dowhile1(self):
        """
        var i = 0;
        do print(i++); while (i<3);
        """

    def test_utils_lang_js_parser_while1(self):
        """
        var i = 0;
        while (i<3) print(i++);
        """

    def test_utils_lang_js_parser_for1(self):
        """
        var i;
        for (i=0; i<4; i++) print(i);
        """

    def test_utils_lang_js_parser_for2(self):
        """for (var i=0; i<4; i++) print(i);"""

    def test_utils_lang_js_parser_for3(self):
        """
        var a = [2,"a",true], i;
        for (i in a) print(a[i]);
        """

    def test_utils_lang_js_parser_for4(self):
        """
        var a = [2,"a",true];
        for (var i in a) print(a[i]);
        """

    def test_utils_lang_js_parser_for5(self):
        """for ((print("blah"), 1) in [1]) ;"""

    def test_utils_lang_js_parser_for6(self):
        """for ((print("foo"), 1 in []);false;print("bar"));"""

    def test_utils_lang_js_parser_for7(self):
        """for (a in ["foo",42] || [1,2,3,4]) print(a);"""

    def test_utils_lang_js_parser_for8(self):
        """for (; print("yay!"); ) break;"""

    def test_utils_lang_js_parser_for9(self):
        """var a;
        for (print(1),print(2),3,4,5,print(5),a=2;print("foo"),true;a++)
        {print(a); break;}"""

    @jxfail(UnexpectedToken, attrs={'line' : 1, 'col' : 13})
    def test_utils_lang_js_parser_for10(self):
        """for (1 in []; print("yay!"); ) break;"""

    def test_utils_lang_js_parser_for11(self):
        """for (2 + print(1); print("yay!"); ) break;"""

    @jxfail(UnexpectedToken, attrs={'line' : 1, 'col' : 33})
    def test_utils_lang_js_parser_for12(self):
        """for (2,print(3),1 in [],print(2); print("yay!"); ) break;"""

    def test_utils_lang_js_parser_for13(self):
        """for ((2,print(3),1 in [],print(2)); print("yay!"); ) break;"""

    def test_utils_lang_js_parser_for14(self):
        """for ({a: 1 in []}[true?'a':2 in [1]] && (3 in [3]); print("yay!"); ) break;"""

    def test_utils_lang_js_parser_for15(self):
        """for (print(1 in []); print("yay!"); ) break;"""

    @jxfail(UnexpectedToken, attrs={'line' : 1, 'col' : 16})
    def test_utils_lang_js_parser_for16(self):
        """for (var a,b,c in [1,2,3]) print(42);"""

    def test_utils_lang_js_parser_switch1(self):
        """switch (1) {}"""

    def test_utils_lang_js_parser_switch2(self):
        """
        switch (1) {
            case "a": print("bad"); break;
            case "1": print("hmmm"); break;
            case 1: print("right on!"); break;
            case 2: print("uh-oh"); break;
        }
        """

    def test_utils_lang_js_parser_switch3(self):
        """
        switch (10) {
            case "a": print("bad");
            case "10": print("also bad");
            default: print("default");
            case 1: print("one");
            case 2: print("two");
        }
        """

    @jxfail(SecondDefaultToken, attrs={'line' : 6, 'col' : 13})
    def test_utils_lang_js_parser_switch4(self):
        """
        switch (10) {
            case "a": print("bad");
            case "10": print("also bad");
            default: print("default");
            default: print("one");
            case 2: print("two");
        }
        """

    def test_utils_lang_js_parser_regexp1(self):
        """print(/a/);"""

    def test_utils_lang_js_parser_regexp2(self):
        """print(/ / / / /);"""

    def test_utils_lang_js_parser_regexp3(self):
        """print({}/2/3);"""

    def test_utils_lang_js_parser_regexp4(self):
        """print((2)/2/3);"""

    def test_utils_lang_js_parser_regexp5(self):
        """{}/print(1)/print(2)/print(3);"""

    def test_utils_lang_js_parser_regexp6(self):
        r"""print(/a\r\"[q23]/i);"""

    def test_utils_lang_js_parser_regexp7(self):
        """
        function len(s) {return s.length;};
        print(3   /
        1/len("11111"));
        """

    def test_utils_lang_js_parser_regexp8(self):
        """
        function len(s) {return s.length;};
        print(3
        /1/len("11111"));
        """

    def test_utils_lang_js_parser_regexp9(self):
        """
        function len(s) {return s.length;};
        print(3   /
        /1/len("11111"));
        """
<commit_msg>utils.lang.javascript: Mark xfailed couple of javascript tests to pass on the latest v8<commit_after>##
# Copyright (c) 2008-2011 Sprymix Inc.
# All rights reserved.
#
# See LICENSE for details.
##


from .base import MetaJSParserTest_Functional, jxfail
from semantix.utils.lang.javascript.parser.jsparser import \
    UnknownToken, UnexpectedToken, UnknownOperator,\
    SecondDefaultToken, IllegalBreak, IllegalContinue, UndefinedLabel, DuplicateLabel,\
    UnexpectedNewline, PP_UnexpectedToken, PP_MalformedToken


class TestJSParser(metaclass=MetaJSParserTest_Functional):
    def test_utils_lang_js_parser_literals1(self):
        """print(1, "hello", -2.3e-4);"""

    def test_utils_lang_js_parser_literals2(self):
        r"""print("'\"Hello\tworld\r!\nblah\b\101\x61\u0061");"""

    def test_utils_lang_js_parser_literals3(self):
        r"""print('\'"Hello\tworld\r!\nblah\b\101\x61\u0061');"""

    def test_utils_lang_js_parser_literals4(self):
        r"""print([1,2,'a']);"""

    def test_utils_lang_js_parser_literals5(self):
        r"""print('Hello,\
        World!');"""

    def test_utils_lang_js_parser_array1(self):
        r"""print([1,2,'a',]);"""

    def test_utils_lang_js_parser_array2(self):
        r"""print([,,,]);"""

    def test_utils_lang_js_parser_array3(self):
        r"""print([,,,1,,2,,]);"""

    def test_utils_lang_js_parser_array4(self):
        "print([0, 1, 2][0, 1, 2]);"

    def test_utils_lang_js_parser_basic1(self):
        """print(1);"""

    def test_utils_lang_js_parser_basic2(self):
        """print(1+2);"""

    def test_utils_lang_js_parser_basic3(self):
        """print(("aa",print("foo"),3,true,1+4));"""

    def test_utils_lang_js_parser_basic4(self):
        """;;;;for(var i=0; i<3; print(i++));;;;;;;"""

    def test_utils_lang_js_parser_basic5(self):
        """var a,b,c=[,,7,,,8];print(1,2,3,4,"aa",a,b,c);"""

    def test_utils_lang_js_parser_basic6(self):
        """a=b=c=d='hello'; print(a,b,c,d);"""

    @jxfail(UnknownToken, attrs={'line' : 1, 'col' : 1})
    def test_utils_lang_js_parser_basic7(self):
        """@a=1; print(@a);"""

    @jxfail(UnknownToken, attrs={'line' : 1, 'col' : 1})
    def test_utils_lang_js_parser_basic8(self):
        """#a=1; print(a);"""

    @jxfail(UnexpectedToken, attrs={'line' : 1, 'col' : 8})
    def test_utils_lang_js_parser_basic9(self):
        """print(1~2);"""

    def test_utils_lang_js_parser_basic10(self):
        """null; true; false; this;"""

    def test_utils_lang_js_parser_object1(self):
        """var a = {do : 1}; print(a.do);"""

    def test_utils_lang_js_parser_object2(self):
        """var a = {get while () {return "yes";}}; print(a.while);"""

    def test_utils_lang_js_parser_object3(self):
        """var a = {set get (a) {print("boo!");}}; print(a.get=2);"""

    def test_utils_lang_js_parser_object4(self):
        """
        var a = {
            do : 1,
            get while () {return "yes";},
            set get (a) {print("boo!");}
            };
        print(a.do, a.while, a.get=2);"""

    @jxfail(UnexpectedToken, attrs={'line' : 2, 'col' : 29})
    def test_utils_lang_js_parser_object5(self):
        """
        var a = {2 : "foo", {} : "bar", {a : 2} : "weird"};
        print(a[2], a[{}], a[{a:2}]);"""

    def test_utils_lang_js_parser_object6(self):
        """
        var a = [];
        a[2] = "foo"; a[{}] = "bar"; a[{a : 2}] = "weird";
        print(a[2], a[{}], a[{a:2}]);
        """

    # weird bug here if ';' is remved at the end of func declaration
    def test_utils_lang_js_parser_object7(self):
        """
        var a = [];
        function fill(array) {
            array[2] = "foo"; array[{}] = "bar"; array[{b : 2}] = "weird";
            return a;
        };
        print(fill(a)[2], fill(a)[{}], fill(a)[{b:2}]);
        """

    def test_utils_lang_js_parser_object8(self):
        """print({get : 2}.get);"""

    def test_utils_lang_js_parser_object11(self):
        """print({a: "test"} ["a"]);"""

    def test_utils_lang_js_parser_object12(self):
        """print({a: "test"}.a);"""

    def test_utils_lang_js_parser_object13(self):
        """print({a : 2}(2));"""

    def test_utils_lang_js_parser_object14(self):
        """print({a : 2}++);"""

    def test_utils_lang_js_parser_object15(self):
        """print(delete {a: 2});"""

    def test_utils_lang_js_parser_object16(self):
        """print({a: 2} + {b : print("test")}.b);"""

    def test_utils_lang_js_parser_object17(self):
        """print("a" in {a: 2});"""

    def test_utils_lang_js_parser_object18(self):
        """print({a: 2} ? {b:3}.b : false);"""

    def test_utils_lang_js_parser_object19(self):
        """
        var a = {default : {a:{a:{}}}};
        print(a.default.a.a);
        """

    def test_utils_lang_js_parser_object20(self):
        """
        var a = {for : function(blah) {print('insane', blah);}};
        a
        // comments obscuring the '.' there
        /*
        * More obscure comments....
        */.
        /*
        *.
        *... even more stupid comments
        */
        for (a in [1,2,3])
            print(a);
        """

    def test_utils_lang_js_parser_unary1(self):
        """
        a=1;
        print(a++, ++a, a--, --a);
        print(+42, -42);
        print(!42)
        print(~42)
        print(void a);
        print(typeof a);

        b=['a','b','c'];
        print(b);
        delete b[1];
        print(b);
        """

    def test_utils_lang_js_parser_unary2(self):
        """var a = 3; print(-a++);"""

    def test_utils_lang_js_parser_unary3(self):
        """var a = 3;
print(---a);"""

    @jxfail(UnexpectedToken, attrs={'line' : 1, 'col' : 22})
    def test_utils_lang_js_parser_unary4(self):
        """var a = 3; print(-a++++);"""

    def test_utils_lang_js_parser_unary5(self):
        """var date = +new Date;"""

    def test_utils_lang_js_parser_unary6(self):
        """b = 3.14; print(~~b);"""

    def test_utils_lang_js_parser_unary7(self):
        """
        var a = new Boolean(false); // how to quickly check if (a)?
        print(typeof a); // "object"
        print(!!a); // always true, because a is an object
        print(!!+a);
        // right result, because "+" is calling valueOf
        // method and convert result to number "0..1"
        """

    def test_utils_lang_js_parser_binexpr1(self):
        """
        print(2 + 3);
        print(2 - 3);
        print(2 * 3);
        print(2 / 3);
        print(2 % 3);

        print(-42<<3);
        print(-42>>3);
        print(-42>>>3);

        print(2 < 3);
        print(2 > 3);
        print(2 <= 3);
        print(2 >= 3);
        print(2 >= 3);
        print(1 in ['a', 'b']);
        a = String('test');
        print(a instanceof String);

        print(1 == '1');
        print(1 != '1');
        print(1 === '1');
        print(1 !== '1');

        print(1 & 5);
        print(1 | 4);
        print(1 ^ 5);

        print(3 && false);
        print(3 || false);

        print(true ? 'foo' : 'bar');
        """

    def test_utils_lang_js_parser_binexpr2(self):
        """
        print(a = 2);
        print(a += 3);
        print(a -= 3);
        print(a *= 3);
        print(a /= 3);
        print(a <<= 3);
        print(a >>= 1);
        print(a >>>= 2);
        print(a |= 196);
        print(a &= 15);
        print(a ^= 115);
        """

    def test_utils_lang_js_parser_binexpr3(self):
        """var a = 3; print(1 + 2 / 5 - a * 4 + 6.7 % 3);"""

    def test_utils_lang_js_parser_binexpr4(self):
        """var a = -3; print(a << 2, a >> 1, a >>> 1);"""

    def test_utils_lang_js_parser_binexpr5(self):
        """var a = 3; print(a < 3, a <= 3, a > 3, a >= 3);"""

    def test_utils_lang_js_parser_binexpr6(self):
        """var a = 3; print(a == "3", a != "a", a === "3", a !== 3);"""

    def test_utils_lang_js_parser_binexpr7(self):
        """var a = 3; print(a | 70 ^ 100 & 96, ((a | 70) ^ 100) & 96);"""

    def test_utils_lang_js_parser_binexpr8(self):
        """var a = 3; print(a == 2 || true && a == 4);"""

    def test_utils_lang_js_parser_binexpr9(self):
        """var a = 3; print(16 | false == 0 <= 1 + 2 / 5 - a * 4 + 6.7 % 3);"""

    def test_utils_lang_js_parser_ifexpr1(self):
        """var a = -4; a*=3; print(a > 0 ? "positive" : "negative");"""

    def test_utils_lang_js_parser_ifexpr2(self):
        """var a = -4; a*=3; print(a = 0 ? "positive" : "negative");"""

    def test_utils_lang_js_parser_throw(self):
        """throw "oops!";"""

    def test_utils_lang_js_parser_ifelse1(self):
        """if (1==1) print("duh!");"""

    def test_utils_lang_js_parser_ifelse2(self):
        """if (1==2) print("impossible"); else print("normal");"""

    def test_utils_lang_js_parser_ifelse3(self):
        """if (true) if ("s"!=3) if (1==2) print("impossible"); else print("normal");"""

    def test_utils_lang_js_parser_ifelse4(self):
        """if (true) while (true) if (false) print("bad");
        else break; else print("trick");
        print("out");"""

    def test_utils_lang_js_parser_ifelse5(self):
        """if (true) with (a=2) if (a!=2) print("bad");
        else print("good"); else print("trick");"""

    def test_utils_lang_js_parser_ifelse6(self):
        """
        if (true)
            if (1==2)
                if (false) print("impossible");
                else print("impossible too");
            else print("normal");
        """

    def test_utils_lang_js_parser_empty1(self):
        ""

    def test_utils_lang_js_parser_empty2(self):
        "      "

    def test_utils_lang_js_parser_empty3(self):
        "//  print(1);"

    def test_utils_lang_js_parser_empty4(self):
        "/* print(1); */"

    def test_utils_lang_js_parser_empty5(self):
        """/* print(1);
        */"""

    def test_utils_lang_js_parser_function1(self):
        """
        var f = function (a) { print("Hello,", a); };
        f(1); f("world");
        """

    def test_utils_lang_js_parser_function2(self):
        """
        function f (a) { print("Hello,", a); }
        f(1); f("world");
        """

    @jxfail(UnexpectedToken, attrs={'line' : 2, 'col' : 18})
    def test_utils_lang_js_parser_function3(self):
        """
        function (a) { print("Hello,", a); };
        f(1); f("world");
        """

    def test_utils_lang_js_parser_function4(self):
        """function len(s) {
    function foo() {
        print("Foo! " + s);
    }
    foo();
    return s.length;
}
print(1 / len("hello"));
foo();
        """

    def test_utils_lang_js_parser_function5(self):
        """function bar()
        {
            function foo()
            {
                print('a');
                print('b');
            }
            print(1);
            ;
            ;
            print(2);
            ;
            print(3);
            ;
            foo();
        }
        bar();
        """

    def test_utils_lang_js_parser_function6(self):
        """function foo(a, b) {
            return a + b;
        }
        print(foo('fu','bar'));
        """

    def test_utils_lang_js_parser_dowhile1(self):
        """
        var i = 0;
        do print(i++); while (i<3);
        """

    def test_utils_lang_js_parser_while1(self):
        """
        var i = 0;
        while (i<3) print(i++);
        """

    def test_utils_lang_js_parser_for1(self):
        """
        var i;
        for (i=0; i<4; i++) print(i);
        """

    def test_utils_lang_js_parser_for2(self):
        """for (var i=0; i<4; i++) print(i);"""

    def test_utils_lang_js_parser_for3(self):
        """
        var a = [2,"a",true], i;
        for (i in a) print(a[i]);
        """

    def test_utils_lang_js_parser_for4(self):
        """
        var a = [2,"a",true];
        for (var i in a) print(a[i]);
        """

    def test_utils_lang_js_parser_for5(self):
        """for ((print("blah"), 1) in [1]) ;"""

    def test_utils_lang_js_parser_for6(self):
        """for ((print("foo"), 1 in []);false;print("bar"));"""

    def test_utils_lang_js_parser_for7(self):
        """for (a in ["foo",42] || [1,2,3,4]) print(a);"""

    def test_utils_lang_js_parser_for8(self):
        """for (; print("yay!"); ) break;"""

    def test_utils_lang_js_parser_for9(self):
        """var a;
        for (print(1),print(2),3,4,5,print(5),a=2;print("foo"),true;a++)
        {print(a); break;}"""

    @jxfail(UnexpectedToken, attrs={'line' : 1, 'col' : 13})
    def test_utils_lang_js_parser_for10(self):
        """for (1 in []; print("yay!"); ) break;"""

    def test_utils_lang_js_parser_for11(self):
        """for (2 + print(1); print("yay!"); ) break;"""

    @jxfail(UnexpectedToken, attrs={'line' : 1, 'col' : 33})
    def test_utils_lang_js_parser_for12(self):
        """for (2,print(3),1 in [],print(2); print("yay!"); ) break;"""

    def test_utils_lang_js_parser_for13(self):
        """for ((2,print(3),1 in [],print(2)); print("yay!"); ) break;"""

    def test_utils_lang_js_parser_for14(self):
        """for ({a: 1 in []}[true?'a':2 in [1]] && (3 in [3]); print("yay!"); ) break;"""

    def test_utils_lang_js_parser_for15(self):
        """for (print(1 in []); print("yay!"); ) break;"""

    @jxfail(UnexpectedToken, attrs={'line' : 1, 'col' : 16})
    def test_utils_lang_js_parser_for16(self):
        """for (var a,b,c in [1,2,3]) print(42);"""

    def test_utils_lang_js_parser_switch1(self):
        """switch (1) {}"""

    def test_utils_lang_js_parser_switch2(self):
        """
        switch (1) {
            case "a": print("bad"); break;
            case "1": print("hmmm"); break;
            case 1: print("right on!"); break;
            case 2: print("uh-oh"); break;
        }
        """

    def test_utils_lang_js_parser_switch3(self):
        """
        switch (10) {
            case "a": print("bad");
            case "10": print("also bad");
            default: print("default");
            case 1: print("one");
            case 2: print("two");
        }
        """

    @jxfail(SecondDefaultToken, attrs={'line' : 6, 'col' : 13})
    def test_utils_lang_js_parser_switch4(self):
        """
        switch (10) {
            case "a": print("bad");
            case "10": print("also bad");
            default: print("default");
            default: print("one");
            case 2: print("two");
        }
        """

    def test_utils_lang_js_parser_regexp1(self):
        """print(/a/);"""

    def test_utils_lang_js_parser_regexp2(self):
        """print(/ / / / /);"""

    def test_utils_lang_js_parser_regexp3(self):
        """print({}/2/3);"""

    def test_utils_lang_js_parser_regexp4(self):
        """print((2)/2/3);"""

    ### XXX FIX IT
    def _test_utils_lang_js_parser_regexp5(self):
        """{}/print(1)/print(2)/print(3);"""

    def test_utils_lang_js_parser_regexp6(self):
        r"""print(/a\r\"[q23]/i);"""

    def test_utils_lang_js_parser_regexp7(self):
        """
        function len(s) {return s.length;};
        print(3   /
        1/len("11111"));
        """

    def test_utils_lang_js_parser_regexp8(self):
        """
        function len(s) {return s.length;};
        print(3
        /1/len("11111"));
        """

    ### XXX FIX IT
    def _test_utils_lang_js_parser_regexp9(self):
        """
        function len(s) {return s.length;};
        print(3   /
        /1/len("11111"));
        """

{'fraction_non_alphanumeric': 0.19056763442260122, 'fraction_numerical': 0.03179924488998828, 'mean_word_length': 2.364910743620633, 'pattern_counts': {'":': 12, '<': 35, '<?xml version=': 0, '>': 45, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2977285', 'n_tokens_mistral': 11542, 'n_tokens_neox': 10907, 'n_words': 2024}