@code-to-json/utils
Advanced tools
Comparing version 1.0.0-rc.24 to 1.0.0-rc.25
@@ -6,2 +6,10 @@ # Change Log | ||
# [1.0.0-rc.25](https://github.com/mike-north/code-to-json/compare/@code-to-json/utils@1.0.0-rc.24...@code-to-json/utils@1.0.0-rc.25) (2019-02-24) | ||
**Note:** Version bump only for package @code-to-json/utils | ||
# [1.0.0-rc.24](https://github.com/mike-north/code-to-json/compare/@code-to-json/utils@1.0.0-rc.23...@code-to-json/utils@1.0.0-rc.24) (2019-02-24) | ||
@@ -8,0 +16,0 @@ |
{ | ||
"name": "@code-to-json/utils", | ||
"version": "1.0.0-rc.24", | ||
"version": "1.0.0-rc.25", | ||
"description": "Low-level utilities for code-to-json", | ||
@@ -37,3 +37,2 @@ "main": "lib/src/index.js", | ||
"mocha": "5.2.0", | ||
"mocha-typescript": "1.1.17", | ||
"nyc": "13.3.0", | ||
@@ -93,3 +92,3 @@ "remark-cli": "6.0.1", | ||
}, | ||
"gitHead": "ebdbfb5a3f12e3663e10fe1742bcd4022a744aec" | ||
"gitHead": "30b564c2f66d95ee2cd1b98fac53fe825e511ba7" | ||
} |
import { expect } from 'chai'; | ||
import { suite, test } from 'mocha-typescript'; | ||
import { describe, it } from 'mocha'; | ||
import { all, isArray, isHomogenousArray, some } from '../src/array'; | ||
@suite | ||
export class ArrayUtilsTests { | ||
@test | ||
public 'isArray tests'(): void { | ||
describe('Array utilities tests', () => { | ||
it('isArray tests', () => { | ||
expect(isArray(0 as any)).to.eql(false, 'number'); | ||
@@ -18,6 +16,5 @@ expect(isArray(null as any)).to.eql(false, 'null'); | ||
expect(isArray(new class B {}() as any)).to.eql(false, 'instance'); | ||
} | ||
}); | ||
@test | ||
public 'isHomogenousArray tests'(): void { | ||
it('isHomogenousArray tests', () => { | ||
expect(isHomogenousArray([1, '2'], v => typeof v === 'string')).to.eql(false, 'mixed contents'); | ||
@@ -30,13 +27,11 @@ expect(isHomogenousArray([1, 2, 3], v => typeof v === 'number')).to.eql( | ||
expect(isHomogenousArray([[1], ['2']], isArray)).to.eql(true, 'nested array case'); | ||
} | ||
}); | ||
@test | ||
public 'some tests'(): void { | ||
it('some tests', () => { | ||
expect(some([1, '2'], v => typeof v === 'string')).to.deep.eq(true); | ||
expect(some([1, '2'], v => typeof v === 'function')).to.deep.eq(false); | ||
expect(some([1, 2], v => typeof v === 'number')).to.deep.eq(true); | ||
} | ||
}); | ||
@test | ||
public 'all tests'(): void { | ||
it('all tests', () => { | ||
expect(all([1, '2'], v => typeof v === 'string')).to.deep.eq(false); | ||
@@ -46,3 +41,3 @@ expect(all([1, '2'], v => typeof v === 'function')).to.deep.eq(false); | ||
expect(all([], v => typeof v === 'number')).to.deep.eq(true); | ||
} | ||
} | ||
}); | ||
}); |
import { expect } from 'chai'; | ||
import { suite, test } from 'mocha-typescript'; | ||
import { describe, it } from 'mocha'; | ||
import { isDefined, isNotNull } from '../src/checks'; | ||
@suite('Simple predicates') | ||
export class SimpleChecks { | ||
@test | ||
public 'isNotNull tests'(): void { | ||
describe('Simple predicates', () => { | ||
it('isNotNull tests', () => { | ||
expect(isNotNull(0)).to.eql(true); | ||
@@ -19,6 +17,5 @@ expect(isNotNull(null)).to.eql(false); | ||
expect(isNotNull(new Map([['a', 1]]))).to.eql(true); | ||
} | ||
}); | ||
@test | ||
public 'isDefined tests'(): void { | ||
it('isDefined tests', () => { | ||
expect(isDefined(0)).to.eql(true); | ||
@@ -34,3 +31,3 @@ expect(isDefined(null)).to.eql(true); | ||
expect(isDefined(new Map([['a', 1]]))).to.eql(true); | ||
} | ||
} | ||
}); | ||
}); |
import { expect } from 'chai'; | ||
import { suite, test } from 'mocha-typescript'; | ||
import { beforeEach, describe, it } from 'mocha'; | ||
import { createQueue, Queue } from '../src/index'; | ||
@suite | ||
export class DeferredProcessingTests { | ||
public q!: Queue<'foo', { idd: string }, any>; | ||
public before(): void { | ||
this.q = createQueue<{ foo: any }, 'foo', { idd: string }>( | ||
describe('Deferred processing tests', () => { | ||
let q: Queue<'foo', { idd: string }, any>; | ||
beforeEach(() => { | ||
q = createQueue<{ foo: any }, 'foo', { idd: string }>( | ||
'foo', | ||
(val: { idd: string }) => `~~${val.idd}~~`, | ||
); | ||
} | ||
}); | ||
@test | ||
public '.queue returns a ref'(): void { | ||
const ref = this.q.queue({ idd: '12345' }); | ||
it('.queue returns a ref', () => { | ||
const ref = q.queue({ idd: '12345' }); | ||
expect(ref).to.deep.eq(['foo', '~~12345~~']); | ||
} | ||
}); | ||
@test | ||
public '.drain calls back w/ the original object'(): void { | ||
this.q.queue({ idd: '23456' }); | ||
it('.drain calls back w/ the original object', () => { | ||
q.queue({ idd: '23456' }); | ||
let iterationCount = 0; | ||
this.q.drain((ref, item) => { | ||
q.drain((ref, item) => { | ||
expect(ref).to.deep.eq(['foo', '~~23456~~']); | ||
@@ -34,16 +30,14 @@ expect(item).to.deep.eq({ | ||
expect(iterationCount).to.eq(1); | ||
} | ||
}); | ||
@test | ||
public '.drain returns the processed object count'(): void { | ||
this.q.queue({ idd: 'asdklh' }); | ||
const { processedCount } = this.q.drain((_ref, _item) => ''); | ||
it('.drain returns the processed object count', () => { | ||
q.queue({ idd: 'asdklh' }); | ||
const { processedCount } = q.drain((_ref, _item) => ''); | ||
expect(processedCount).to.eq(1); | ||
} | ||
}); | ||
@test | ||
public '.drainUntilEmpty completely drains everything'(): void { | ||
this.q.queue({ idd: '23456' }); | ||
it('.drainUntilEmpty completely drains everything', () => { | ||
q.queue({ idd: '23456' }); | ||
let icount = 0; | ||
this.q.drainUntilEmpty((reff, item) => { | ||
q.drainUntilEmpty((reff, item) => { | ||
expect(reff).to.deep.eq(['foo', '~~23456~~']); | ||
@@ -56,11 +50,10 @@ expect(item).to.deep.eq({ | ||
expect(icount).to.eq(1); | ||
} | ||
}); | ||
@test | ||
public '.queue de-duplicates repeated queues'(): void { | ||
it('.queue de-duplicates repeated queues', () => { | ||
const obj = { idd: '34567' }; | ||
this.q.queue(obj); | ||
this.q.queue(obj); | ||
q.queue(obj); | ||
q.queue(obj); | ||
let iterationCount = 0; | ||
this.q.drain((r, item) => { | ||
q.drain((r, item) => { | ||
expect(r).to.deep.eq(['foo', '~~34567~~']); | ||
@@ -73,3 +66,3 @@ expect(item).to.deep.eq({ | ||
expect(iterationCount).to.eq(1); | ||
} | ||
} | ||
}); | ||
}); |
import { expect } from 'chai'; | ||
import { suite, test } from 'mocha-typescript'; | ||
import { describe, it } from 'mocha'; | ||
import { UnreachableError } from '../src/index'; | ||
@suite | ||
export class ErrorTests { | ||
@test | ||
public 'UnreachableError tests'(): void { | ||
describe('Error tests', () => { | ||
it('UnreachableError tests', () => { | ||
expect(() => { | ||
throw new UnreachableError('' as never); | ||
}).to.throw('Reached code that should be unreachable'); | ||
} | ||
} | ||
}); | ||
}); |
import { expect } from 'chai'; | ||
import { suite, test } from 'mocha-typescript'; | ||
import { describe, it } from 'mocha'; | ||
import { pipe } from '../src/pipe'; | ||
@@ -22,5 +22,4 @@ | ||
@suite | ||
export class PipeTests { | ||
@test public 'basic use'(): void { | ||
describe('Pipe tests', () => { | ||
it('basic use', () => { | ||
expect(pipe()(3)).to.eql(3); | ||
@@ -58,3 +57,3 @@ expect(pipe(square)(3)).to.eql(9); | ||
).to.eql(12); | ||
} | ||
} | ||
}); | ||
}); |
import { expect } from 'chai'; | ||
import { suite, test } from 'mocha-typescript'; | ||
import { describe, it } from 'mocha'; | ||
import { timeout } from '../src/index'; | ||
@suite | ||
export class PromiseTests { | ||
@test | ||
public async 'timeout tests'(): Promise<void> { | ||
describe('Promise tests', () => { | ||
it('timeout tests', async () => { | ||
let resolved = false; | ||
@@ -18,3 +16,3 @@ const p = timeout(100).then(() => { | ||
expect(resolved).to.eq(true, 'short timeout resolves sooner than longer timeout (2)'); | ||
} | ||
} | ||
}); | ||
}); |
import { expect } from 'chai'; | ||
import { suite, test } from 'mocha-typescript'; | ||
import { describe, it } from 'mocha'; | ||
import { createRef } from '../src/deferred-processing/ref'; | ||
import { isRef } from '../src/index'; | ||
@suite | ||
export class RefTests { | ||
@test | ||
public 'isRef tests'(): void { | ||
describe('Ref tests', () => { | ||
it('isRef tests', () => { | ||
expect(isRef([] as any)).to.eql(false); | ||
@@ -15,3 +13,3 @@ expect(isRef()).to.eql(false); | ||
expect(isRef(['foo' as any, 99 as any])).to.eql(false); | ||
} | ||
} | ||
}); | ||
}); |
import { expect } from 'chai'; | ||
import { suite, test } from 'mocha-typescript'; | ||
import { describe, it } from 'mocha'; | ||
import { camelize } from '../src/string'; | ||
@suite | ||
export class StringUtilTests { | ||
@test public 'camelize tests'(): void { | ||
describe('String utilities tests', () => { | ||
it('camelize tests', () => { | ||
expect(camelize('')).to.eq(''); | ||
@@ -14,3 +13,3 @@ expect(camelize('FooBar')).to.eq('fooBar'); | ||
expect(camelize('foo-bar')).to.eq('fooBar'); | ||
} | ||
} | ||
}); | ||
}); |
Sorry, the diff of this file is not supported yet
19
86172
1291