Skip to content

Commit

Permalink
tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Harris-Miller committed Jul 25, 2024
1 parent d7b07f6 commit 16f497f
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions test/isoLens.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
var R = require('../source/index.js');
var eq = require('./shared/eq.js');

var they = it;

var fromPosJson = R.pipe(JSON.parse, value => ({ x: Number.parseFloat(value['@x']), y: Number.parseFloat(value['@y']) }));
var toPosJson = R.pipe(v => ({ '@x': v.x.toString(), '@y': v.y.toString() }), JSON.stringify);


var positionJsonLens = R.lensIso(fromPosJson, toPosJson);
var foobarLens = R.lensProp('foobar');

var objLens = R.compose(foobarLens, positionJsonLens);

var obj = {
foobar: '{"@x":"4","@y":"2"}'
};


describe('lensIso :: view, set, over', function() {
they('view', function() {
eq(R.view(objLens, obj), { x: 4, y: 2 });
});

they('set', function() {
const newObj = R.set(objLens, { x: 1, y: 100 }, obj);
eq(newObj, {
foobar: '{"@x":"1","@y":"100"}'
});
});

they('over', function() {
const newObj = R.over(objLens, R.map(x => x * 2), obj);
eq(newObj, {
foobar: '{"@x":"8","@y":"4"}'
});
});
});

0 comments on commit 16f497f

Please sign in to comment.