-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
287 additions
and
3 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 |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// Make sure exceptions are snapshot as well | ||
export const stringifyErrors = function(func) { | ||
return addErrorHandler(func, String) | ||
} | ||
|
||
// Wrap a function with a error handler | ||
const addErrorHandler = function(func, errorHandler) { | ||
return errorHandledFunc.bind(null, func, errorHandler) | ||
} | ||
|
||
const errorHandledFunc = function(func, errorHandler, ...args) { | ||
try { | ||
return func(...args) | ||
} catch (error) { | ||
return errorHandler(error, ...args) | ||
} | ||
} |
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,7 +1,40 @@ | ||
import test from 'ava' | ||
import prettyFormat from 'pretty-format' | ||
|
||
import fastCartesian from '../src/main.js' | ||
|
||
test('Dummy test', t => { | ||
t.is(typeof fastCartesian, 'function') | ||
import { stringifyErrors } from './helpers/error.js' | ||
|
||
const eFastCartesian = stringifyErrors(fastCartesian) | ||
|
||
const generator = function*() { | ||
yield 0 | ||
yield 1 | ||
} | ||
|
||
;[ | ||
[], | ||
[[]], | ||
[[], []], | ||
[undefined], | ||
[null], | ||
[[], true], | ||
[[0]], | ||
[[0], [1]], | ||
[[0, 1]], | ||
[[0, 1], [2]], | ||
[[0, 1], [2, 3]], | ||
// eslint-disable-next-line no-magic-numbers | ||
[[0, 1, 2], [3, 4]], | ||
[[[0]]], | ||
[[0, undefined, 1]], | ||
['abc'], | ||
[new Map([[{}, 0], [{}, 1]])], | ||
[new Set([0, 1])], | ||
[generator()], | ||
].forEach(args => { | ||
const title = prettyFormat(args, { min: true }) | ||
test(title, t => { | ||
t.snapshot(eFastCartesian(...args)) | ||
}) | ||
}) |
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 |
---|---|---|
@@ -0,0 +1,233 @@ | ||
# Snapshot report for `test/main.js` | ||
|
||
The actual snapshot is saved in `main.js.snap`. | ||
|
||
Generated by [AVA](https://ava.li). | ||
|
||
## ["abc"] | ||
|
||
> Snapshot 1 | ||
[ | ||
[ | ||
'a', | ||
], | ||
[ | ||
'b', | ||
], | ||
[ | ||
'c', | ||
], | ||
] | ||
|
||
## [Map {{} => 0, {} => 1}] | ||
|
||
> Snapshot 1 | ||
[ | ||
[ | ||
[ | ||
{}, | ||
0, | ||
], | ||
], | ||
[ | ||
[ | ||
{}, | ||
1, | ||
], | ||
], | ||
] | ||
|
||
## [Set {0, 1}] | ||
|
||
> Snapshot 1 | ||
[ | ||
[ | ||
0, | ||
], | ||
[ | ||
1, | ||
], | ||
] | ||
|
||
## [[0, 1, 2], [3, 4]] | ||
|
||
> Snapshot 1 | ||
[ | ||
[ | ||
0, | ||
3, | ||
], | ||
[ | ||
0, | ||
4, | ||
], | ||
[ | ||
1, | ||
3, | ||
], | ||
[ | ||
1, | ||
4, | ||
], | ||
[ | ||
2, | ||
3, | ||
], | ||
[ | ||
2, | ||
4, | ||
], | ||
] | ||
|
||
## [[0, 1], [2, 3]] | ||
|
||
> Snapshot 1 | ||
[ | ||
[ | ||
0, | ||
2, | ||
], | ||
[ | ||
0, | ||
3, | ||
], | ||
[ | ||
1, | ||
2, | ||
], | ||
[ | ||
1, | ||
3, | ||
], | ||
] | ||
|
||
## [[0, 1], [2]] | ||
|
||
> Snapshot 1 | ||
[ | ||
[ | ||
0, | ||
2, | ||
], | ||
[ | ||
1, | ||
2, | ||
], | ||
] | ||
|
||
## [[0, 1]] | ||
|
||
> Snapshot 1 | ||
[ | ||
[ | ||
0, | ||
], | ||
[ | ||
1, | ||
], | ||
] | ||
|
||
## [[0, undefined, 1]] | ||
|
||
> Snapshot 1 | ||
[ | ||
[ | ||
0, | ||
], | ||
[ | ||
undefined, | ||
], | ||
[ | ||
1, | ||
], | ||
] | ||
|
||
## [[0], [1]] | ||
|
||
> Snapshot 1 | ||
[ | ||
[ | ||
0, | ||
1, | ||
], | ||
] | ||
|
||
## [[0]] | ||
|
||
> Snapshot 1 | ||
[ | ||
[ | ||
0, | ||
], | ||
] | ||
|
||
## [[[0]]] | ||
|
||
> Snapshot 1 | ||
[ | ||
[ | ||
[ | ||
0, | ||
], | ||
], | ||
] | ||
|
||
## [[], []] | ||
|
||
> Snapshot 1 | ||
[] | ||
|
||
## [[], true] | ||
|
||
> Snapshot 1 | ||
'TypeError: Argument must be iterable: true' | ||
|
||
## [[]] | ||
|
||
> Snapshot 1 | ||
[] | ||
|
||
## [] | ||
|
||
> Snapshot 1 | ||
[] | ||
|
||
## [null] | ||
|
||
> Snapshot 1 | ||
'TypeError: Argument must be iterable: null' | ||
|
||
## [undefined] | ||
|
||
> Snapshot 1 | ||
'TypeError: Argument must be iterable: undefined' | ||
|
||
## [{}] | ||
|
||
> Snapshot 1 | ||
[ | ||
[ | ||
0, | ||
], | ||
[ | ||
1, | ||
], | ||
] |
Binary file not shown.