2021-02-17 19:55:22 +00:00
|
|
|
import { Single, Double, fromJS, Dictionary, IDENTITY_FOLD, fold, mapPointers, Value } from '../src/index';
|
2021-01-07 16:41:46 +00:00
|
|
|
import './test-utils';
|
|
|
|
|
|
|
|
describe('Single', () => {
|
|
|
|
it('should print reasonably', () => {
|
2021-02-17 15:52:01 +00:00
|
|
|
expect(Single(123.45).toString()).toEqual("123.45f");
|
2021-01-07 16:41:46 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('Double', () => {
|
|
|
|
it('should print reasonably', () => {
|
2021-02-17 19:55:22 +00:00
|
|
|
expect(Double(123.45).toString()).toEqual("123.45");
|
2021-01-07 16:41:46 +00:00
|
|
|
});
|
|
|
|
});
|
2021-02-17 19:55:22 +00:00
|
|
|
|
|
|
|
describe('fold', () => {
|
|
|
|
function mkv<T extends object>(t: T): Value<T> {
|
|
|
|
return fromJS<T>([
|
|
|
|
1,
|
|
|
|
2,
|
|
|
|
new Dictionary([[[3, 4], fromJS([5, 6])],
|
|
|
|
['a', 1],
|
|
|
|
['b', true]]),
|
|
|
|
Single(3.4),
|
|
|
|
t,
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
it('should support identity', () => {
|
|
|
|
const w = new Date();
|
|
|
|
const v = mkv(w);
|
|
|
|
expect(fold(v, IDENTITY_FOLD)).is(v);
|
|
|
|
const w1 = new Date();
|
|
|
|
const v1 = mkv(w1);
|
|
|
|
expect(fold(v, IDENTITY_FOLD)).not.is(v1);
|
|
|
|
expect(mapPointers(v, _t => w1)).is(v1);
|
|
|
|
});
|
|
|
|
});
|