aboutsummaryrefslogtreecommitdiffstats
path: root/packages/tslint-config/test
diff options
context:
space:
mode:
authorHsuan Lee <boczeratul@gmail.com>2019-03-06 17:46:50 +0800
committerHsuan Lee <boczeratul@gmail.com>2019-03-06 17:46:50 +0800
commit35703539d0f2b4ddb3b11d0de8c9634af59ab71f (patch)
treeae3731221dbbb3a6fa40060a8d916cfd3f738289 /packages/tslint-config/test
parent92a1fde5b1ecd81b07cdb5bf0c9c1cd3544799db (diff)
downloaddexon-0x-contracts-stable.tar
dexon-0x-contracts-stable.tar.gz
dexon-0x-contracts-stable.tar.bz2
dexon-0x-contracts-stable.tar.lz
dexon-0x-contracts-stable.tar.xz
dexon-0x-contracts-stable.tar.zst
dexon-0x-contracts-stable.zip
Deploy @dexon-foundation/0x.jsstable
Diffstat (limited to 'packages/tslint-config/test')
-rw-r--r--packages/tslint-config/test/enumNamingSpec.spec.ts88
-rw-r--r--packages/tslint-config/test/lintrunner.ts23
2 files changed, 0 insertions, 111 deletions
diff --git a/packages/tslint-config/test/enumNamingSpec.spec.ts b/packages/tslint-config/test/enumNamingSpec.spec.ts
deleted file mode 100644
index d5b864eba..000000000
--- a/packages/tslint-config/test/enumNamingSpec.spec.ts
+++ /dev/null
@@ -1,88 +0,0 @@
-import * as assert from 'assert';
-
-import { Rule } from '../rules/enumNamingRule';
-
-import { getFixedResult, helper } from './lintrunner';
-const rule = 'enum-naming';
-
-describe('enumNamingRule', () => {
- it(`should not fail PascalCase`, () => {
- const src = `enum test { MemberOne, MemberTwo }`;
- const result = helper(src, rule);
- assert.equal(result.errorCount, 0);
- });
- it(`should not fail PascalCase keys with uncased values`, () => {
- const src = `enum test { MemberOne = 'member_one', MemberTwo = 'member two' }`;
- const result = helper(src, rule);
- assert.equal(result.errorCount, 0);
- });
- it(`should not fail PascalCase keys with numbers`, () => {
- const src = `enum test { Member1 = 'member_one', MemberTwo = 'member two' }`;
- const result = helper(src, rule);
- assert.equal(result.errorCount, 0);
- });
- it(`should fail with camelCase`, () => {
- const src = `enum test { memberOne, memberTwo }`;
- const result = helper(src, rule);
- assert.equal(result.errorCount, 2);
- });
- it(`should fail with snake case`, () => {
- const src = `enum test { member_one, member_two }`;
- const result = helper(src, rule);
- assert.equal(result.errorCount, 2);
- });
- it(`should fail with all caps`, () => {
- const src = `enum test { MEMBERONE, MEMBER_TWO }`;
- const result = helper(src, rule);
- assert.equal(result.errorCount, 2);
- });
- it(`should fail with mixed case`, () => {
- const src = `enum test { member_one, MemberTwo }`;
- const result = helper(src, rule);
- assert.equal(result.errorCount, 1);
- });
-
- it(`should fail with the right position`, () => {
- const src = `enum test { MemberOne, member_two }`;
- const startPosition = src.indexOf('member_two');
- const endPosition = startPosition + 'member_two'.length;
- const failure = helper(src, rule).failures[0];
-
- assert.equal(failure.getStartPosition().getPosition(), startPosition);
- assert.equal(failure.getEndPosition().getPosition(), endPosition);
- assert.equal(failure.getFailure(), Rule.FAILURE_STRING);
- });
-
- it(`should fail with the right message`, () => {
- const src = `enum test { memberOne, memberTwo }`;
- const failure = helper(src, rule).failures[0];
-
- assert.equal(failure.getFailure(), Rule.FAILURE_STRING);
- });
-});
-describe('enumNaming fixer', () => {
- it('should fix keys', () => {
- const src = `enum test { MemberOne, memberTwo, member_three, MEMBER_FOUR, MEMBERFIVE }`;
- const expected = `enum test { MemberOne, MemberTwo, MemberThree, MemberFour, Memberfive }`;
- const actual = getFixedResult(src, rule);
- const result = helper(src, rule);
- assert.equal(result.errorCount, 4); // tslint:disable-line:custom-no-magic-numbers
- assert.equal(actual, expected);
- });
- it('should not fix values', () => {
- const src = `enum test { MemberOne = 'MemberOne', memberTwo = 'memberTwo', member_three = 'member_three', MEMBER_FOUR = 'MEMBER_FOUR' }`;
- const expected = `enum test { MemberOne = 'MemberOne', MemberTwo = 'memberTwo', MemberThree = 'member_three', MemberFour = 'MEMBER_FOUR' }`;
- const actual = getFixedResult(src, rule);
- const result = helper(src, rule);
- assert.equal(result.errorCount, 3); // tslint:disable-line:custom-no-magic-numbers
- assert.equal(actual, expected);
- });
- it('should preserve values with equals sign', () => {
- const src = `enum Operators { assign = '=', EQUALS = '==', Triple_Equals = '===' }`;
- const expected = `enum Operators { Assign = '=', Equals = '==', TripleEquals = '===' }`;
- const actual = getFixedResult(src, rule);
- const result = helper(src, rule);
- assert.equal(result.errorCount, 3); // tslint:disable-line:custom-no-magic-numbers
- assert.equal(actual, expected);
- });
-});
diff --git a/packages/tslint-config/test/lintrunner.ts b/packages/tslint-config/test/lintrunner.ts
deleted file mode 100644
index fcd1b6844..000000000
--- a/packages/tslint-config/test/lintrunner.ts
+++ /dev/null
@@ -1,23 +0,0 @@
-import * as path from 'path';
-import { Configuration, Linter, Replacement } from 'tslint';
-
-export const helper = (src: string, rule: string) => {
- const linter = new Linter({ fix: false });
- linter.lint(
- '',
- src,
- Configuration.parseConfigFile({
- rules: {
- [rule]: true,
- },
- rulesDirectory: path.join(__dirname, '../rules'),
- }),
- );
- return linter.getResult();
-};
-
-export const getFixedResult = (src: string, rule: string) => {
- const result = helper(src, rule);
- const fixes = [].concat.apply(result.failures.map(x => x.getFix()));
- return Replacement.applyFixes(src, fixes);
-};