SQL Operations Studio Public Preview 1 (0.23) release source code

This commit is contained in:
Karl Burtram
2017-11-09 14:30:27 -08:00
parent b88ecb8d93
commit 3cdac41339
8829 changed files with 759707 additions and 286 deletions

View File

@@ -0,0 +1,208 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
'use strict';
import assert = require('assert');
import os = require('os');
import path = require('path');
import fs = require('fs');
import extfs = require('vs/base/node/extfs');
import uuid = require('vs/base/common/uuid');
import { ConfigWatcher } from 'vs/base/node/config';
import { onError } from 'vs/base/test/common/utils';
suite('Config', () => {
function testFile(callback: (error: Error, path: string, cleanUp: (callback: () => void) => void) => void): void {
const id = uuid.generateUuid();
const parentDir = path.join(os.tmpdir(), 'vsctests', id);
const newDir = path.join(parentDir, 'config', id);
const testFile = path.join(newDir, 'config.json');
extfs.mkdirp(newDir, 493, error => {
callback(error, testFile, (callback) => extfs.del(parentDir, os.tmpdir(), () => { }, callback));
});
}
test('defaults', function () {
const id = uuid.generateUuid();
const parentDir = path.join(os.tmpdir(), 'vsctests', id);
const newDir = path.join(parentDir, 'config', id);
const testFile = path.join(newDir, 'config.json');
let watcher = new ConfigWatcher(testFile);
let config = watcher.getConfig();
assert.ok(config);
assert.equal(Object.keys(config), 0);
watcher.dispose();
let watcher2 = new ConfigWatcher<any[]>(testFile, { defaultConfig: ['foo'], onError: console.error });
let config2 = watcher2.getConfig();
assert.ok(Array.isArray(config2));
assert.equal(config2.length, 1);
watcher.dispose();
});
test('getConfig / getValue', function (done: () => void) {
testFile((error, testFile, cleanUp) => {
if (error) {
return onError(error, done);
}
fs.writeFileSync(testFile, '// my comment\n{ "foo": "bar" }');
let watcher = new ConfigWatcher<{ foo: string; }>(testFile);
let config = watcher.getConfig();
assert.ok(config);
assert.equal(config.foo, 'bar');
assert.equal(watcher.getValue('foo'), 'bar');
assert.equal(watcher.getValue('bar'), void 0);
assert.equal(watcher.getValue('bar', 'fallback'), 'fallback');
assert.ok(!watcher.hasParseErrors);
watcher.dispose();
cleanUp(done);
});
});
test('getConfig / getValue - broken JSON', function (done: () => void) {
testFile((error, testFile, cleanUp) => {
if (error) {
return onError(error, done);
}
fs.writeFileSync(testFile, '// my comment\n "foo": "bar ... ');
let watcher = new ConfigWatcher<{ foo: string; }>(testFile);
let config = watcher.getConfig();
assert.ok(config);
assert.ok(!config.foo);
assert.ok(watcher.hasParseErrors);
watcher.dispose();
cleanUp(done);
});
});
test('watching', function (done: () => void) {
this.timeout(10000); // watching is timing intense
testFile((error, testFile, cleanUp) => {
if (error) {
return onError(error, done);
}
fs.writeFileSync(testFile, '// my comment\n{ "foo": "bar" }');
let watcher = new ConfigWatcher<{ foo: string; }>(testFile);
watcher.getConfig(); // ensure we are in sync
fs.writeFileSync(testFile, '// my comment\n{ "foo": "changed" }');
watcher.onDidUpdateConfiguration(event => {
assert.ok(event);
assert.equal(event.config.foo, 'changed');
assert.equal(watcher.getValue('foo'), 'changed');
watcher.dispose();
cleanUp(done);
});
});
});
test('watching also works when file created later', function (done: () => void) {
this.timeout(10000); // watching is timing intense
testFile((error, testFile, cleanUp) => {
if (error) {
return onError(error, done);
}
let watcher = new ConfigWatcher<{ foo: string; }>(testFile);
watcher.getConfig(); // ensure we are in sync
fs.writeFileSync(testFile, '// my comment\n{ "foo": "changed" }');
watcher.onDidUpdateConfiguration(event => {
assert.ok(event);
assert.equal(event.config.foo, 'changed');
assert.equal(watcher.getValue('foo'), 'changed');
watcher.dispose();
cleanUp(done);
});
});
});
test('watching detects the config file getting deleted', function (done: () => void) {
this.timeout(10000); // watching is timing intense
testFile((error, testFile, cleanUp) => {
if (error) {
return onError(error, done);
}
fs.writeFileSync(testFile, '// my comment\n{ "foo": "bar" }');
let watcher = new ConfigWatcher<{ foo: string; }>(testFile);
watcher.getConfig(); // ensure we are in sync
watcher.onDidUpdateConfiguration(event => {
assert.ok(event);
watcher.dispose();
cleanUp(done);
});
fs.unlinkSync(testFile);
});
});
test('reload', function (done: () => void) {
testFile((error, testFile, cleanUp) => {
if (error) {
return onError(error, done);
}
fs.writeFileSync(testFile, '// my comment\n{ "foo": "bar" }');
let watcher = new ConfigWatcher<{ foo: string; }>(testFile, { changeBufferDelay: 100, onError: console.error });
watcher.getConfig(); // ensure we are in sync
fs.writeFileSync(testFile, '// my comment\n{ "foo": "changed" }');
// still old values because change is not bubbling yet
assert.equal(watcher.getConfig().foo, 'bar');
assert.equal(watcher.getValue('foo'), 'bar');
// force a load from disk
watcher.reload(config => {
assert.equal(config.foo, 'changed');
assert.equal(watcher.getConfig().foo, 'changed');
assert.equal(watcher.getValue('foo'), 'changed');
watcher.dispose();
cleanUp(done);
});
});
});
});

View File

@@ -0,0 +1,24 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
'use strict';
import * as assert from 'assert';
import decoder = require('vs/base/node/decoder');
suite('Decoder', () => {
test('decoding', function () {
const lineDecoder = new decoder.LineDecoder();
let res = lineDecoder.write(new Buffer('hello'));
assert.equal(res.length, 0);
res = lineDecoder.write(new Buffer('\nworld'));
assert.equal(res[0], 'hello');
assert.equal(res.length, 1);
assert.equal(lineDecoder.end(), 'world');
});
});

View File

@@ -0,0 +1,57 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
'use strict';
import assert = require('assert');
import encoding = require('vs/base/node/encoding');
suite('Encoding', () => {
test('detectBOM UTF-8', (done: (err?: any) => void) => {
const file = require.toUrl('./fixtures/some_utf8.css');
encoding.detectEncodingByBOM(file).then((encoding: string) => {
assert.equal(encoding, 'utf8');
done();
}, done);
});
test('detectBOM UTF-16 LE', (done: (err?: any) => void) => {
const file = require.toUrl('./fixtures/some_utf16le.css');
encoding.detectEncodingByBOM(file).then((encoding: string) => {
assert.equal(encoding, 'utf16le');
done();
}, done);
});
test('detectBOM UTF-16 BE', (done: (err?: any) => void) => {
const file = require.toUrl('./fixtures/some_utf16be.css');
encoding.detectEncodingByBOM(file).then((encoding: string) => {
assert.equal(encoding, 'utf16be');
done();
}, done);
});
test('detectBOM ANSI', function (done: (err?: any) => void) {
const file = require.toUrl('./fixtures/some_ansi.css');
encoding.detectEncodingByBOM(file).then((encoding: string) => {
assert.equal(encoding, null);
done();
}, done);
});
test('detectBOM ANSI', function (done: (err?: any) => void) {
const file = require.toUrl('./fixtures/empty.txt');
encoding.detectEncodingByBOM(file).then((encoding: string) => {
assert.equal(encoding, null);
done();
}, done);
});
});

View File

@@ -0,0 +1,40 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
/*----------------------------------------------------------
The base color for this template is #5c87b2. If you'd like
to use a different color start by replacing all instances of
#5c87b2 with your new color.
----------------------------------------------------------*/
body
{
background-color: #5c87b2;
font-size: .75em;
font-family: Segoe UI, Verdana, Helvetica, Sans-Serif;
margin: 8px;
padding: 0;
color: #696969;
}
h1, h2, h3, h4, h5, h6
{
color: #000;
font-size: 40px;
margin: 0px;
}
textarea
{
font-family: Consolas
}
#results
{
margin-top: 2em;
margin-left: 2em;
color: black;
font-size: medium;
}

View File

@@ -0,0 +1,40 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
/*----------------------------------------------------------
The base color for this template is #5c87b2. If you'd like
to use a different color start by replacing all instances of
#5c87b2 with your new color.
----------------------------------------------------------*/
body
{
background-color: #5c87b2;
font-size: .75em;
font-family: Segoe UI, Verdana, Helvetica, Sans-Serif;
margin: 8px;
padding: 0;
color: #696969;
}
h1, h2, h3, h4, h5, h6
{
color: #000;
font-size: 40px;
margin: 0px;
}
textarea
{
font-family: Consolas
}
#results
{
margin-top: 2em;
margin-left: 2em;
color: black;
font-size: medium;
}

View File

@@ -0,0 +1,268 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
'use strict';
import assert = require('assert');
import os = require('os');
import path = require('path');
import fs = require('fs');
import uuid = require('vs/base/common/uuid');
import strings = require('vs/base/common/strings');
import extfs = require('vs/base/node/extfs');
import { onError } from 'vs/base/test/common/utils';
suite('Extfs', () => {
test('mkdirp', function (done: () => void) {
const id = uuid.generateUuid();
const parentDir = path.join(os.tmpdir(), 'vsctests', id);
const newDir = path.join(parentDir, 'extfs', id);
extfs.mkdirp(newDir, 493, (error) => {
if (error) {
return onError(error, done);
}
assert.ok(fs.existsSync(newDir));
extfs.del(parentDir, os.tmpdir(), () => { }, done);
}); // 493 = 0755
});
test('delSync - swallows file not found error', function () {
const id = uuid.generateUuid();
const parentDir = path.join(os.tmpdir(), 'vsctests', id);
const newDir = path.join(parentDir, 'extfs', id);
extfs.delSync(newDir);
assert.ok(!fs.existsSync(newDir));
});
test('delSync - simple', function (done: () => void) {
const id = uuid.generateUuid();
const parentDir = path.join(os.tmpdir(), 'vsctests', id);
const newDir = path.join(parentDir, 'extfs', id);
extfs.mkdirp(newDir, 493, (error) => {
if (error) {
return onError(error, done);
}
fs.writeFileSync(path.join(newDir, 'somefile.txt'), 'Contents');
fs.writeFileSync(path.join(newDir, 'someOtherFile.txt'), 'Contents');
extfs.delSync(newDir);
assert.ok(!fs.existsSync(newDir));
done();
}); // 493 = 0755
});
test('delSync - recursive folder structure', function (done: () => void) {
const id = uuid.generateUuid();
const parentDir = path.join(os.tmpdir(), 'vsctests', id);
const newDir = path.join(parentDir, 'extfs', id);
extfs.mkdirp(newDir, 493, (error) => {
if (error) {
return onError(error, done);
}
fs.writeFileSync(path.join(newDir, 'somefile.txt'), 'Contents');
fs.writeFileSync(path.join(newDir, 'someOtherFile.txt'), 'Contents');
fs.mkdirSync(path.join(newDir, 'somefolder'));
fs.writeFileSync(path.join(newDir, 'somefolder', 'somefile.txt'), 'Contents');
extfs.delSync(newDir);
assert.ok(!fs.existsSync(newDir));
done();
}); // 493 = 0755
});
test('copy, move and delete', function (done: () => void) {
const id = uuid.generateUuid();
const id2 = uuid.generateUuid();
const sourceDir = require.toUrl('./fixtures');
const parentDir = path.join(os.tmpdir(), 'vsctests', 'extfs');
const targetDir = path.join(parentDir, id);
const targetDir2 = path.join(parentDir, id2);
extfs.copy(sourceDir, targetDir, (error) => {
if (error) {
return onError(error, done);
}
assert.ok(fs.existsSync(targetDir));
assert.ok(fs.existsSync(path.join(targetDir, 'index.html')));
assert.ok(fs.existsSync(path.join(targetDir, 'site.css')));
assert.ok(fs.existsSync(path.join(targetDir, 'examples')));
assert.ok(fs.statSync(path.join(targetDir, 'examples')).isDirectory());
assert.ok(fs.existsSync(path.join(targetDir, 'examples', 'small.jxs')));
extfs.mv(targetDir, targetDir2, (error) => {
if (error) {
return onError(error, done);
}
assert.ok(!fs.existsSync(targetDir));
assert.ok(fs.existsSync(targetDir2));
assert.ok(fs.existsSync(path.join(targetDir2, 'index.html')));
assert.ok(fs.existsSync(path.join(targetDir2, 'site.css')));
assert.ok(fs.existsSync(path.join(targetDir2, 'examples')));
assert.ok(fs.statSync(path.join(targetDir2, 'examples')).isDirectory());
assert.ok(fs.existsSync(path.join(targetDir2, 'examples', 'small.jxs')));
extfs.mv(path.join(targetDir2, 'index.html'), path.join(targetDir2, 'index_moved.html'), (error) => {
if (error) {
return onError(error, done);
}
assert.ok(!fs.existsSync(path.join(targetDir2, 'index.html')));
assert.ok(fs.existsSync(path.join(targetDir2, 'index_moved.html')));
extfs.del(parentDir, os.tmpdir(), (error) => {
if (error) {
return onError(error, done);
}
}, (error) => {
if (error) {
return onError(error, done);
}
assert.ok(!fs.existsSync(parentDir));
done();
});
});
});
});
});
test('readdir', function (done: () => void) {
if (strings.canNormalize && typeof process.versions['electron'] !== 'undefined' /* needs electron */) {
const id = uuid.generateUuid();
const parentDir = path.join(os.tmpdir(), 'vsctests', id);
const newDir = path.join(parentDir, 'extfs', id, 'öäü');
extfs.mkdirp(newDir, 493, (error) => {
if (error) {
return onError(error, done);
}
assert.ok(fs.existsSync(newDir));
extfs.readdir(path.join(parentDir, 'extfs', id), (error, children) => {
assert.equal(children.some(n => n === 'öäü'), true); // Mac always converts to NFD, so
extfs.del(parentDir, os.tmpdir(), () => { }, done);
});
}); // 493 = 0755
} else {
done();
}
});
test('writeFileAndFlush', function (done: () => void) {
const id = uuid.generateUuid();
const parentDir = path.join(os.tmpdir(), 'vsctests', id);
const newDir = path.join(parentDir, 'extfs', id);
const testFile = path.join(newDir, 'flushed.txt');
extfs.mkdirp(newDir, 493, (error) => {
if (error) {
return onError(error, done);
}
assert.ok(fs.existsSync(newDir));
extfs.writeFileAndFlush(testFile, 'Hello World', null, (error) => {
if (error) {
return onError(error, done);
}
assert.equal(fs.readFileSync(testFile), 'Hello World');
const largeString = (new Array(100 * 1024)).join('Large String\n');
extfs.writeFileAndFlush(testFile, largeString, null, (error) => {
if (error) {
return onError(error, done);
}
assert.equal(fs.readFileSync(testFile), largeString);
extfs.del(parentDir, os.tmpdir(), () => { }, done);
});
});
});
});
test('realcase', (done) => {
const id = uuid.generateUuid();
const parentDir = path.join(os.tmpdir(), 'vsctests', id);
const newDir = path.join(parentDir, 'extfs', id);
extfs.mkdirp(newDir, 493, (error) => {
// assume case insensitive file system
if (process.platform === 'win32' || process.platform === 'darwin') {
const upper = newDir.toUpperCase();
const real = extfs.realcaseSync(upper);
if (real) { // can be null in case of permission errors
assert.notEqual(real, upper);
assert.equal(real.toUpperCase(), upper);
assert.equal(real, newDir);
}
}
// linux, unix, etc. -> assume case sensitive file system
else {
const real = extfs.realcaseSync(newDir);
assert.equal(real, newDir);
}
extfs.del(parentDir, os.tmpdir(), () => { }, done);
});
});
test('realpath', (done) => {
const id = uuid.generateUuid();
const parentDir = path.join(os.tmpdir(), 'vsctests', id);
const newDir = path.join(parentDir, 'extfs', id);
extfs.mkdirp(newDir, 493, (error) => {
extfs.realpath(newDir, (error, realpath) => {
assert.ok(realpath);
assert.ok(!error);
extfs.del(parentDir, os.tmpdir(), () => { }, done);
});
});
});
test('realpathSync', (done) => {
const id = uuid.generateUuid();
const parentDir = path.join(os.tmpdir(), 'vsctests', id);
const newDir = path.join(parentDir, 'extfs', id);
extfs.mkdirp(newDir, 493, (error) => {
let realpath: string;
try {
realpath = extfs.realpathSync(newDir);
} catch (error) {
assert.ok(!error);
}
assert.ok(realpath);
extfs.del(parentDir, os.tmpdir(), () => { }, done);
});
});
});

View File

@@ -0,0 +1,23 @@
'use strict';
/// <reference path="employee.ts" />
var Workforce;
(function (Workforce_1) {
var Company = (function () {
function Company() {
}
return Company;
})();
(function (property, Workforce, IEmployee) {
if (property === void 0) { property = employees; }
if (IEmployee === void 0) { IEmployee = []; }
property;
calculateMonthlyExpenses();
{
var result = 0;
for (var i = 0; i < employees.length; i++) {
result += employees[i].calculatePay();
}
return result;
}
});
})(Workforce || (Workforce = {}));

View File

@@ -0,0 +1,117 @@
'use strict';
var Conway;
(function (Conway) {
var Cell = (function () {
function Cell() {
}
return Cell;
})();
(function (property, number, property, number, property, boolean) {
if (property === void 0) { property = row; }
if (property === void 0) { property = col; }
if (property === void 0) { property = live; }
});
var GameOfLife = (function () {
function GameOfLife() {
}
return GameOfLife;
})();
(function () {
property;
gridSize = 50;
property;
canvasSize = 600;
property;
lineColor = '#cdcdcd';
property;
liveColor = '#666';
property;
deadColor = '#eee';
property;
initialLifeProbability = 0.5;
property;
animationRate = 60;
property;
cellSize = 0;
property;
context: ICanvasRenderingContext2D;
property;
world = createWorld();
circleOfLife();
function createWorld() {
return travelWorld(function (cell) {
cell.live = Math.random() < initialLifeProbability;
return cell;
});
}
function circleOfLife() {
world = travelWorld(function (cell) {
cell = world[cell.row][cell.col];
draw(cell);
return resolveNextGeneration(cell);
});
setTimeout(function () { circleOfLife(); }, animationRate);
}
function resolveNextGeneration(cell) {
var count = countNeighbors(cell);
var newCell = new Cell(cell.row, cell.col, cell.live);
if (count < 2 || count > 3)
newCell.live = false;
else if (count == 3)
newCell.live = true;
return newCell;
}
function countNeighbors(cell) {
var neighbors = 0;
for (var row = -1; row <= 1; row++) {
for (var col = -1; col <= 1; col++) {
if (row == 0 && col == 0)
continue;
if (isAlive(cell.row + row, cell.col + col)) {
neighbors++;
}
}
}
return neighbors;
}
function isAlive(row, col) {
// todo - need to guard with world[row] exists?
if (row < 0 || col < 0 || row >= gridSize || col >= gridSize)
return false;
return world[row][col].live;
}
function travelWorld(callback) {
var result = [];
for (var row = 0; row < gridSize; row++) {
var rowData = [];
for (var col = 0; col < gridSize; col++) {
rowData.push(callback(new Cell(row, col, false)));
}
result.push(rowData);
}
return result;
}
function draw(cell) {
if (context == null)
context = createDrawingContext();
if (cellSize == 0)
cellSize = canvasSize / gridSize;
context.strokeStyle = lineColor;
context.strokeRect(cell.row * cellSize, cell.col * cellSize, cellSize, cellSize);
context.fillStyle = cell.live ? liveColor : deadColor;
context.fillRect(cell.row * cellSize, cell.col * cellSize, cellSize, cellSize);
}
function createDrawingContext() {
var canvas = document.getElementById('conway-canvas');
if (canvas == null) {
canvas = document.createElement('canvas');
canvas.id = "conway-canvas";
canvas.width = canvasSize;
canvas.height = canvasSize;
document.body.appendChild(canvas);
}
return canvas.getContext('2d');
}
});
})(Conway || (Conway = {}));
var game = new Conway.GameOfLife();

View File

@@ -0,0 +1,38 @@
'use strict';
var Workforce;
(function (Workforce) {
var Employee = (function () {
function Employee() {
}
return Employee;
})();
(property);
name: string, property;
basepay: number;
implements;
IEmployee;
{
name;
basepay;
}
var SalesEmployee = (function () {
function SalesEmployee() {
}
return SalesEmployee;
})();
();
Employee(name, basepay);
{
function calculatePay() {
var multiplier = (document.getElementById("mult")), as = any, value;
return _super.calculatePay.call(this) * multiplier + bonus;
}
}
var employee = new Employee('Bob', 1000);
var salesEmployee = new SalesEmployee('Jim', 800, 400);
salesEmployee.calclatePay(); // error: No member 'calclatePay' on SalesEmployee
})(Workforce || (Workforce = {}));
extern;
var $;
var s = Workforce.salesEmployee.calculatePay();
$('#results').text(s);

View File

@@ -0,0 +1,24 @@
'use strict';
var M;
(function (M) {
var C = (function () {
function C() {
}
return C;
})();
(function (x, property, number) {
if (property === void 0) { property = w; }
var local = 1;
// unresolved symbol because x is local
//self.x++;
self.w--; // ok because w is a property
property;
f = function (y) {
return y + x + local + w + self.w;
};
function sum(z) {
return z + f(z) + w + self.w;
}
});
})(M || (M = {}));
var c = new M.C(12, 5);

View File

@@ -0,0 +1,121 @@
<!DOCTYPE html>
<html>
<head id='headID'>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<title>Strada </title>
<link href="site.css" rel="stylesheet" type="text/css" />
<script src="jquery-1.4.1.js"></script>
<script src="../compiler/dtree.js" type="text/javascript"></script>
<script src="../compiler/typescript.js" type="text/javascript"></script>
<script type="text/javascript">
// Compile strada source into resulting javascript
function compile(prog, libText) {
var outfile = {
source: "",
Write: function (s) { this.source += s; },
WriteLine: function (s) { this.source += s + "\r"; },
}
var parseErrors = []
var compiler=new Tools.TypeScriptCompiler(outfile,true);
compiler.setErrorCallback(function(start,len, message) { parseErrors.push({start:start, len:len, message:message}); });
compiler.addUnit(libText,"lib.ts");
compiler.addUnit(prog,"input.ts");
compiler.typeCheck();
compiler.emit();
if(parseErrors.length > 0 ) {
//throw new Error(parseErrors);
}
while(outfile.source[0] == '/' && outfile.source[1] == '/' && outfile.source[2] == ' ') {
outfile.source = outfile.source.slice(outfile.source.indexOf('\r')+1);
}
var errorPrefix = "";
for(var i = 0;i<parseErrors.length;i++) {
errorPrefix += "// Error: (" + parseErrors[i].start + "," + parseErrors[i].len + ") " + parseErrors[i].message + "\r";
}
return errorPrefix + outfile.source;
}
</script>
<script type="text/javascript">
var libText = "";
$.get("../compiler/lib.ts", function(newLibText) {
libText = newLibText;
});
// execute the javascript in the compiledOutput pane
function execute() {
$('#compilation').text("Running...");
var txt = $('#compiledOutput').val();
var res;
try {
var ret = eval(txt);
res = "Ran successfully!";
} catch(e) {
res = "Exception thrown: " + e;
}
$('#compilation').text(String(res));
}
// recompile the stradaSrc and populate the compiledOutput pane
function srcUpdated() {
var newText = $('#stradaSrc').val();
var compiledSource;
try {
compiledSource = compile(newText, libText);
} catch (e) {
compiledSource = "//Parse error"
for(var i in e)
compiledSource += "\r// " + e[i];
}
$('#compiledOutput').val(compiledSource);
}
// Populate the stradaSrc pane with one of the built in samples
function exampleSelectionChanged() {
var examples = document.getElementById('examples');
var selectedExample = examples.options[examples.selectedIndex].value;
if (selectedExample != "") {
$.get('examples/' + selectedExample, function (srcText) {
$('#stradaSrc').val(srcText);
setTimeout(srcUpdated,100);
}, function (err) {
console.log(err);
});
}
}
</script>
</head>
<body>
<h1>TypeScript</h1>
<br />
<select id="examples" onchange='exampleSelectionChanged()'>
<option value="">Select...</option>
<option value="small.ts">Small</option>
<option value="employee.ts">Employees</option>
<option value="conway.ts">Conway Game of Life</option>
<option value="typescript.ts">TypeScript Compiler</option>
</select>
<div>
<textarea id='stradaSrc' rows='40' cols='80' onchange='srcUpdated()' onkeyup='srcUpdated()' spellcheck="false">
//Type your TypeScript here...
</textarea>
<textarea id='compiledOutput' rows='40' cols='80' spellcheck="false">
//Compiled code will show up here...
</textarea>
<br />
<button onclick='execute()'/>Run</button>
<div id='compilation'>Press 'run' to execute code...</div>
<div id='results'>...write your results into #results...</div>
</div>
<div id='bod' style='display:none'></div>
</body>
</html>

View File

@@ -0,0 +1,40 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
/*----------------------------------------------------------
The base color for this template is #5c87b2. If you'd like
to use a different color start by replacing all instances of
#5c87b2 with your new color.
----------------------------------------------------------*/
body
{
background-color: #5c87b2;
font-size: .75em;
font-family: Segoe UI, Verdana, Helvetica, Sans-Serif;
margin: 8px;
padding: 0;
color: #696969;
}
h1, h2, h3, h4, h5, h6
{
color: #000;
font-size: 40px;
margin: 0px;
}
textarea
{
font-family: Consolas
}
#results
{
margin-top: 2em;
margin-left: 2em;
color: black;
font-size: medium;
}

View File

@@ -0,0 +1,490 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
'use strict';
import * as assert from 'assert';
import flow = require('vs/base/node/flow');
const loop = flow.loop;
const sequence = flow.sequence;
const parallel = flow.parallel;
suite('Flow', () => {
function assertCounterEquals(counter, expected): void {
assert.ok(counter === expected, 'Expected ' + expected + ' assertions, but got ' + counter);
}
function syncThrowsError(callback): void {
callback(new Error('foo'), null);
}
function syncSequenceGetThrowsError(value, callback) {
sequence(
function onError(error) {
callback(error, null);
},
function getFirst() {
syncThrowsError(this);
},
function handleFirst(first) {
//Foo
}
);
}
function syncGet(value, callback): void {
callback(null, value);
}
function syncGetError(value, callback): void {
callback(new Error(''), null);
}
function asyncGet(value, callback): void {
process.nextTick(function () {
callback(null, value);
});
}
function asyncGetError(value, callback): void {
process.nextTick(function () {
callback(new Error(''), null);
});
}
test('loopSync', function (done: () => void) {
const elements = ['1', '2', '3'];
loop(elements, function (element, callback, index, total) {
assert.ok(index === 0 || index === 1 || index === 2);
assert.deepEqual(3, total);
callback(null, element);
}, function (error, result) {
assert.equal(error, null);
assert.deepEqual(result, elements);
done();
});
});
test('loopByFunctionSync', function (done: () => void) {
const elements = function (callback) {
callback(null, ['1', '2', '3']);
};
loop(elements, function (element, callback) {
callback(null, element);
}, function (error, result) {
assert.equal(error, null);
assert.deepEqual(result, ['1', '2', '3']);
done();
});
});
test('loopByFunctionAsync', function (done: () => void) {
const elements = function (callback) {
process.nextTick(function () {
callback(null, ['1', '2', '3']);
});
};
loop(elements, function (element, callback) {
callback(null, element);
}, function (error, result) {
assert.equal(error, null);
assert.deepEqual(result, ['1', '2', '3']);
done();
});
});
test('loopSyncErrorByThrow', function (done: () => void) {
const elements = ['1', '2', '3'];
loop(elements, function (element, callback) {
if (element === '2') {
throw new Error('foo');
} else {
callback(null, element);
}
}, function (error, result) {
assert.ok(error);
assert.ok(!result);
done();
});
});
test('loopSyncErrorByCallback', function (done: () => void) {
const elements = ['1', '2', '3'];
loop(elements, function (element, callback) {
if (element === '2') {
callback(new Error('foo'), null);
} else {
callback(null, element);
}
}, function (error, result) {
assert.ok(error);
assert.ok(!result);
done();
});
});
test('loopAsync', function (done: () => void) {
const elements = ['1', '2', '3'];
loop(elements, function (element, callback) {
process.nextTick(function () {
callback(null, element);
});
}, function (error, result) {
assert.equal(error, null);
assert.deepEqual(result, elements);
done();
});
});
test('loopAsyncErrorByCallback', function (done: () => void) {
const elements = ['1', '2', '3'];
loop(elements, function (element, callback) {
process.nextTick(function () {
if (element === '2') {
callback(new Error('foo'), null);
} else {
callback(null, element);
}
});
}, function (error, result) {
assert.ok(error);
assert.ok(!result);
done();
});
});
test('sequenceSync', function (done: () => void) {
let assertionCount = 0;
let errorCount = 0;
sequence(
function onError(error) {
errorCount++;
},
function getFirst() {
syncGet('1', this);
},
function handleFirst(first) {
assert.deepEqual('1', first);
assertionCount++;
syncGet('2', this);
},
function handleSecond(second) {
assert.deepEqual('2', second);
assertionCount++;
syncGet(null, this);
},
function handleThird(third) {
assert.ok(!third);
assertionCount++;
assertCounterEquals(assertionCount, 3);
assertCounterEquals(errorCount, 0);
done();
}
);
});
test('sequenceAsync', function (done: () => void) {
let assertionCount = 0;
let errorCount = 0;
sequence(
function onError(error) {
errorCount++;
},
function getFirst() {
asyncGet('1', this);
},
function handleFirst(first) {
assert.deepEqual('1', first);
assertionCount++;
asyncGet('2', this);
},
function handleSecond(second) {
assert.deepEqual('2', second);
assertionCount++;
asyncGet(null, this);
},
function handleThird(third) {
assert.ok(!third);
assertionCount++;
assertCounterEquals(assertionCount, 3);
assertCounterEquals(errorCount, 0);
done();
}
);
});
test('sequenceSyncErrorByThrow', function (done: () => void) {
let assertionCount = 0;
let errorCount = 0;
sequence(
function onError(error) {
errorCount++;
assertCounterEquals(assertionCount, 1);
assertCounterEquals(errorCount, 1);
done();
},
function getFirst() {
syncGet('1', this);
},
function handleFirst(first) {
assert.deepEqual('1', first);
assertionCount++;
syncGet('2', this);
},
function handleSecond(second) {
if (true) {
throw new Error('');
}
// assertionCount++;
// syncGet(null, this);
},
function handleThird(third) {
throw new Error('We should not be here');
}
);
});
test('sequenceSyncErrorByCallback', function (done: () => void) {
let assertionCount = 0;
let errorCount = 0;
sequence(
function onError(error) {
errorCount++;
assertCounterEquals(assertionCount, 1);
assertCounterEquals(errorCount, 1);
done();
},
function getFirst() {
syncGet('1', this);
},
function handleFirst(first) {
assert.deepEqual('1', first);
assertionCount++;
syncGetError('2', this);
},
function handleSecond(second) {
throw new Error('We should not be here');
}
);
});
test('sequenceAsyncErrorByThrow', function (done: () => void) {
let assertionCount = 0;
let errorCount = 0;
sequence(
function onError(error) {
errorCount++;
assertCounterEquals(assertionCount, 1);
assertCounterEquals(errorCount, 1);
done();
},
function getFirst() {
asyncGet('1', this);
},
function handleFirst(first) {
assert.deepEqual('1', first);
assertionCount++;
asyncGet('2', this);
},
function handleSecond(second) {
if (true) {
throw new Error('');
}
// assertionCount++;
// asyncGet(null, this);
},
function handleThird(third) {
throw new Error('We should not be here');
}
);
});
test('sequenceAsyncErrorByCallback', function (done: () => void) {
let assertionCount = 0;
let errorCount = 0;
sequence(
function onError(error) {
errorCount++;
assertCounterEquals(assertionCount, 1);
assertCounterEquals(errorCount, 1);
done();
},
function getFirst() {
asyncGet('1', this);
},
function handleFirst(first) {
assert.deepEqual('1', first);
assertionCount++;
asyncGetError('2', this);
},
function handleSecond(second) {
throw new Error('We should not be here');
}
);
});
test('syncChainedSequenceError', function (done: () => void) {
sequence(
function onError(error) {
done();
},
function getFirst() {
syncSequenceGetThrowsError('1', this);
}
);
});
test('tolerateBooleanResults', function (done: () => void) {
let assertionCount = 0;
let errorCount = 0;
sequence(
function onError(error) {
errorCount++;
},
function getFirst() {
this(true);
},
function getSecond(result) {
assert.equal(result, true);
this(false);
},
function last(result) {
assert.equal(result, false);
assertionCount++;
assertCounterEquals(assertionCount, 1);
assertCounterEquals(errorCount, 0);
done();
}
);
});
test('loopTolerateBooleanResults', function (done: () => void) {
let elements = ['1', '2', '3'];
loop(elements, function (element, callback) {
process.nextTick(function () {
(<any>callback)(true);
});
}, function (error, result) {
assert.equal(error, null);
assert.deepEqual(result, [true, true, true]);
done();
});
});
test('parallel', function (done: () => void) {
let elements = [1, 2, 3, 4, 5];
let sum = 0;
parallel(elements, function (element, callback) {
sum += element;
callback(null, element * element);
}, function (errors, result) {
assert.ok(!errors);
assert.deepEqual(sum, 15);
assert.deepEqual(result, [1, 4, 9, 16, 25]);
done();
});
});
test('parallel - setTimeout', function (done: () => void) {
let elements = [1, 2, 3, 4, 5];
let timeouts = [10, 30, 5, 0, 4];
let sum = 0;
parallel(elements, function (element, callback) {
setTimeout(function () {
sum += element;
callback(null, element * element);
}, timeouts.pop());
}, function (errors, result) {
assert.ok(!errors);
assert.deepEqual(sum, 15);
assert.deepEqual(result, [1, 4, 9, 16, 25]);
done();
});
});
test('parallel - with error', function (done: () => void) {
const elements = [1, 2, 3, 4, 5];
const timeouts = [10, 30, 5, 0, 4];
let sum = 0;
parallel(elements, function (element, callback) {
setTimeout(function () {
if (element === 4) {
callback(new Error('error!'), null);
} else {
sum += element;
callback(null, element * element);
}
}, timeouts.pop());
}, function (errors, result) {
assert.ok(errors);
assert.deepEqual(errors, [null, null, null, new Error('error!'), null]);
assert.deepEqual(sum, 11);
assert.deepEqual(result, [1, 4, 9, null, 25]);
done();
});
});
});

View File

@@ -0,0 +1,887 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
'use strict';
import * as assert from 'assert';
import * as path from 'path';
import glob = require('vs/base/common/glob');
suite('Glob', () => {
// test('perf', function () {
// let patterns = [
// '{**/*.cs,**/*.json,**/*.csproj,**/*.sln}',
// '{**/*.cs,**/*.csproj,**/*.sln}',
// '{**/*.ts,**/*.tsx,**/*.js,**/*.jsx,**/*.es6,**/*.mjs}',
// '**/*.go',
// '{**/*.ps,**/*.ps1}',
// '{**/*.c,**/*.cpp,**/*.h}',
// '{**/*.fsx,**/*.fsi,**/*.fs,**/*.ml,**/*.mli}',
// '{**/*.js,**/*.jsx,**/*.es6,**/*.mjs}',
// '{**/*.ts,**/*.tsx}',
// '{**/*.php}',
// '{**/*.php}',
// '{**/*.php}',
// '{**/*.php}',
// '{**/*.py}',
// '{**/*.py}',
// '{**/*.py}',
// '{**/*.rs,**/*.rslib}',
// '{**/*.cpp,**/*.cc,**/*.h}',
// '{**/*.md}',
// '{**/*.md}',
// '{**/*.md}'
// ];
// let paths = [
// '/DNXConsoleApp/Program.cs',
// 'C:\\DNXConsoleApp\\foo\\Program.cs',
// 'test/qunit',
// 'test/test.txt',
// 'test/node_modules',
// '.hidden.txt',
// '/node_module/test/foo.js'
// ];
// let results = 0;
// let c = 1000;
// console.profile('glob.match');
// while (c-- > 0) {
// for (let path of paths) {
// for (let pattern of patterns) {
// let r = glob.match(pattern, path);
// if (r) {
// results += 42;
// }
// }
// }
// }
// console.profileEnd();
// });
test('simple', function () {
let p = 'node_modules';
assert(glob.match(p, 'node_modules'));
assert(!glob.match(p, 'node_module'));
assert(!glob.match(p, '/node_modules'));
assert(!glob.match(p, 'test/node_modules'));
p = 'test.txt';
assert(glob.match(p, 'test.txt'));
assert(!glob.match(p, 'test?txt'));
assert(!glob.match(p, '/text.txt'));
assert(!glob.match(p, 'test/test.txt'));
p = 'test(.txt';
assert(glob.match(p, 'test(.txt'));
assert(!glob.match(p, 'test?txt'));
p = 'qunit';
assert(glob.match(p, 'qunit'));
assert(!glob.match(p, 'qunit.css'));
assert(!glob.match(p, 'test/qunit'));
// Absolute
p = '/DNXConsoleApp/**/*.cs';
assert(glob.match(p, '/DNXConsoleApp/Program.cs'));
assert(glob.match(p, '/DNXConsoleApp/foo/Program.cs'));
p = 'C:/DNXConsoleApp/**/*.cs';
assert(glob.match(p, 'C:\\DNXConsoleApp\\Program.cs'));
assert(glob.match(p, 'C:\\DNXConsoleApp\\foo\\Program.cs'));
});
test('dot hidden', function () {
let p = '.*';
assert(glob.match(p, '.git'));
assert(glob.match(p, '.hidden.txt'));
assert(!glob.match(p, 'git'));
assert(!glob.match(p, 'hidden.txt'));
assert(!glob.match(p, 'path/.git'));
assert(!glob.match(p, 'path/.hidden.txt'));
p = '**/.*';
assert(glob.match(p, '.git'));
assert(glob.match(p, '.hidden.txt'));
assert(!glob.match(p, 'git'));
assert(!glob.match(p, 'hidden.txt'));
assert(glob.match(p, 'path/.git'));
assert(glob.match(p, 'path/.hidden.txt'));
assert(!glob.match(p, 'path/git'));
assert(!glob.match(p, 'pat.h/hidden.txt'));
p = '._*';
assert(glob.match(p, '._git'));
assert(glob.match(p, '._hidden.txt'));
assert(!glob.match(p, 'git'));
assert(!glob.match(p, 'hidden.txt'));
assert(!glob.match(p, 'path/._git'));
assert(!glob.match(p, 'path/._hidden.txt'));
p = '**/._*';
assert(glob.match(p, '._git'));
assert(glob.match(p, '._hidden.txt'));
assert(!glob.match(p, 'git'));
assert(!glob.match(p, 'hidden._txt'));
assert(glob.match(p, 'path/._git'));
assert(glob.match(p, 'path/._hidden.txt'));
assert(!glob.match(p, 'path/git'));
assert(!glob.match(p, 'pat.h/hidden._txt'));
});
test('file pattern', function () {
let p = '*.js';
assert(glob.match(p, 'foo.js'));
assert(!glob.match(p, 'folder/foo.js'));
assert(!glob.match(p, '/node_modules/foo.js'));
assert(!glob.match(p, 'foo.jss'));
assert(!glob.match(p, 'some.js/test'));
p = 'html.*';
assert(glob.match(p, 'html.js'));
assert(glob.match(p, 'html.txt'));
assert(!glob.match(p, 'htm.txt'));
p = '*.*';
assert(glob.match(p, 'html.js'));
assert(glob.match(p, 'html.txt'));
assert(glob.match(p, 'htm.txt'));
assert(!glob.match(p, 'folder/foo.js'));
assert(!glob.match(p, '/node_modules/foo.js'));
p = 'node_modules/test/*.js';
assert(glob.match(p, 'node_modules/test/foo.js'));
assert(!glob.match(p, 'folder/foo.js'));
assert(!glob.match(p, '/node_module/test/foo.js'));
assert(!glob.match(p, 'foo.jss'));
assert(!glob.match(p, 'some.js/test'));
});
test('star', function () {
let p = 'node*modules';
assert(glob.match(p, 'node_modules'));
assert(glob.match(p, 'node_super_modules'));
assert(!glob.match(p, 'node_module'));
assert(!glob.match(p, '/node_modules'));
assert(!glob.match(p, 'test/node_modules'));
p = '*';
assert(glob.match(p, 'html.js'));
assert(glob.match(p, 'html.txt'));
assert(glob.match(p, 'htm.txt'));
assert(!glob.match(p, 'folder/foo.js'));
assert(!glob.match(p, '/node_modules/foo.js'));
});
test('questionmark', function () {
let p = 'node?modules';
assert(glob.match(p, 'node_modules'));
assert(!glob.match(p, 'node_super_modules'));
assert(!glob.match(p, 'node_module'));
assert(!glob.match(p, '/node_modules'));
assert(!glob.match(p, 'test/node_modules'));
p = '?';
assert(glob.match(p, 'h'));
assert(!glob.match(p, 'html.txt'));
assert(!glob.match(p, 'htm.txt'));
assert(!glob.match(p, 'folder/foo.js'));
assert(!glob.match(p, '/node_modules/foo.js'));
});
test('globstar', function () {
let p = '**/*.js';
assert(glob.match(p, 'foo.js'));
assert(glob.match(p, 'folder/foo.js'));
assert(glob.match(p, '/node_modules/foo.js'));
assert(!glob.match(p, 'foo.jss'));
assert(!glob.match(p, 'some.js/test'));
assert(!glob.match(p, '/some.js/test'));
assert(!glob.match(p, '\\some.js\\test'));
p = '**/project.json';
assert(glob.match(p, 'project.json'));
assert(glob.match(p, '/project.json'));
assert(glob.match(p, 'some/folder/project.json'));
assert(!glob.match(p, 'some/folder/file_project.json'));
assert(!glob.match(p, 'some/folder/fileproject.json'));
// assert(!glob.match(p, '/rrproject.json')); TODO@ben this still fails if T1-3 are disabled
assert(!glob.match(p, 'some/rrproject.json'));
// assert(!glob.match(p, 'rrproject.json'));
// assert(!glob.match(p, '\\rrproject.json'));
assert(!glob.match(p, 'some\\rrproject.json'));
p = 'test/**';
assert(glob.match(p, 'test'));
assert(glob.match(p, 'test/foo.js'));
assert(glob.match(p, 'test/other/foo.js'));
assert(!glob.match(p, 'est/other/foo.js'));
p = '**';
assert(glob.match(p, 'foo.js'));
assert(glob.match(p, 'folder/foo.js'));
assert(glob.match(p, '/node_modules/foo.js'));
assert(glob.match(p, 'foo.jss'));
assert(glob.match(p, 'some.js/test'));
p = 'test/**/*.js';
assert(glob.match(p, 'test/foo.js'));
assert(glob.match(p, 'test/other/foo.js'));
assert(glob.match(p, 'test/other/more/foo.js'));
assert(!glob.match(p, 'test/foo.ts'));
assert(!glob.match(p, 'test/other/foo.ts'));
assert(!glob.match(p, 'test/other/more/foo.ts'));
p = '**/**/*.js';
assert(glob.match(p, 'foo.js'));
assert(glob.match(p, 'folder/foo.js'));
assert(glob.match(p, '/node_modules/foo.js'));
assert(!glob.match(p, 'foo.jss'));
assert(!glob.match(p, 'some.js/test'));
p = '**/node_modules/**/*.js';
assert(!glob.match(p, 'foo.js'));
assert(!glob.match(p, 'folder/foo.js'));
assert(glob.match(p, 'node_modules/foo.js'));
assert(glob.match(p, 'node_modules/some/folder/foo.js'));
assert(!glob.match(p, 'node_modules/some/folder/foo.ts'));
assert(!glob.match(p, 'foo.jss'));
assert(!glob.match(p, 'some.js/test'));
p = '{**/node_modules/**,**/.git/**,**/bower_components/**}';
assert(glob.match(p, 'node_modules'));
assert(glob.match(p, '/node_modules'));
assert(glob.match(p, '/node_modules/more'));
assert(glob.match(p, 'some/test/node_modules'));
assert(glob.match(p, 'some\\test\\node_modules'));
assert(glob.match(p, 'C:\\\\some\\test\\node_modules'));
assert(glob.match(p, 'C:\\\\some\\test\\node_modules\\more'));
assert(glob.match(p, 'bower_components'));
assert(glob.match(p, 'bower_components/more'));
assert(glob.match(p, '/bower_components'));
assert(glob.match(p, 'some/test/bower_components'));
assert(glob.match(p, 'some\\test\\bower_components'));
assert(glob.match(p, 'C:\\\\some\\test\\bower_components'));
assert(glob.match(p, 'C:\\\\some\\test\\bower_components\\more'));
assert(glob.match(p, '.git'));
assert(glob.match(p, '/.git'));
assert(glob.match(p, 'some/test/.git'));
assert(glob.match(p, 'some\\test\\.git'));
assert(glob.match(p, 'C:\\\\some\\test\\.git'));
assert(!glob.match(p, 'tempting'));
assert(!glob.match(p, '/tempting'));
assert(!glob.match(p, 'some/test/tempting'));
assert(!glob.match(p, 'some\\test\\tempting'));
assert(!glob.match(p, 'C:\\\\some\\test\\tempting'));
p = '{**/package.json,**/project.json}';
assert(glob.match(p, 'package.json'));
assert(glob.match(p, '/package.json'));
assert(!glob.match(p, 'xpackage.json'));
assert(!glob.match(p, '/xpackage.json'));
});
test('brace expansion', function () {
let p = '*.{html,js}';
assert(glob.match(p, 'foo.js'));
assert(glob.match(p, 'foo.html'));
assert(!glob.match(p, 'folder/foo.js'));
assert(!glob.match(p, '/node_modules/foo.js'));
assert(!glob.match(p, 'foo.jss'));
assert(!glob.match(p, 'some.js/test'));
p = '*.{html}';
assert(glob.match(p, 'foo.html'));
assert(!glob.match(p, 'foo.js'));
assert(!glob.match(p, 'folder/foo.js'));
assert(!glob.match(p, '/node_modules/foo.js'));
assert(!glob.match(p, 'foo.jss'));
assert(!glob.match(p, 'some.js/test'));
p = '{node_modules,testing}';
assert(glob.match(p, 'node_modules'));
assert(glob.match(p, 'testing'));
assert(!glob.match(p, 'node_module'));
assert(!glob.match(p, 'dtesting'));
p = '**/{foo,bar}';
assert(glob.match(p, 'foo'));
assert(glob.match(p, 'bar'));
assert(glob.match(p, 'test/foo'));
assert(glob.match(p, 'test/bar'));
assert(glob.match(p, 'other/more/foo'));
assert(glob.match(p, 'other/more/bar'));
p = '{foo,bar}/**';
assert(glob.match(p, 'foo'));
assert(glob.match(p, 'bar'));
assert(glob.match(p, 'foo/test'));
assert(glob.match(p, 'bar/test'));
assert(glob.match(p, 'foo/other/more'));
assert(glob.match(p, 'bar/other/more'));
p = '{**/*.d.ts,**/*.js}';
assert(glob.match(p, 'foo.js'));
assert(glob.match(p, 'testing/foo.js'));
assert(glob.match(p, 'testing\\foo.js'));
assert(glob.match(p, '/testing/foo.js'));
assert(glob.match(p, '\\testing\\foo.js'));
assert(glob.match(p, 'C:\\testing\\foo.js'));
assert(glob.match(p, 'foo.d.ts'));
assert(glob.match(p, 'testing/foo.d.ts'));
assert(glob.match(p, 'testing\\foo.d.ts'));
assert(glob.match(p, '/testing/foo.d.ts'));
assert(glob.match(p, '\\testing\\foo.d.ts'));
assert(glob.match(p, 'C:\\testing\\foo.d.ts'));
assert(!glob.match(p, 'foo.d'));
assert(!glob.match(p, 'testing/foo.d'));
assert(!glob.match(p, 'testing\\foo.d'));
assert(!glob.match(p, '/testing/foo.d'));
assert(!glob.match(p, '\\testing\\foo.d'));
assert(!glob.match(p, 'C:\\testing\\foo.d'));
p = '{**/*.d.ts,**/*.js,path/simple.jgs}';
assert(glob.match(p, 'foo.js'));
assert(glob.match(p, 'testing/foo.js'));
assert(glob.match(p, 'testing\\foo.js'));
assert(glob.match(p, '/testing/foo.js'));
assert(glob.match(p, 'path/simple.jgs'));
assert(!glob.match(p, '/path/simple.jgs'));
assert(glob.match(p, '\\testing\\foo.js'));
assert(glob.match(p, 'C:\\testing\\foo.js'));
p = '{**/*.d.ts,**/*.js,foo.[0-9]}';
assert(glob.match(p, 'foo.5'));
assert(glob.match(p, 'foo.8'));
assert(!glob.match(p, 'bar.5'));
assert(!glob.match(p, 'foo.f'));
assert(glob.match(p, 'foo.js'));
p = 'prefix/{**/*.d.ts,**/*.js,foo.[0-9]}';
assert(glob.match(p, 'prefix/foo.5'));
assert(glob.match(p, 'prefix/foo.8'));
assert(!glob.match(p, 'prefix/bar.5'));
assert(!glob.match(p, 'prefix/foo.f'));
assert(glob.match(p, 'prefix/foo.js'));
});
test('expression support (single)', function () {
let siblings = ['test.html', 'test.txt', 'test.ts', 'test.js'];
// { "**/*.js": { "when": "$(basename).ts" } }
let expression: glob.IExpression = {
'**/*.js': {
when: '$(basename).ts'
}
};
assert.strictEqual('**/*.js', glob.match(expression, 'test.js', () => siblings));
assert.strictEqual(glob.match(expression, 'test.js', () => []), null);
assert.strictEqual(glob.match(expression, 'test.js', () => ['te.ts']), null);
assert.strictEqual(glob.match(expression, 'test.js'), null);
expression = {
'**/*.js': {
when: ''
}
};
assert.strictEqual(glob.match(expression, 'test.js', () => siblings), null);
expression = <any>{
'**/*.js': {
}
};
assert.strictEqual('**/*.js', glob.match(expression, 'test.js', () => siblings));
expression = {};
assert.strictEqual(glob.match(expression, 'test.js', () => siblings), null);
});
test('expression support (multiple)', function () {
let siblings = ['test.html', 'test.txt', 'test.ts', 'test.js'];
// { "**/*.js": { "when": "$(basename).ts" } }
let expression: glob.IExpression = {
'**/*.js': { when: '$(basename).ts' },
'**/*.as': true,
'**/*.foo': false,
'**/*.bananas': { bananas: true }
};
assert.strictEqual('**/*.js', glob.match(expression, 'test.js', () => siblings));
assert.strictEqual('**/*.as', glob.match(expression, 'test.as', () => siblings));
assert.strictEqual('**/*.bananas', glob.match(expression, 'test.bananas', () => siblings));
assert.strictEqual('**/*.bananas', glob.match(expression, 'test.bananas'));
assert.strictEqual(glob.match(expression, 'test.foo', () => siblings), null);
});
test('brackets', function () {
let p = 'foo.[0-9]';
assert(glob.match(p, 'foo.5'));
assert(glob.match(p, 'foo.8'));
assert(!glob.match(p, 'bar.5'));
assert(!glob.match(p, 'foo.f'));
p = 'foo.[^0-9]';
assert(!glob.match(p, 'foo.5'));
assert(!glob.match(p, 'foo.8'));
assert(!glob.match(p, 'bar.5'));
assert(glob.match(p, 'foo.f'));
});
test('full path', function () {
let p = 'testing/this/foo.txt';
assert(glob.match(p, nativeSep('testing/this/foo.txt')));
});
test('prefix agnostic', function () {
let p = '**/*.js';
assert(glob.match(p, 'foo.js'));
assert(glob.match(p, '/foo.js'));
assert(glob.match(p, '\\foo.js'));
assert(glob.match(p, 'testing/foo.js'));
assert(glob.match(p, 'testing\\foo.js'));
assert(glob.match(p, '/testing/foo.js'));
assert(glob.match(p, '\\testing\\foo.js'));
assert(glob.match(p, 'C:\\testing\\foo.js'));
assert(!glob.match(p, 'foo.ts'));
assert(!glob.match(p, 'testing/foo.ts'));
assert(!glob.match(p, 'testing\\foo.ts'));
assert(!glob.match(p, '/testing/foo.ts'));
assert(!glob.match(p, '\\testing\\foo.ts'));
assert(!glob.match(p, 'C:\\testing\\foo.ts'));
assert(!glob.match(p, 'foo.js.txt'));
assert(!glob.match(p, 'testing/foo.js.txt'));
assert(!glob.match(p, 'testing\\foo.js.txt'));
assert(!glob.match(p, '/testing/foo.js.txt'));
assert(!glob.match(p, '\\testing\\foo.js.txt'));
assert(!glob.match(p, 'C:\\testing\\foo.js.txt'));
assert(!glob.match(p, 'testing.js/foo'));
assert(!glob.match(p, 'testing.js\\foo'));
assert(!glob.match(p, '/testing.js/foo'));
assert(!glob.match(p, '\\testing.js\\foo'));
assert(!glob.match(p, 'C:\\testing.js\\foo'));
p = '**/foo.js';
assert(glob.match(p, 'foo.js'));
assert(glob.match(p, '/foo.js'));
assert(glob.match(p, '\\foo.js'));
assert(glob.match(p, 'testing/foo.js'));
assert(glob.match(p, 'testing\\foo.js'));
assert(glob.match(p, '/testing/foo.js'));
assert(glob.match(p, '\\testing\\foo.js'));
assert(glob.match(p, 'C:\\testing\\foo.js'));
});
test('cached properly', function () {
let p = '**/*.js';
assert(glob.match(p, 'foo.js'));
assert(glob.match(p, 'testing/foo.js'));
assert(glob.match(p, 'testing\\foo.js'));
assert(glob.match(p, '/testing/foo.js'));
assert(glob.match(p, '\\testing\\foo.js'));
assert(glob.match(p, 'C:\\testing\\foo.js'));
assert(!glob.match(p, 'foo.ts'));
assert(!glob.match(p, 'testing/foo.ts'));
assert(!glob.match(p, 'testing\\foo.ts'));
assert(!glob.match(p, '/testing/foo.ts'));
assert(!glob.match(p, '\\testing\\foo.ts'));
assert(!glob.match(p, 'C:\\testing\\foo.ts'));
assert(!glob.match(p, 'foo.js.txt'));
assert(!glob.match(p, 'testing/foo.js.txt'));
assert(!glob.match(p, 'testing\\foo.js.txt'));
assert(!glob.match(p, '/testing/foo.js.txt'));
assert(!glob.match(p, '\\testing\\foo.js.txt'));
assert(!glob.match(p, 'C:\\testing\\foo.js.txt'));
assert(!glob.match(p, 'testing.js/foo'));
assert(!glob.match(p, 'testing.js\\foo'));
assert(!glob.match(p, '/testing.js/foo'));
assert(!glob.match(p, '\\testing.js\\foo'));
assert(!glob.match(p, 'C:\\testing.js\\foo'));
// Run again and make sure the regex are properly reused
assert(glob.match(p, 'foo.js'));
assert(glob.match(p, 'testing/foo.js'));
assert(glob.match(p, 'testing\\foo.js'));
assert(glob.match(p, '/testing/foo.js'));
assert(glob.match(p, '\\testing\\foo.js'));
assert(glob.match(p, 'C:\\testing\\foo.js'));
assert(!glob.match(p, 'foo.ts'));
assert(!glob.match(p, 'testing/foo.ts'));
assert(!glob.match(p, 'testing\\foo.ts'));
assert(!glob.match(p, '/testing/foo.ts'));
assert(!glob.match(p, '\\testing\\foo.ts'));
assert(!glob.match(p, 'C:\\testing\\foo.ts'));
assert(!glob.match(p, 'foo.js.txt'));
assert(!glob.match(p, 'testing/foo.js.txt'));
assert(!glob.match(p, 'testing\\foo.js.txt'));
assert(!glob.match(p, '/testing/foo.js.txt'));
assert(!glob.match(p, '\\testing\\foo.js.txt'));
assert(!glob.match(p, 'C:\\testing\\foo.js.txt'));
assert(!glob.match(p, 'testing.js/foo'));
assert(!glob.match(p, 'testing.js\\foo'));
assert(!glob.match(p, '/testing.js/foo'));
assert(!glob.match(p, '\\testing.js\\foo'));
assert(!glob.match(p, 'C:\\testing.js\\foo'));
});
test('invalid glob', function () {
let p = '**/*(.js';
assert(!glob.match(p, 'foo.js'));
});
test('split glob aware', function () {
assert.deepEqual(glob.splitGlobAware('foo,bar', ','), ['foo', 'bar']);
assert.deepEqual(glob.splitGlobAware('foo', ','), ['foo']);
assert.deepEqual(glob.splitGlobAware('{foo,bar}', ','), ['{foo,bar}']);
assert.deepEqual(glob.splitGlobAware('foo,bar,{foo,bar}', ','), ['foo', 'bar', '{foo,bar}']);
assert.deepEqual(glob.splitGlobAware('{foo,bar},foo,bar,{foo,bar}', ','), ['{foo,bar}', 'foo', 'bar', '{foo,bar}']);
assert.deepEqual(glob.splitGlobAware('[foo,bar]', ','), ['[foo,bar]']);
assert.deepEqual(glob.splitGlobAware('foo,bar,[foo,bar]', ','), ['foo', 'bar', '[foo,bar]']);
assert.deepEqual(glob.splitGlobAware('[foo,bar],foo,bar,[foo,bar]', ','), ['[foo,bar]', 'foo', 'bar', '[foo,bar]']);
});
test('expression with disabled glob', function () {
let expr = { '**/*.js': false };
assert.strictEqual(glob.match(expr, 'foo.js'), null);
});
test('expression with two non-trivia globs', function () {
let expr = {
'**/*.j?': true,
'**/*.t?': true
};
assert.strictEqual(glob.match(expr, 'foo.js'), '**/*.j?');
assert.strictEqual(glob.match(expr, 'foo.as'), null);
});
test('expression with empty glob', function () {
let expr = { '': true };
assert.strictEqual(glob.match(expr, 'foo.js'), null);
});
test('expression with other falsy value', function () {
let expr = { '**/*.js': 0 };
assert.strictEqual(glob.match(expr, 'foo.js'), '**/*.js');
});
test('expression with two basename globs', function () {
let expr = {
'**/bar': true,
'**/baz': true
};
assert.strictEqual(glob.match(expr, 'bar'), '**/bar');
assert.strictEqual(glob.match(expr, 'foo'), null);
assert.strictEqual(glob.match(expr, 'foo/bar'), '**/bar');
assert.strictEqual(glob.match(expr, 'foo\\bar'), '**/bar');
assert.strictEqual(glob.match(expr, 'foo/foo'), null);
});
test('expression with two basename globs and a siblings expression', function () {
let expr = {
'**/bar': true,
'**/baz': true,
'**/*.js': { when: '$(basename).ts' }
};
let sibilings = () => ['foo.ts', 'foo.js', 'foo', 'bar'];
assert.strictEqual(glob.match(expr, 'bar', sibilings), '**/bar');
assert.strictEqual(glob.match(expr, 'foo', sibilings), null);
assert.strictEqual(glob.match(expr, 'foo/bar', sibilings), '**/bar');
assert.strictEqual(glob.match(expr, 'foo\\bar', sibilings), '**/bar');
assert.strictEqual(glob.match(expr, 'foo/foo', sibilings), null);
assert.strictEqual(glob.match(expr, 'foo.js', sibilings), '**/*.js');
assert.strictEqual(glob.match(expr, 'bar.js', sibilings), null);
});
test('expression with multipe basename globs', function () {
let expr = {
'**/bar': true,
'{**/baz,**/foo}': true
};
assert.strictEqual(glob.match(expr, 'bar'), '**/bar');
assert.strictEqual(glob.match(expr, 'foo'), '{**/baz,**/foo}');
assert.strictEqual(glob.match(expr, 'baz'), '{**/baz,**/foo}');
assert.strictEqual(glob.match(expr, 'abc'), null);
});
test('falsy expression/pattern', function () {
assert.strictEqual(glob.match(null, 'foo'), false);
assert.strictEqual(glob.match('', 'foo'), false);
assert.strictEqual(glob.parse(null)('foo'), false);
assert.strictEqual(glob.parse('')('foo'), false);
});
test('falsy path', function () {
assert.strictEqual(glob.parse('foo')(null), false);
assert.strictEqual(glob.parse('foo')(''), false);
assert.strictEqual(glob.parse('**/*.j?')(null), false);
assert.strictEqual(glob.parse('**/*.j?')(''), false);
assert.strictEqual(glob.parse('**/*.foo')(null), false);
assert.strictEqual(glob.parse('**/*.foo')(''), false);
assert.strictEqual(glob.parse('**/foo')(null), false);
assert.strictEqual(glob.parse('**/foo')(''), false);
assert.strictEqual(glob.parse('{**/baz,**/foo}')(null), false);
assert.strictEqual(glob.parse('{**/baz,**/foo}')(''), false);
assert.strictEqual(glob.parse('{**/*.baz,**/*.foo}')(null), false);
assert.strictEqual(glob.parse('{**/*.baz,**/*.foo}')(''), false);
});
test('expression/pattern basename', function () {
assert.strictEqual(glob.parse('**/foo')('bar/baz', 'baz'), false);
assert.strictEqual(glob.parse('**/foo')('bar/foo', 'foo'), true);
assert.strictEqual(glob.parse('{**/baz,**/foo}')('baz/bar', 'bar'), false);
assert.strictEqual(glob.parse('{**/baz,**/foo}')('baz/foo', 'foo'), true);
let expr = { '**/*.js': { when: '$(basename).ts' } };
let sibilings = () => ['foo.ts', 'foo.js'];
assert.strictEqual(glob.parse(expr)('bar/baz.js', 'baz.js', sibilings), null);
assert.strictEqual(glob.parse(expr)('bar/foo.js', 'foo.js', sibilings), '**/*.js');
});
test('expression/pattern basename terms', function () {
assert.deepStrictEqual(glob.getBasenameTerms(glob.parse('**/*.foo')), []);
assert.deepStrictEqual(glob.getBasenameTerms(glob.parse('**/foo')), ['foo']);
assert.deepStrictEqual(glob.getBasenameTerms(glob.parse('**/foo/')), ['foo']);
assert.deepStrictEqual(glob.getBasenameTerms(glob.parse('{**/baz,**/foo}')), ['baz', 'foo']);
assert.deepStrictEqual(glob.getBasenameTerms(glob.parse('{**/baz/,**/foo/}')), ['baz', 'foo']);
assert.deepStrictEqual(glob.getBasenameTerms(glob.parse({
'**/foo': true,
'{**/bar,**/baz}': true,
'{**/bar2/,**/baz2/}': true,
'**/bulb': false
})), ['foo', 'bar', 'baz', 'bar2', 'baz2']);
assert.deepStrictEqual(glob.getBasenameTerms(glob.parse({
'**/foo': { when: '$(basename).zip' },
'**/bar': true
})), ['bar']);
});
test('expression/pattern optimization for basenames', function () {
assert.deepStrictEqual(glob.getBasenameTerms(glob.parse('**/foo/**')), []);
assert.deepStrictEqual(glob.getBasenameTerms(glob.parse('**/foo/**', { trimForExclusions: true })), ['foo']);
testOptimizationForBasenames('**/*.foo/**', [], [['baz/bar.foo/bar/baz', true]]);
testOptimizationForBasenames('**/foo/**', ['foo'], [['bar/foo', true], ['bar/foo/baz', false]]);
testOptimizationForBasenames('{**/baz/**,**/foo/**}', ['baz', 'foo'], [['bar/baz', true], ['bar/foo', true]]);
testOptimizationForBasenames({
'**/foo/**': true,
'{**/bar/**,**/baz/**}': true,
'**/bulb/**': false
}, ['foo', 'bar', 'baz'], [
['bar/foo', '**/foo/**'],
['foo/bar', '{**/bar/**,**/baz/**}'],
['bar/nope', null]
]);
const siblingsFn = () => ['baz', 'baz.zip', 'nope'];
testOptimizationForBasenames({
'**/foo/**': { when: '$(basename).zip' },
'**/bar/**': true
}, ['bar'], [
['bar/foo', null],
['bar/foo/baz', null],
['bar/foo/nope', null],
['foo/bar', '**/bar/**'],
], [
null,
siblingsFn,
siblingsFn
]);
});
function testOptimizationForBasenames(pattern: string | glob.IExpression, basenameTerms: string[], matches: [string, string | boolean][], siblingsFns: (() => string[])[] = []) {
const parsed = glob.parse(<glob.IExpression>pattern, { trimForExclusions: true });
assert.deepStrictEqual(glob.getBasenameTerms(parsed), basenameTerms);
matches.forEach(([text, result], i) => {
assert.strictEqual(parsed(text, null, siblingsFns[i]), result);
});
}
test('trailing slash', function () {
// Testing existing (more or less intuitive) behavior
assert.strictEqual(glob.parse('**/foo/')('bar/baz', 'baz'), false);
assert.strictEqual(glob.parse('**/foo/')('bar/foo', 'foo'), true);
assert.strictEqual(glob.parse('**/*.foo/')('bar/file.baz', 'file.baz'), false);
assert.strictEqual(glob.parse('**/*.foo/')('bar/file.foo', 'file.foo'), true);
assert.strictEqual(glob.parse('{**/foo/,**/abc/}')('bar/baz', 'baz'), false);
assert.strictEqual(glob.parse('{**/foo/,**/abc/}')('bar/foo', 'foo'), true);
assert.strictEqual(glob.parse('{**/foo/,**/abc/}')('bar/abc', 'abc'), true);
assert.strictEqual(glob.parse('{**/foo/,**/abc/}', { trimForExclusions: true })('bar/baz', 'baz'), false);
assert.strictEqual(glob.parse('{**/foo/,**/abc/}', { trimForExclusions: true })('bar/foo', 'foo'), true);
assert.strictEqual(glob.parse('{**/foo/,**/abc/}', { trimForExclusions: true })('bar/abc', 'abc'), true);
});
test('expression/pattern path', function () {
assert.strictEqual(glob.parse('**/foo/bar')(nativeSep('foo/baz'), 'baz'), false);
assert.strictEqual(glob.parse('**/foo/bar')(nativeSep('foo/bar'), 'bar'), true);
assert.strictEqual(glob.parse('**/foo/bar')(nativeSep('bar/foo/bar'), 'bar'), true);
assert.strictEqual(glob.parse('**/foo/bar/**')(nativeSep('bar/foo/bar'), 'bar'), true);
assert.strictEqual(glob.parse('**/foo/bar/**')(nativeSep('bar/foo/bar/baz'), 'baz'), true);
assert.strictEqual(glob.parse('**/foo/bar/**', { trimForExclusions: true })(nativeSep('bar/foo/bar'), 'bar'), true);
assert.strictEqual(glob.parse('**/foo/bar/**', { trimForExclusions: true })(nativeSep('bar/foo/bar/baz'), 'baz'), false);
assert.strictEqual(glob.parse('foo/bar')(nativeSep('foo/baz'), 'baz'), false);
assert.strictEqual(glob.parse('foo/bar')(nativeSep('foo/bar'), 'bar'), true);
assert.strictEqual(glob.parse('foo/bar/baz')(nativeSep('foo/bar/baz'), 'baz'), true); // #15424
assert.strictEqual(glob.parse('foo/bar')(nativeSep('bar/foo/bar'), 'bar'), false);
assert.strictEqual(glob.parse('foo/bar/**')(nativeSep('foo/bar/baz'), 'baz'), true);
assert.strictEqual(glob.parse('foo/bar/**', { trimForExclusions: true })(nativeSep('foo/bar'), 'bar'), true);
assert.strictEqual(glob.parse('foo/bar/**', { trimForExclusions: true })(nativeSep('foo/bar/baz'), 'baz'), false);
});
test('expression/pattern paths', function () {
assert.deepStrictEqual(glob.getPathTerms(glob.parse('**/*.foo')), []);
assert.deepStrictEqual(glob.getPathTerms(glob.parse('**/foo')), []);
assert.deepStrictEqual(glob.getPathTerms(glob.parse('**/foo/bar')), ['*/foo/bar']);
assert.deepStrictEqual(glob.getPathTerms(glob.parse('**/foo/bar/')), ['*/foo/bar']);
// Not supported
// assert.deepStrictEqual(glob.getPathTerms(glob.parse('{**/baz/bar,**/foo/bar,**/bar}')), ['*/baz/bar', '*/foo/bar']);
// assert.deepStrictEqual(glob.getPathTerms(glob.parse('{**/baz/bar/,**/foo/bar/,**/bar/}')), ['*/baz/bar', '*/foo/bar']);
const parsed = glob.parse({
'**/foo/bar': true,
'**/foo2/bar2': true,
// Not supported
// '{**/bar/foo,**/baz/foo}': true,
// '{**/bar2/foo/,**/baz2/foo/}': true,
'**/bulb': true,
'**/bulb2': true,
'**/bulb/foo': false
});
assert.deepStrictEqual(glob.getPathTerms(parsed), ['*/foo/bar', '*/foo2/bar2']);
assert.deepStrictEqual(glob.getBasenameTerms(parsed), ['bulb', 'bulb2']);
assert.deepStrictEqual(glob.getPathTerms(glob.parse({
'**/foo/bar': { when: '$(basename).zip' },
'**/bar/foo': true,
'**/bar2/foo2': true
})), ['*/bar/foo', '*/bar2/foo2']);
});
test('expression/pattern optimization for paths', function () {
assert.deepStrictEqual(glob.getPathTerms(glob.parse('**/foo/bar/**')), []);
assert.deepStrictEqual(glob.getPathTerms(glob.parse('**/foo/bar/**', { trimForExclusions: true })), ['*/foo/bar']);
testOptimizationForPaths('**/*.foo/bar/**', [], [[nativeSep('baz/bar.foo/bar/baz'), true]]);
testOptimizationForPaths('**/foo/bar/**', ['*/foo/bar'], [[nativeSep('bar/foo/bar'), true], [nativeSep('bar/foo/bar/baz'), false]]);
// Not supported
// testOptimizationForPaths('{**/baz/bar/**,**/foo/bar/**}', ['*/baz/bar', '*/foo/bar'], [[nativeSep('bar/baz/bar'), true], [nativeSep('bar/foo/bar'), true]]);
testOptimizationForPaths({
'**/foo/bar/**': true,
// Not supported
// '{**/bar/bar/**,**/baz/bar/**}': true,
'**/bulb/bar/**': false
}, ['*/foo/bar'], [
[nativeSep('bar/foo/bar'), '**/foo/bar/**'],
// Not supported
// [nativeSep('foo/bar/bar'), '{**/bar/bar/**,**/baz/bar/**}'],
[nativeSep('/foo/bar/nope'), null]
]);
const siblingsFn = () => ['baz', 'baz.zip', 'nope'];
testOptimizationForPaths({
'**/foo/123/**': { when: '$(basename).zip' },
'**/bar/123/**': true
}, ['*/bar/123'], [
[nativeSep('bar/foo/123'), null],
[nativeSep('bar/foo/123/baz'), null],
[nativeSep('bar/foo/123/nope'), null],
[nativeSep('foo/bar/123'), '**/bar/123/**'],
], [
null,
siblingsFn,
siblingsFn
]);
});
function testOptimizationForPaths(pattern: string | glob.IExpression, pathTerms: string[], matches: [string, string | boolean][], siblingsFns: (() => string[])[] = []) {
const parsed = glob.parse(<glob.IExpression>pattern, { trimForExclusions: true });
assert.deepStrictEqual(glob.getPathTerms(parsed), pathTerms);
matches.forEach(([text, result], i) => {
assert.strictEqual(parsed(text, null, siblingsFns[i]), result);
});
}
function nativeSep(slashPath: string): string {
return slashPath.replace(/\//g, path.sep);
}
test('mergeExpressions', () => {
// Empty => empty
assert.deepEqual(glob.mergeExpressions(), glob.getEmptyExpression());
// Doesn't modify given expressions
const expr1 = { 'a': true };
glob.mergeExpressions(expr1, { 'b': true });
assert.deepEqual(expr1, { 'a': true });
// Merges correctly
assert.deepEqual(glob.mergeExpressions({ 'a': true }, { 'b': true }), { 'a': true, 'b': true });
// Ignores null/undefined portions
assert.deepEqual(glob.mergeExpressions(undefined, { 'a': true }, null, { 'b': true }), { 'a': true, 'b': true });
// Later expressions take precedence
assert.deepEqual(glob.mergeExpressions({ 'a': true, 'b': false, 'c': true }, { 'a': false, 'b': true }), { 'a': false, 'b': true, 'c': true });
});
});

View File

@@ -0,0 +1,23 @@
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Data.OleDb;
using System.Data.Odbc;
using System.IO;
using System.Net.Mail;
using System.Text.RegularExpressions;
using System.DirectoryServices;
using System.Diagnostics;
using System.Resources;
using System.Globalization;
using System.Reflection;
using System.Runtime.Serialization.Formatters.Binary;
using System.Runtime.Serialization;
ObjectCount = LoadObjects("Öffentlicher Ordner");
Private = "Persönliche Information"

View File

@@ -0,0 +1,35 @@
/*----------------------------------------------------------
The base color for this template is #5c87b2. If you'd like
to use a different color start by replacing all instances of
#5c87b2 with your new color.
----------------------------------------------------------*/
body
{
background-color: #5c87b2;
font-size: .75em;
font-family: Segoe UI, Verdana, Helvetica, Sans-Serif;
margin: 8px;
padding: 0;
color: #696969;
}
h1, h2, h3, h4, h5, h6
{
color: #000;
font-size: 40px;
margin: 0px;
}
textarea
{
font-family: Consolas
}
#results
{
margin-top: 2em;
margin-left: 2em;
color: black;
font-size: medium;
}

View File

@@ -0,0 +1,11 @@
{
"type": "typescript",
"sources": [
"examples/company.ts",
"examples/conway.ts",
"examples/employee.ts",
"examples/large.ts",
"examples/small.ts"
]
}

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 151 B

Binary file not shown.

View File

@@ -0,0 +1 @@
VSCODEは最高のエディタだ。

View File

@@ -0,0 +1,3 @@
<?xml>
</xml>

View File

@@ -0,0 +1,79 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
'use strict';
import assert = require('assert');
import mimeCommon = require('vs/base/common/mime');
import mime = require('vs/base/node/mime');
suite('Mime', () => {
test('detectMimesFromFile (JSON saved as PNG)', function (done: (err?: any) => void) {
const file = require.toUrl('./fixtures/some.json.png');
mime.detectMimesFromFile(file).then(mimes => {
assert.deepEqual(mimes.mimes, ['text/plain']);
done();
}, done);
});
test('detectMimesFromFile (PNG saved as TXT)', function (done: (err?: any) => void) {
mimeCommon.registerTextMime({ id: 'text', mime: 'text/plain', extension: '.txt' });
const file = require.toUrl('./fixtures/some.png.txt');
mime.detectMimesFromFile(file).then(mimes => {
assert.deepEqual(mimes.mimes, ['text/plain', 'application/octet-stream']);
done();
}, done);
});
test('detectMimesFromFile (XML saved as PNG)', function (done: (err?: any) => void) {
const file = require.toUrl('./fixtures/some.xml.png');
mime.detectMimesFromFile(file).then(mimes => {
assert.deepEqual(mimes.mimes, ['text/plain']);
done();
}, done);
});
test('detectMimesFromFile (QWOFF saved as TXT)', function (done: (err?: any) => void) {
const file = require.toUrl('./fixtures/some.qwoff.txt');
mime.detectMimesFromFile(file).then(mimes => {
assert.deepEqual(mimes.mimes, ['text/plain', 'application/octet-stream']);
done();
}, done);
});
test('detectMimesFromFile (CSS saved as QWOFF)', function (done: (err?: any) => void) {
const file = require.toUrl('./fixtures/some.css.qwoff');
mime.detectMimesFromFile(file).then(mimes => {
assert.deepEqual(mimes.mimes, ['text/plain']);
done();
}, done);
});
test('detectMimesFromFile (PDF)', function (done: () => void) {
const file = require.toUrl('./fixtures/some.pdf');
mime.detectMimesFromFile(file).then(mimes => {
assert.deepEqual(mimes.mimes, ['application/octet-stream']);
done();
}, done);
});
test('autoGuessEncoding (ShiftJIS)', function (done: () => void) {
const file = require.toUrl('./fixtures/some.shiftjis.txt');
mime.detectMimesFromFile(file, { autoGuessEncoding: true }).then(mimes => {
assert.equal(mimes.encoding, 'shiftjis');
done();
}, done);
});
test('autoGuessEncoding (CP1252)', function (done: () => void) {
const file = require.toUrl('./fixtures/some.cp1252.txt');
mime.detectMimesFromFile(file, { autoGuessEncoding: true }).then(mimes => {
assert.equal(mimes.encoding, 'windows1252');
done();
}, done);
});
});

View File

@@ -0,0 +1,147 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
'use strict';
import { TPromise } from 'vs/base/common/winjs.base';
import assert = require('assert');
import os = require('os');
import path = require('path');
import fs = require('fs');
import uuid = require('vs/base/common/uuid');
import extfs = require('vs/base/node/extfs');
import { onError } from 'vs/base/test/common/utils';
import * as pfs from 'vs/base/node/pfs';
suite('PFS', () => {
test('writeFile', function (done: () => void) {
const id = uuid.generateUuid();
const parentDir = path.join(os.tmpdir(), 'vsctests', id);
const newDir = path.join(parentDir, 'pfs', id);
const testFile = path.join(newDir, 'writefile.txt');
extfs.mkdirp(newDir, 493, (error) => {
if (error) {
return onError(error, done);
}
assert.ok(fs.existsSync(newDir));
pfs.writeFile(testFile, 'Hello World', null).done(() => {
assert.equal(fs.readFileSync(testFile), 'Hello World');
extfs.del(parentDir, os.tmpdir(), () => { }, done);
}, error => onError(error, done));
});
});
test('writeFile - parallel write on different files works', function (done: () => void) {
const id = uuid.generateUuid();
const parentDir = path.join(os.tmpdir(), 'vsctests', id);
const newDir = path.join(parentDir, 'pfs', id);
const testFile1 = path.join(newDir, 'writefile1.txt');
const testFile2 = path.join(newDir, 'writefile2.txt');
const testFile3 = path.join(newDir, 'writefile3.txt');
const testFile4 = path.join(newDir, 'writefile4.txt');
const testFile5 = path.join(newDir, 'writefile5.txt');
extfs.mkdirp(newDir, 493, (error) => {
if (error) {
return onError(error, done);
}
assert.ok(fs.existsSync(newDir));
TPromise.join([
pfs.writeFile(testFile1, 'Hello World 1', null),
pfs.writeFile(testFile2, 'Hello World 2', null),
pfs.writeFile(testFile3, 'Hello World 3', null),
pfs.writeFile(testFile4, 'Hello World 4', null),
pfs.writeFile(testFile5, 'Hello World 5', null)
]).done(() => {
assert.equal(fs.readFileSync(testFile1), 'Hello World 1');
assert.equal(fs.readFileSync(testFile2), 'Hello World 2');
assert.equal(fs.readFileSync(testFile3), 'Hello World 3');
assert.equal(fs.readFileSync(testFile4), 'Hello World 4');
assert.equal(fs.readFileSync(testFile5), 'Hello World 5');
extfs.del(parentDir, os.tmpdir(), () => { }, done);
}, error => onError(error, done));
});
});
test('writeFile - parallel write on same files works and is sequentalized', function (done: () => void) {
const id = uuid.generateUuid();
const parentDir = path.join(os.tmpdir(), 'vsctests', id);
const newDir = path.join(parentDir, 'pfs', id);
const testFile = path.join(newDir, 'writefile.txt');
extfs.mkdirp(newDir, 493, (error) => {
if (error) {
return onError(error, done);
}
assert.ok(fs.existsSync(newDir));
TPromise.join([
pfs.writeFile(testFile, 'Hello World 1', null),
pfs.writeFile(testFile, 'Hello World 2', null),
TPromise.timeout(10).then(() => pfs.writeFile(testFile, 'Hello World 3', null)),
pfs.writeFile(testFile, 'Hello World 4', null),
TPromise.timeout(10).then(() => pfs.writeFile(testFile, 'Hello World 5', null))
]).done(() => {
assert.equal(fs.readFileSync(testFile), 'Hello World 5');
extfs.del(parentDir, os.tmpdir(), () => { }, done);
}, error => onError(error, done));
});
});
test('rimraf - simple', function (done: () => void) {
const id = uuid.generateUuid();
const parentDir = path.join(os.tmpdir(), 'vsctests', id);
const newDir = path.join(parentDir, 'extfs', id);
extfs.mkdirp(newDir, 493, (error) => {
if (error) {
return onError(error, done);
}
fs.writeFileSync(path.join(newDir, 'somefile.txt'), 'Contents');
fs.writeFileSync(path.join(newDir, 'someOtherFile.txt'), 'Contents');
pfs.rimraf(newDir).then(() => {
assert.ok(!fs.existsSync(newDir));
done();
}, error => onError(error, done));
}); // 493 = 0755
});
test('rimraf - recursive folder structure', function (done: () => void) {
const id = uuid.generateUuid();
const parentDir = path.join(os.tmpdir(), 'vsctests', id);
const newDir = path.join(parentDir, 'extfs', id);
extfs.mkdirp(newDir, 493, (error) => {
if (error) {
return onError(error, done);
}
fs.writeFileSync(path.join(newDir, 'somefile.txt'), 'Contents');
fs.writeFileSync(path.join(newDir, 'someOtherFile.txt'), 'Contents');
fs.mkdirSync(path.join(newDir, 'somefolder'));
fs.writeFileSync(path.join(newDir, 'somefolder', 'somefile.txt'), 'Contents');
pfs.rimraf(newDir).then(() => {
assert.ok(!fs.existsSync(newDir));
done();
}, error => onError(error, done));
}); // 493 = 0755
});
});

View File

@@ -0,0 +1,38 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
'use strict';
import * as assert from 'assert';
import * as net from 'net';
import ports = require('vs/base/node/ports');
suite('Ports', () => {
test('Finds a free port (no timeout)', function (done: () => void) {
this.timeout(1000 * 10); // higher timeout for this test
if (process.env['VSCODE_PID']) {
return done(); // this test fails when run from within VS Code
}
// get an initial freeport >= 7000
ports.findFreePort(7000, 100, 300000, (initialPort) => {
assert.ok(initialPort >= 7000);
// create a server to block this port
const server = net.createServer();
server.listen(initialPort, null, null, () => {
// once listening, find another free port and assert that the port is different from the opened one
ports.findFreePort(7000, 50, 300000, (freePort) => {
assert.ok(freePort >= 7000 && freePort !== initialPort);
server.close();
done();
});
});
});
});
});

View File

@@ -0,0 +1,16 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
'use strict';
import processes = require('vs/base/node/processes');
const sender = processes.createQueuedSender(process);
process.on('message', msg => {
sender.send(msg);
});
sender.send('ready');

View File

@@ -0,0 +1,19 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
'use strict';
import processes = require('vs/base/node/processes');
const sender = processes.createQueuedSender(process);
process.on('message', msg => {
sender.send(msg);
sender.send(msg);
sender.send(msg);
sender.send('done');
});
sender.send('ready');

View File

@@ -0,0 +1,89 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
'use strict';
import * as assert from 'assert';
import * as cp from 'child_process';
import * as objects from 'vs/base/common/objects';
import * as platform from 'vs/base/common/platform';
import URI from 'vs/base/common/uri';
import processes = require('vs/base/node/processes');
function fork(id: string): cp.ChildProcess {
const opts: any = {
env: objects.mixin(objects.clone(process.env), {
AMD_ENTRYPOINT: id,
PIPE_LOGGING: 'true',
VERBOSE_LOGGING: true
})
};
return cp.fork(URI.parse(require.toUrl('bootstrap')).fsPath, ['--type=processTests'], opts);
}
suite('Processes', () => {
test('buffered sending - simple data', function (done: () => void) {
if (process.env['VSCODE_PID']) {
return done(); // this test fails when run from within VS Code
}
const child = fork('vs/base/test/node/processes/fixtures/fork');
const sender = processes.createQueuedSender(child);
let counter = 0;
const msg1 = 'Hello One';
const msg2 = 'Hello Two';
const msg3 = 'Hello Three';
child.on('message', msgFromChild => {
if (msgFromChild === 'ready') {
sender.send(msg1);
sender.send(msg2);
sender.send(msg3);
} else {
counter++;
if (counter === 1) {
assert.equal(msgFromChild, msg1);
} else if (counter === 2) {
assert.equal(msgFromChild, msg2);
} else if (counter === 3) {
assert.equal(msgFromChild, msg3);
child.kill();
done();
}
}
});
});
test('buffered sending - lots of data (potential deadlock on win32)', function (done: () => void) {
if (!platform.isWindows || process.env['VSCODE_PID']) {
return done(); // test is only relevant for Windows and seems to crash randomly on some Linux builds
}
const child = fork('vs/base/test/node/processes/fixtures/fork_large');
const sender = processes.createQueuedSender(child);
const largeObj = Object.create(null);
for (let i = 0; i < 10000; i++) {
largeObj[i] = 'some data';
}
const msg = JSON.stringify(largeObj);
child.on('message', msgFromChild => {
if (msgFromChild === 'ready') {
sender.send(msg);
sender.send(msg);
sender.send(msg);
} else if (msgFromChild === 'done') {
child.kill();
done();
}
});
});
});

View File

@@ -0,0 +1,40 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
/*----------------------------------------------------------
The base color for this template is #5c87b2. If you'd like
to use a different color start by replacing all instances of
#5c87b2 with your new color.
----------------------------------------------------------*/
body
{
background-color: #5c87b2;
font-size: .75em;
font-family: Segoe UI, Verdana, Helvetica, Sans-Serif;
margin: 8px;
padding: 0;
color: #696969;
}
h1, h2, h3, h4, h5, h6
{
color: #000;
font-size: 40px;
margin: 0px;
}
textarea
{
font-family: Consolas
}
#results
{
margin-top: 2em;
margin-left: 2em;
color: black;
font-size: medium;
}

View File

@@ -0,0 +1,71 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
'use strict';
import assert = require('assert');
import fs = require('fs');
import stream = require('vs/base/node/stream');
suite('Stream', () => {
test('readExactlyByFile - ANSI', function (done: (err?) => void) {
const file = require.toUrl('./fixtures/file.css');
stream.readExactlyByFile(file, 10).then(({ buffer, bytesRead }) => {
assert.equal(bytesRead, 10);
assert.equal(buffer.toString(), '/*--------');
done();
}, done);
});
test('readExactlyByFile - empty', function (done: (err?: any) => void) {
const file = require.toUrl('./fixtures/empty.txt');
stream.readExactlyByFile(file, 10).then(({ bytesRead }) => {
assert.equal(bytesRead, 0);
done();
}, done);
});
test('readExactlyByStream - ANSI', function (done: (err?: any) => void) {
const file = require.toUrl('./fixtures/file.css');
stream.readExactlyByStream(fs.createReadStream(file), 10).then(({ buffer, bytesRead }) => {
assert.equal(bytesRead, 10);
assert.equal(buffer.toString(), '/*--------');
done();
}, done);
});
test('readExactlyByStream - empty', function (done: (err?: any) => void) {
const file = require.toUrl('./fixtures/empty.txt');
stream.readExactlyByStream(fs.createReadStream(file), 10).then(({ bytesRead }) => {
assert.equal(bytesRead, 0);
done();
}, done);
});
test('readToMatchingString - ANSI', function (done: (err?: any) => void) {
const file = require.toUrl('./fixtures/file.css');
stream.readToMatchingString(file, '\n', 10, 100).then((result: string) => {
// \r may be present on Windows
assert.equal(result.replace('\r', ''), '/*---------------------------------------------------------------------------------------------');
done();
}, done);
});
test('readToMatchingString - empty', function (done: (err?: any) => void) {
const file = require.toUrl('./fixtures/empty.txt');
stream.readToMatchingString(file, '\n', 10, 100).then((result: string) => {
assert.equal(result, null);
done();
}, done);
});
});

Binary file not shown.

View File

@@ -0,0 +1,29 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
'use strict';
import * as assert from 'assert';
import * as path from 'path';
import * as os from 'os';
import URI from 'vs/base/common/uri';
import { extract } from 'vs/base/node/zip';
import { generateUuid } from 'vs/base/common/uuid';
import { rimraf, exists } from 'vs/base/node/pfs';
const fixtures = URI.parse(require.toUrl('./fixtures')).fsPath;
suite('Zip', () => {
test('extract should handle directories', () => {
const fixture = path.join(fixtures, 'extract.zip');
const target = path.join(os.tmpdir(), generateUuid());
return extract(fixture, target)
.then(() => exists(path.join(target, 'extension')))
.then(exists => assert(exists))
.then(() => rimraf(target));
});
});