Skip to content

Commit

Permalink
1. added 'test' directory to tslint.
Browse files Browse the repository at this point in the history
2. fixed tslint issues there and removed evil semicolons.
3. removed the watch mode for grunt-ts it seems much slower
   then running tsc directly with the -w flag.
   the grunt-ts will be used for CI/releases
   and the watch.bat file will be used during development workflow.
   (until a better option is avaliable).

Change-Id: I147c581bfc8c7b5cad75cefd30d02289f3faf71a
  • Loading branch information
bd82 committed Mar 2, 2015
1 parent b432aa8 commit 48bfba9
Show file tree
Hide file tree
Showing 7 changed files with 494 additions and 490 deletions.
4 changes: 1 addition & 3 deletions gruntfile.js
Expand Up @@ -26,15 +26,13 @@ module.exports = function(grunt) {
configuration: grunt.file.readJSON("tslint.json")
},
files: {
src: ['src/**/*.ts', 'examples/**/*.ts']
src: ['src/**/*.ts', 'examples/**/*.ts', 'test/**/*.ts']
}
},

ts: {
default: {
src: ["**/*.ts", "!node_modules/**/*.ts", "!build/**/*.ts"],
watch: "src", // TODO: the grunt-ts plugin only supports watching a single directory,
// this means the code needs to be moved to a single directory...
outDir: "gen"
},
options: {
Expand Down
420 changes: 210 additions & 210 deletions test/parse/GAstBuilderSpec.ts

Large diffs are not rendered by default.

364 changes: 185 additions & 179 deletions test/parse/grammar/ContentAssistSpec.ts

Large diffs are not rendered by default.

74 changes: 37 additions & 37 deletions test/parse/grammar/FirstSpec.ts
Expand Up @@ -5,40 +5,40 @@

module chevrotain.parse.grammar.first.spec {

import t = test.parser.grammar.samples;
import gast = chevrotain.parse.grammar.gast;
import matchers = test.matchers;
import t = test.parser.grammar.samples
import gast = chevrotain.parse.grammar.gast
import matchers = test.matchers

describe("The Grammar Ast first model", function () {
"use strict";
"use strict"

it("can compute the first for a terminal", function () {
var terminal = new gast.Terminal(t.EntityTok);
var actual = first(terminal);
expect(actual.length).toBe(1);
expect(actual[0]).toBe(t.EntityTok);
var terminal = new gast.Terminal(t.EntityTok)
var actual = first(terminal)
expect(actual.length).toBe(1)
expect(actual[0]).toBe(t.EntityTok)

var terminal2 = new gast.Terminal(t.CommaTok);
var actual2 = first(terminal2);
expect(actual2.length).toBe(1);
expect(actual2[0]).toBe(t.CommaTok);
});
var terminal2 = new gast.Terminal(t.CommaTok)
var actual2 = first(terminal2)
expect(actual2.length).toBe(1)
expect(actual2[0]).toBe(t.CommaTok)
})

it("can compute the first for a Sequence production ", function () {
var seqProduction = new gast.FLAT([new gast.Terminal(t.EntityTok)]);
var actual = first(seqProduction);
expect(actual.length).toBe(1);
expect(actual[0]).toBe(t.EntityTok);
var seqProduction = new gast.FLAT([new gast.Terminal(t.EntityTok)])
var actual = first(seqProduction)
expect(actual.length).toBe(1)
expect(actual[0]).toBe(t.EntityTok)

var seqProduction2 = new gast.FLAT(
[
new gast.Terminal(t.EntityTok),
new gast.OPTION([new gast.Terminal(t.NamespaceTok)])
]);
var actual2 = first(seqProduction2);
expect(actual2.length).toBe(1);
expect(actual2[0]).toBe(t.EntityTok);
});
])
var actual2 = first(seqProduction2)
expect(actual2.length).toBe(1)
expect(actual2[0]).toBe(t.EntityTok)
})

it("can compute the first for an alternatives production ", function () {
var altProduction = new gast.OR(
Expand All @@ -47,23 +47,23 @@ module chevrotain.parse.grammar.first.spec {
new gast.Terminal(t.NamespaceTok),
new gast.Terminal(t.TypeTok)

]);
var actual = first(altProduction);
expect(actual.length).toBe(3);
expect(actual[0]).toBe(t.EntityTok);
expect(actual[1]).toBe(t.NamespaceTok);
expect(actual[2]).toBe(t.TypeTok);
])
var actual = first(altProduction)
expect(actual.length).toBe(3)
expect(actual[0]).toBe(t.EntityTok)
expect(actual[1]).toBe(t.NamespaceTok)
expect(actual[2]).toBe(t.TypeTok)

});
})

it("can compute the first for an production with optional prefix", function () {
var withOptionalPrefix = new gast.FLAT(
[
new gast.OPTION([new gast.Terminal(t.NamespaceTok)]),
new gast.Terminal(t.EntityTok)
]);
var actual = first(withOptionalPrefix);
matchers.arrayEqualityNoOrder(actual, [t.NamespaceTok, t.EntityTok]);
])
var actual = first(withOptionalPrefix)
matchers.arrayEqualityNoOrder(actual, [t.NamespaceTok, t.EntityTok])


var withTwoOptPrefix = new gast.FLAT(
Expand All @@ -72,11 +72,11 @@ module chevrotain.parse.grammar.first.spec {
new gast.OPTION([new gast.Terminal(t.ColonTok)]),
new gast.Terminal(t.EntityTok),
new gast.OPTION([new gast.Terminal(t.ConstTok)])
]);
var actual2 = first(withTwoOptPrefix);
matchers.arrayEqualityNoOrder(actual2, [t.NamespaceTok, t.ColonTok, t.EntityTok]);
});
])
var actual2 = first(withTwoOptPrefix)
matchers.arrayEqualityNoOrder(actual2, [t.NamespaceTok, t.ColonTok, t.EntityTok])
})

});
})

}
64 changes: 32 additions & 32 deletions test/parse/grammar/FollowSpec.ts
Expand Up @@ -9,51 +9,51 @@

module chevrotain.parse.grammar.follow.spec {

import t = test.parser.grammar.samples;
import gast = chevrotain.parse.grammar.gast;
import samples = test.parser.grammar.samples;
import matchers = test.matchers;
import t = test.parser.grammar.samples
import gast = chevrotain.parse.grammar.gast
import samples = test.parser.grammar.samples
import matchers = test.matchers

describe("The Grammar Ast Follows model", function () {
"use strict";
"use strict"

it("can build a followNamePrefix from a Terminal", function () {
var terminal = new gast.Terminal(t.IdentTok);
var actual = buildInProdFollowPrefix(terminal);
expect(actual).toBe("Ident1_IN_");
var terminal = new gast.Terminal(t.IdentTok)
var actual = buildInProdFollowPrefix(terminal)
expect(actual).toBe("Ident1_IN_")

var terminal2 = new gast.Terminal(t.EntityTok);
terminal2.occurrenceInParent = 3;
var actual2 = buildInProdFollowPrefix(terminal2);
expect(actual2).toBe("Entity3_IN_");
});
var terminal2 = new gast.Terminal(t.EntityTok)
terminal2.occurrenceInParent = 3
var actual2 = buildInProdFollowPrefix(terminal2)
expect(actual2).toBe("Entity3_IN_")
})

it("can build a followName prefix from a TopLevel Production and index", function () {
var prod = new gast.TOP_LEVEL("bamba", []);
var index = 5;
var prod = new gast.TOP_LEVEL("bamba", [])
var index = 5

var actual = buildBetweenProdsFollowPrefix(prod, index);
expect(actual).toBe("bamba5_IN_");
});
var actual = buildBetweenProdsFollowPrefix(prod, index)
expect(actual).toBe("bamba5_IN_")
})

it("can compute the follows for Top level production ref in ActionDec", function () {
var actual:any = new ResyncFollowsWalker(samples.actionDec).startWalking();
var actualPairs = actual.entries();
expect(actualPairs.length).toBe(3);
expect(actual.get('ParamSpec1_IN_actionDec').length).toBe(2);
matchers.arrayEqualityNoOrder(actual.get('ParamSpec1_IN_actionDec'), [t.CommaTok, t.RParenTok]);
expect(actual.get('ParamSpec2_IN_actionDec').length).toBe(2);
matchers.arrayEqualityNoOrder(actual.get('ParamSpec1_IN_actionDec'), [t.CommaTok, t.RParenTok]);
expect(actual.get('qualifiedName1_IN_actionDec').length).toBe(1);
matchers.arrayEqualityNoOrder(actual.get('qualifiedName1_IN_actionDec'), [t.SemicolonTok]);
});
var actual:any = new ResyncFollowsWalker(samples.actionDec).startWalking()
var actualPairs = actual.entries()
expect(actualPairs.length).toBe(3)
expect(actual.get("ParamSpec1_IN_actionDec").length).toBe(2)
matchers.arrayEqualityNoOrder(actual.get("ParamSpec1_IN_actionDec"), [t.CommaTok, t.RParenTok])
expect(actual.get("ParamSpec2_IN_actionDec").length).toBe(2)
matchers.arrayEqualityNoOrder(actual.get("ParamSpec1_IN_actionDec"), [t.CommaTok, t.RParenTok])
expect(actual.get("qualifiedName1_IN_actionDec").length).toBe(1)
matchers.arrayEqualityNoOrder(actual.get("qualifiedName1_IN_actionDec"), [t.SemicolonTok])
})

it("can compute all follows for a set of top level productions", function () {
var actual = computeAllProdsFollows([samples.actionDec]);
expect(actual.entries().length).toBe(3);
});
var actual = computeAllProdsFollows([samples.actionDec])
expect(actual.entries().length).toBe(3)
})


});
})

}
38 changes: 19 additions & 19 deletions test/parse/grammar/Samples.ts
Expand Up @@ -3,8 +3,8 @@

module test.parser.grammar.samples {

import t = chevrotain.scan.tokens;
import gast = chevrotain.parse.grammar.gast;
import t = chevrotain.scan.tokens
import gast = chevrotain.parse.grammar.gast

export class IdentTok extends t.Token {}
export class DotTok extends t.Token {}
Expand All @@ -28,44 +28,44 @@ module test.parser.grammar.samples {
export class KeyTok extends t.Token {}
export class ElementTok extends t.Token {}

export var qualifiedName = new gast.TOP_LEVEL('qualifiedName', [
export var qualifiedName = new gast.TOP_LEVEL("qualifiedName", [
new gast.Terminal(IdentTok),
new gast.MANY([
new gast.Terminal(DotTok),
new gast.Terminal(IdentTok, 2)
])
]);
])

export var ParamSpec = new gast.TOP_LEVEL('ParamSpec', [
export var ParamSpec = new gast.TOP_LEVEL("ParamSpec", [
new gast.Terminal(IdentTok),
new gast.Terminal(ColonTok),
new gast.ProdRef('qualifiedName', qualifiedName),
new gast.ProdRef("qualifiedName", qualifiedName),
new gast.OPTION([
new gast.Terminal(LSquareTok),
new gast.Terminal(RSquareTok)
])
]);
])

export var actionDec = new gast.TOP_LEVEL('actionDec', [
export var actionDec = new gast.TOP_LEVEL("actionDec", [
new gast.Terminal(ActionTok),
new gast.Terminal(IdentTok),
new gast.Terminal(LParenTok),
new gast.OPTION([
new gast.ProdRef('ParamSpec', ParamSpec),
new gast.ProdRef("ParamSpec", ParamSpec),
new gast.MANY([
new gast.Terminal(CommaTok),
new gast.ProdRef('ParamSpec', ParamSpec, 2)
new gast.ProdRef("ParamSpec", ParamSpec, 2)
])
]),
new gast.Terminal(RParenTok),
new gast.OPTION([
new gast.Terminal(ColonTok),
new gast.ProdRef('qualifiedName', qualifiedName)
new gast.ProdRef("qualifiedName", qualifiedName)
]),
new gast.Terminal(SemicolonTok)
]);
])

export var cardinality = new gast.TOP_LEVEL('cardinality', [
export var cardinality = new gast.TOP_LEVEL("cardinality", [
new gast.Terminal(LSquareTok),
new gast.Terminal(UnsignedIntegerLiteralTok),
new gast.Terminal(DotDotTok),
Expand All @@ -74,21 +74,21 @@ module test.parser.grammar.samples {
new gast.Terminal(AsteriskTok)
]),
new gast.Terminal(RSquareTok)
]);
])

export var assignedTypeSpec = new gast.TOP_LEVEL('assignedTypeSpec', [
export var assignedTypeSpec = new gast.TOP_LEVEL("assignedTypeSpec", [
new gast.Terminal(ColonTok),
new gast.ProdRef('assignedType', null),
new gast.ProdRef("assignedType", null),

new gast.OPTION([
new gast.ProdRef('enumClause', null)
new gast.ProdRef("enumClause", null)
]),

new gast.OPTION([
new gast.Terminal(DefaultTok),
new gast.ProdRef('expression', null)
new gast.ProdRef("expression", null)
])
]);
])


}
20 changes: 10 additions & 10 deletions test/utils/Matchers.ts
Expand Up @@ -4,30 +4,30 @@
module test.matchers {

export function containsAll<T>(actual:T[], expected:T[]):boolean {
var containsAll = true;
var containsAll = true
_.forEach(expected, function (elem) {
// test code, it does not need to be efficent :)
var containsCurrElem = _.intersection(actual, [elem]).length === 1;
containsAll = containsAll && containsCurrElem;
var containsCurrElem = _.intersection(actual, [elem]).length === 1
containsAll = containsAll && containsCurrElem
}, this
);
return containsAll;
)
return containsAll
}

// won't always work for arrays with duplicates...
export function arrayEqualityNoOrder<T>(actual:T[], expected:T[]):void {
expect(actual.length).toBe(expected.length);
expect(actual.length).toBe(expected.length)

var intersection = _.intersection(actual, expected);
expect(intersection.length === actual.length).toBeTruthy();
var intersection = _.intersection(actual, expected)
expect(intersection.length === actual.length).toBeTruthy()
}

// Will not work for arrays with internal arrays/objects.
export function scalarArrayEquality<T>(actual:T[], expected:T[]):void {
expect(actual.length).toBe(expected.length);
expect(actual.length).toBe(expected.length)

for (var idx = 0; idx < actual.length; idx++) {
expect(actual[idx]).toEqual(expected[idx]);
expect(actual[idx]).toEqual(expected[idx])
}
}
}
Expand Down

0 comments on commit 48bfba9

Please sign in to comment.