-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16378 from thoov/update-ember-metal-tests
[CLEANUP] Convert ember-metal tests over to new style
- Loading branch information
Showing
18 changed files
with
2,157 additions
and
2,112 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,93 +1,95 @@ | ||
import { Cache } from '..'; | ||
import { moduleFor, AbstractTestCase } from 'internal-test-helpers'; | ||
|
||
QUnit.module('Cache'); | ||
moduleFor('Cache', class extends AbstractTestCase { | ||
['@test basic'](assert) { | ||
let cache = new Cache(100, key => key.toUpperCase()); | ||
|
||
QUnit.test('basic', function(assert) { | ||
let cache = new Cache(100, key => key.toUpperCase()); | ||
assert.equal(cache.get('foo'), 'FOO'); | ||
assert.equal(cache.get('bar'), 'BAR'); | ||
assert.equal(cache.get('foo'), 'FOO'); | ||
} | ||
|
||
assert.equal(cache.get('foo'), 'FOO'); | ||
assert.equal(cache.get('bar'), 'BAR'); | ||
assert.equal(cache.get('foo'), 'FOO'); | ||
}); | ||
|
||
QUnit.test('explicit sets', function(assert) { | ||
let cache = new Cache(100, key => key.toUpperCase()); | ||
['@test explicit sets'](assert) { | ||
let cache = new Cache(100, key => key.toUpperCase()); | ||
|
||
assert.equal(cache.get('foo'), 'FOO'); | ||
assert.equal(cache.get('foo'), 'FOO'); | ||
|
||
assert.equal(cache.set('foo', 'FOO!!!'), 'FOO!!!'); | ||
assert.equal(cache.set('foo', 'FOO!!!'), 'FOO!!!'); | ||
|
||
assert.equal(cache.get('foo'), 'FOO!!!'); | ||
assert.equal(cache.get('foo'), 'FOO!!!'); | ||
|
||
assert.strictEqual(cache.set('foo', undefined), undefined); | ||
assert.strictEqual(cache.set('foo', undefined), undefined); | ||
|
||
assert.strictEqual(cache.get('foo'), undefined); | ||
}); | ||
|
||
QUnit.test('caches computation correctly', function(assert) { | ||
let count = 0; | ||
let cache = new Cache(100, key => { | ||
count++; | ||
return key.toUpperCase(); | ||
}); | ||
|
||
assert.equal(count, 0); | ||
cache.get('foo'); | ||
assert.equal(count, 1); | ||
cache.get('bar'); | ||
assert.equal(count, 2); | ||
cache.get('bar'); | ||
assert.equal(count, 2); | ||
cache.get('foo'); | ||
assert.equal(count, 2); | ||
}); | ||
assert.strictEqual(cache.get('foo'), undefined); | ||
} | ||
|
||
QUnit.test('caches computation correctly with custom cache keys', function(assert) { | ||
let count = 0; | ||
let cache = new Cache( | ||
100, | ||
obj => { | ||
['@test caches computation correctly'](assert) { | ||
let count = 0; | ||
let cache = new Cache(100, key => { | ||
count++; | ||
return obj.value.toUpperCase(); | ||
}, | ||
obj => obj.key | ||
); | ||
|
||
assert.equal(count, 0); | ||
cache.get({ key: 'foo', value: 'foo' }); | ||
assert.equal(count, 1); | ||
cache.get({ key: 'bar', value: 'bar' }); | ||
assert.equal(count, 2); | ||
cache.get({ key: 'bar', value: 'bar' }); | ||
assert.equal(count, 2); | ||
cache.get({ key: 'foo', value: 'foo' }); | ||
assert.equal(count, 2); | ||
return key.toUpperCase(); | ||
}); | ||
|
||
assert.equal(count, 0); | ||
cache.get('foo'); | ||
assert.equal(count, 1); | ||
cache.get('bar'); | ||
assert.equal(count, 2); | ||
cache.get('bar'); | ||
assert.equal(count, 2); | ||
cache.get('foo'); | ||
assert.equal(count, 2); | ||
} | ||
|
||
['@test caches computation correctly with custom cache keys'](assert) { | ||
let count = 0; | ||
let cache = new Cache( | ||
100, | ||
obj => { | ||
count++; | ||
return obj.value.toUpperCase(); | ||
}, | ||
obj => obj.key | ||
); | ||
|
||
assert.equal(count, 0); | ||
cache.get({ key: 'foo', value: 'foo' }); | ||
assert.equal(count, 1); | ||
cache.get({ key: 'bar', value: 'bar' }); | ||
assert.equal(count, 2); | ||
cache.get({ key: 'bar', value: 'bar' }); | ||
assert.equal(count, 2); | ||
cache.get({ key: 'foo', value: 'foo' }); | ||
assert.equal(count, 2); | ||
} | ||
|
||
['@test handles undefined value correctly'](assert) { | ||
let count = 0; | ||
let cache = new Cache(100, () => { count++; }); | ||
|
||
assert.equal(count, 0); | ||
assert.strictEqual(cache.get('foo'), undefined); | ||
assert.equal(count, 1); | ||
assert.strictEqual(cache.get('bar'), undefined); | ||
assert.equal(count, 2); | ||
assert.strictEqual(cache.get('bar'), undefined); | ||
assert.equal(count, 2); | ||
assert.strictEqual(cache.get('foo'), undefined); | ||
assert.equal(count, 2); | ||
} | ||
|
||
['@test continues working after reaching cache limit'](assert) { | ||
let cache = new Cache(3, key => key.toUpperCase()); | ||
|
||
cache.get('a'); | ||
cache.get('b'); | ||
cache.get('c'); | ||
|
||
assert.equal(cache.get('d'), 'D'); | ||
assert.equal(cache.get('a'), 'A'); | ||
assert.equal(cache.get('b'), 'B'); | ||
assert.equal(cache.get('c'), 'C'); | ||
} | ||
}); | ||
|
||
QUnit.test('handles undefined value correctly', function(assert) { | ||
let count = 0; | ||
let cache = new Cache(100, () => { count++; }); | ||
|
||
assert.equal(count, 0); | ||
assert.strictEqual(cache.get('foo'), undefined); | ||
assert.equal(count, 1); | ||
assert.strictEqual(cache.get('bar'), undefined); | ||
assert.equal(count, 2); | ||
assert.strictEqual(cache.get('bar'), undefined); | ||
assert.equal(count, 2); | ||
assert.strictEqual(cache.get('foo'), undefined); | ||
assert.equal(count, 2); | ||
}); | ||
|
||
QUnit.test('continues working after reaching cache limit', function(assert) { | ||
let cache = new Cache(3, key => key.toUpperCase()); | ||
|
||
cache.get('a'); | ||
cache.get('b'); | ||
cache.get('c'); | ||
|
||
assert.equal(cache.get('d'), 'D'); | ||
assert.equal(cache.get('a'), 'A'); | ||
assert.equal(cache.get('b'), 'B'); | ||
assert.equal(cache.get('c'), 'C'); | ||
}); |
Oops, something went wrong.