Skip to content

Commit

Permalink
Remove clone() methods from List and Generic
Browse files Browse the repository at this point in the history
* Keep all cloning together for readability and interface hiding.
  • Loading branch information
maryrosecook committed Aug 13, 2013
1 parent dcbbf54 commit bc9241c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 32 deletions.
40 changes: 20 additions & 20 deletions spec/library.spec.js
Expand Up @@ -50,30 +50,30 @@ describe('library', function() {
var l = new library.List();
l.add("1");
l.add("2");
expect(l.clone().items()[0]).toEqual("1");
expect(l.clone().items()[1]).toEqual("2");
expect(l.clone() !== l).toEqual(true);
expect(l.clone().constructor === library.List).toEqual(true);
expect(library.clone(l).items()[0]).toEqual("1");
expect(library.clone(l).items()[1]).toEqual("2");
expect(library.clone(l) !== l).toEqual(true);
expect(library.clone(l).constructor === library.List).toEqual(true);
});

it('should clone list inside list', function() {
var l = new library.List();
var innerL = new library.List();
innerL.add("1");
l.add(innerL);
expect(l.clone().items()[0].items()[0]).toEqual("1");
expect(l.clone().items()[0] !== innerL).toEqual(true);
expect(l.clone().items()[0].constructor === library.List).toEqual(true);
expect(library.clone(l).items()[0].items()[0]).toEqual("1");
expect(library.clone(l).items()[0] !== innerL).toEqual(true);
expect(library.clone(l).items()[0].constructor === library.List).toEqual(true);
});

it('should clone generic inside list', function() {
var l = new library.List();
var g = new library.Generic();
g.la = "1";
l.add(g);
expect(l.clone().items()[0].la).toEqual("1");
expect(l.clone() !== l).toEqual(true);
expect(l.clone().items()[0].constructor === library.Generic).toEqual(true);
expect(library.clone(l).items()[0].la).toEqual("1");
expect(library.clone(l) !== l).toEqual(true);
expect(library.clone(l).items()[0].constructor === library.Generic).toEqual(true);
});
});

Expand All @@ -82,30 +82,30 @@ describe('library', function() {
var g = new library.Generic();
g.one = "1";
g.two = "2";
expect(g.clone().one).toEqual("1");
expect(g.clone().two).toEqual("2");
expect(g.clone() !== g).toEqual(true);
expect(g.clone() instanceof library.Generic).toEqual(true);
expect(library.clone(g).one).toEqual("1");
expect(library.clone(g).two).toEqual("2");
expect(library.clone(g) !== g).toEqual(true);
expect(library.clone(g) instanceof library.Generic).toEqual(true);
});

it('should clone a list inside a generic', function() {
var g = new library.Generic();
var l = new library.List();
l.add("1");
g.l = l;
expect(g.clone().l.items()[0]).toEqual("1");
expect(g.clone().l !== l).toEqual(true);
expect(g.clone().l.constructor === library.List).toEqual(true);
expect(library.clone(g).l.items()[0]).toEqual("1");
expect(library.clone(g).l !== l).toEqual(true);
expect(library.clone(g).l.constructor === library.List).toEqual(true);
});

it('should clone generic inside generic', function() {
var g = new library.Generic();
var innerG = new library.Generic();
innerG.one = "1";
g.innerG = innerG;
expect(g.clone().innerG.one).toEqual("1");
expect(g.clone().innerG !== innerG).toEqual(true);
expect(g.clone().innerG.constructor === library.Generic).toEqual(true);
expect(library.clone(g).innerG.one).toEqual("1");
expect(library.clone(g).innerG !== innerG).toEqual(true);
expect(library.clone(g).innerG.constructor === library.Generic).toEqual(true);
});
});

Expand Down
13 changes: 1 addition & 12 deletions src/library.js
Expand Up @@ -107,12 +107,6 @@
}

return out;
},

clone: function() {
var c = new Generic();
extendObj(this, c);
return c;
}
};

Expand Down Expand Up @@ -191,16 +185,11 @@

return out;
}
},

clone: function() {
var c = new List();
c.data = clone(this.data);
return c;
}
};

exports.Library.List = List;
exports.Library.Generic = Generic;
exports.Library.getInitialEnv = getInitialEnv;
exports.Library.clone = clone; // exported for testing
})(typeof exports === 'undefined' ? this.Isla : exports);

0 comments on commit bc9241c

Please sign in to comment.