<commit_before>///<reference path='..\compiler\typescript.ts' />
///<reference path='harness.ts' />
///<reference path='external\json2.ts' />

module FourSlash {
    // Represents a parsed source file with metadata
    export interface FourSlashFile {
        // The contents of the file (with markers, etc stripped out)
        content: string;

        // Filename
        name: string;

        // File-specific options (name/value pairs)
        fileOptions: { [index: string]: string; };
    }

    // Represents a set of parsed source files and options
    export interface FourSlashData {
        // Global options (name/value pairs)
        globalOptions: { [index: string]: string; };

        files: FourSlashFile[];

        // A mapping from marker names to name/position pairs
        markerPositions: { [index: string]: { fileName: string; position: number; }; };
        markerNames: string[];
    }

    interface MemberListData {
        result: {
            maybeInaccurate: bool;
            isMemberCompletion: bool;
            entries: {
                name: string;
                type: string;
                kind: string;
                kindModifiers: string;
            }[];
        };
    }

    interface MarkerMap {
        [index: string]: { fileName: string; position: number; };
    }

    // List of allowed metadata names
    var fileMetadataNames = ['Filename'];
    var globalMetadataNames = ['Module', 'Target']; // Note: Neither actually supported at the moment

    export var currentTestState: TestState = null;

    export class TestState {
        // Language service instance
        public langSvc: Harness.TypeScriptLS;
        private realLangSvc: Services.ILanguageService;

        // The current caret position in the active file
        public currentCaretPosition = 0;

        // The file that's currently 'opened'
        public activeFile: FourSlashFile = null;

        constructor (public testData: FourSlashData) {
            // Initialize the language service with all the scripts
            this.langSvc = new Harness.TypeScriptLS();

            for (var i = 0; i < testData.files.length; i++) {
                this.langSvc.addScript(testData.files[i].name, testData.files[i].content, false);
            }
            
            this.realLangSvc = this.langSvc.getLanguageService().languageService;

            // Open the first file by default
            this.openFile(0);
        }

        // Entry points from fourslash.ts
        public goToMarker(name = '') {
            var marker = this.getMarkerByName(name);
            if (this.activeFile.name !== marker.fileName) {
                this.openFile(marker.fileName);
            }

            if (marker.position === -1 || marker.position > this.langSvc.getScriptSourceLength(this.getActiveFileIndex())) {
                throw new Error('Marker "' + name + '" has been invalidated by unrecoverable edits to the file.');
            }

            this.currentCaretPosition = marker.position;
        }

        public moveCaretRight(count ?= 1) {
            this.currentCaretPosition += count;
            this.currentCaretPosition = Math.min(this.currentCaretPosition, this.langSvc.getScriptSourceLength(this.getActiveFileIndex()));
        }

        // Opens a file given its 0-based index or filename
        public openFile(index: number);
        public openFile(name: string);
        public openFile(indexOrName: any) {
            var fileToOpen: FourSlashFile = this.findFile(indexOrName);
            this.activeFile = fileToOpen;
        }

        public verifyErrorExistsBetweenMarkers(startMarker: string, endMarker: string) {
            var startPos = this.getMarkerByName(startMarker).position;
            var endPos = this.getMarkerByName(endMarker).position;
            var fileIndex = this.getScriptIndex(this.findFile(this.getMarkerByName(startMarker).fileName));
            var errors = this.realLangSvc.getErrors(9999);
            var exists = errors.some(function (error: TypeScript.ErrorEntry) { 
                if (error.unitIndex != fileIndex) return false;
                return ((error.minChar === startPos) && (error.limChar === endPos));
            });
            if (!exists) {
                IO.printLine("Expected error not found.  Error list is:");<commit_msg>Updated test harness to not depend on ES5 only Array.prototype.some method<commit_after>///<reference path='..\compiler\typescript.ts' />
///<reference path='harness.ts' />
///<reference path='external\json2.ts' />

module FourSlash {
    // Represents a parsed source file with metadata
    export interface FourSlashFile {
        // The contents of the file (with markers, etc stripped out)
        content: string;

        // Filename
        name: string;

        // File-specific options (name/value pairs)
        fileOptions: { [index: string]: string; };
    }

    // Represents a set of parsed source files and options
    export interface FourSlashData {
        // Global options (name/value pairs)
        globalOptions: { [index: string]: string; };

        files: FourSlashFile[];

        // A mapping from marker names to name/position pairs
        markerPositions: { [index: string]: { fileName: string; position: number; }; };
        markerNames: string[];
    }

    interface MemberListData {
        result: {
            maybeInaccurate: bool;
            isMemberCompletion: bool;
            entries: {
                name: string;
                type: string;
                kind: string;
                kindModifiers: string;
            }[];
        };
    }

    interface MarkerMap {
        [index: string]: { fileName: string; position: number; };
    }

    // List of allowed metadata names
    var fileMetadataNames = ['Filename'];
    var globalMetadataNames = ['Module', 'Target']; // Note: Neither actually supported at the moment

    export var currentTestState: TestState = null;

    export class TestState {
        // Language service instance
        public langSvc: Harness.TypeScriptLS;
        private realLangSvc: Services.ILanguageService;

        // The current caret position in the active file
        public currentCaretPosition = 0;

        // The file that's currently 'opened'
        public activeFile: FourSlashFile = null;

        constructor (public testData: FourSlashData) {
            // Initialize the language service with all the scripts
            this.langSvc = new Harness.TypeScriptLS();

            for (var i = 0; i < testData.files.length; i++) {
                this.langSvc.addScript(testData.files[i].name, testData.files[i].content, false);
            }
            
            this.realLangSvc = this.langSvc.getLanguageService().languageService;

            // Open the first file by default
            this.openFile(0);
        }

        // Entry points from fourslash.ts
        public goToMarker(name = '') {
            var marker = this.getMarkerByName(name);
            if (this.activeFile.name !== marker.fileName) {
                this.openFile(marker.fileName);
            }

            if (marker.position === -1 || marker.position > this.langSvc.getScriptSourceLength(this.getActiveFileIndex())) {
                throw new Error('Marker "' + name + '" has been invalidated by unrecoverable edits to the file.');
            }

            this.currentCaretPosition = marker.position;
        }

        public moveCaretRight(count ?= 1) {
            this.currentCaretPosition += count;
            this.currentCaretPosition = Math.min(this.currentCaretPosition, this.langSvc.getScriptSourceLength(this.getActiveFileIndex()));
        }

        // Opens a file given its 0-based index or filename
        public openFile(index: number);
        public openFile(name: string);
        public openFile(indexOrName: any) {
            var fileToOpen: FourSlashFile = this.findFile(indexOrName);
            this.activeFile = fileToOpen;
        }

        public verifyErrorExistsBetweenMarkers(startMarker: string, endMarker: string) {
            var startPos = this.getMarkerByName(startMarker).position;
            var endPos = this.getMarkerByName(endMarker).position;
            var fileIndex = this.getScriptIndex(this.findFile(this.getMarkerByName(startMarker).fileName));
            var errors = this.realLangSvc.getErrors(9999);
            var exists = false;
            errors.forEach(function (error: TypeScript.ErrorEntry) {
                if (error.unitIndex != fileIndex) return;
                if ((error.minChar === startPos) && (error.limChar === endPos)) exists = true;
            });
            if (!exists) {
                IO.printLine("Expected error not found.  Error list is:");
{'fraction_non_alphanumeric': 0.10216647662485746, 'fraction_numerical': 0.002622576966932725, 'mean_word_length': 2.138103756708408, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, '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': '4478604', 'n_tokens_mistral': 2305, 'n_tokens_neox': 2236, 'n_words': 611}