<commit_before>define(function(require, exports, module) {

var parser = require("treehugger/js/parse");
var traverse = require("treehugger/traverse");
var baseLanguageHandler = require("plugins/c9.ide.language/base_handler");
// var parser = require("plugins/c9.ide.language/parse");

var handler = module.exports = Object.create(baseLanguageHandler);

handler.init = function() {
    // Create a new event handler. 
    handler.sender.on("mocha_outline", function(e) {
        // code = code.replace(/^(#!.*\n)/, "//$1");
        var ast = parser.parse(e.data.code);
        
        handler.sender.emit("mocha_outline_result", {
            id: e.data.id, // Some unique id for this request
            result: getTestCases(ast)
        });
    });
};

handler.handlesLanguage = function() {
    return false;
};

function getTestCases(ast) {
    var items = [];
    
    // Traverse the AST with some pattern matching
    // for debugging, do ast.toString() or node.toString()
    ast.traverseTopDown( 
        'Call(Var("before"), _)', function(b, node) {
            items.push({
                label: "before all",
                type: "prepare",
                pos: node.getPos()
            });
        },
        'Call(Var("beforeEach"), _)', function(b, node) {
            items.push({
                label: "before each",
                type: "prepare",
                pos: node.getPos()
            });
        },
        'Call(Var("after"), _)', function(b, node) {
            items.push({
                label: "before all",
                type: "prepare",
                pos: node.getPos()
            });
        },
        'Call(Var("afterEach"), _)', function(b, node) {
            items.push({
                label: "before each",
                type: "prepare",
                pos: node.getPos()
            });
        },
        'Call(Var("it"), [String(description), _])', function(b, node) {
            items.push({
                label: b.description.value,
                kind: "it",
                type: "test",
                selpos: b.description.getPos(),
                pos: node.getPos()
            });
        },
        'Call(Var("describe"), [String(description), body])', function(b, node) {<commit_msg>Add .only support<commit_after>define(function(require, exports, module) {

var parser = require("treehugger/js/parse");
var traverse = require("treehugger/traverse");
var baseLanguageHandler = require("plugins/c9.ide.language/base_handler");
// var parser = require("plugins/c9.ide.language/parse");

var handler = module.exports = Object.create(baseLanguageHandler);

handler.init = function() {
    // Create a new event handler. 
    handler.sender.on("mocha_outline", function(e) {
        // code = code.replace(/^(#!.*\n)/, "//$1");
        var ast = parser.parse(e.data.code);
        
        handler.sender.emit("mocha_outline_result", {
            id: e.data.id, // Some unique id for this request
            result: getTestCases(ast)
        });
    });
};

handler.handlesLanguage = function() {
    return false;
};

function getTestCases(ast) {
    var items = [];
    
    // Traverse the AST with some pattern matching
    // for debugging, do ast.toString() or node.toString()
    ast.traverseTopDown( 
        'Call(Var("before"), _)', function(b, node) {
            items.push({
                label: "before all",
                type: "prepare",
                pos: node.getPos()
            });
        },
        'Call(Var("beforeEach"), _)', function(b, node) {
            items.push({
                label: "before each",
                type: "prepare",
                pos: node.getPos()
            });
        },
        'Call(Var("after"), _)', function(b, node) {
            items.push({
                label: "before all",
                type: "prepare",
                pos: node.getPos()
            });
        },
        'Call(Var("afterEach"), _)', function(b, node) {
            items.push({
                label: "before each",
                type: "prepare",
                pos: node.getPos()
            });
        },
        'Call(Var("it"), [String(description), _])', function(b, node) {
            items.push({
                label: b.description.value,
                kind: "it",
                type: "test",
                selpos: b.description.getPos(),
                pos: node.getPos()
            });
        },
        'Call(PropAccess(Var("it"), "only"), [String(description), _])', function(b, node) {
            items.push({
                label: b.description.value,
                kind: "it",
                type: "test",
                selpos: b.description.getPos(),
                pos: node.getPos()
            });
        },
        'Call(Var("describe"), [String(description), body])', function(b, node) {
            items.push({
                label: b.description.value,
                items: getTestCases(b.body),
                type: "testset",
                isOpen: true,
                selpos: b.description.getPos(),
                pos: node.getPos()
            });
            return node;
        },
        'Call(PropAccess(Var("describe"), "only"), [String(description), body])', function(b, node) {
{'fraction_non_alphanumeric': 0.15648710166919574, 'fraction_numerical': 0.0011380880121396055, 'mean_word_length': 1.653749370910921, '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': '1744111', 'n_tokens_mistral': 1521, 'n_tokens_neox': 1456, 'n_words': 301}