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


import os
import subprocess
import tempfile
import py.test

from semantix.utils import ast, debug, functional, config
import semantix.utils.lang.javascript.parser.jsparser as jsp
from semantix.utils.lang.javascript.codegen import JavascriptSourceGenerator


def jxfail(*args, **kwargs):
    def wrap(func):
        setattr(func, 'xfail', (args, kwargs))
        return func
    return wrap


@config.configurable
class MetaTestJavascript(type):
    v8_executable = config.cvalue('v8', type=str, doc='path to v8 executable')
    v8_found = None

    @debug.debug
    def do_test(src):
        jsparser = jsp.JSParser()

        with tempfile.NamedTemporaryFile('w') as file:
            file.write(src)
            file.flush()

            result = subprocess.getoutput("%s %s" % (MetaTestJavascript.v8_executable, file.name))

            """LOG [js.parse] Test Source
            print(src)
            """

            """LOG [js.parse] Expected Result
            print(result)
            """

            tree = jsparser.parse(src)
            """LOG [js.parse] Test Source AST
            print(ast.dump.pretty_dump(tree, colorize=True))
            """<commit_msg>utils.lang.javascript.tests: Set default v8 binary path to /usr/bin/d8<commit_after>##
# Copyright (c) 2008-2011 Sprymix Inc.
# All rights reserved.
#
# See LICENSE for details.
##


import os
import subprocess
import tempfile
import py.test

from semantix.utils import ast, debug, functional, config
import semantix.utils.lang.javascript.parser.jsparser as jsp
from semantix.utils.lang.javascript.codegen import JavascriptSourceGenerator


def jxfail(*args, **kwargs):
    def wrap(func):
        setattr(func, 'xfail', (args, kwargs))
        return func
    return wrap


@config.configurable
class MetaTestJavascript(type):
    v8_executable = config.cvalue('/usr/bin/d8', type=str, doc='path to v8 executable')
    v8_found = None

    @debug.debug
    def do_test(src):
        jsparser = jsp.JSParser()

        with tempfile.NamedTemporaryFile('w') as file:
            file.write(src)
            file.flush()

            result = subprocess.getoutput("%s %s" % (MetaTestJavascript.v8_executable, file.name))

            """LOG [js.parse] Test Source
            print(src)
            """

            """LOG [js.parse] Expected Result
            print(result)
            """

            tree = jsparser.parse(src)
            """LOG [js.parse] Test Source AST
            print(ast.dump.pretty_dump(tree, colorize=True))
            """
{'fraction_non_alphanumeric': 0.11448066717210008, 'fraction_numerical': 0.01061410159211524, 'mean_word_length': 2.532797858099063, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6264191', 'n_tokens_mistral': 840, 'n_tokens_neox': 787, 'n_words': 199}