Skip to content
Browse files

more incredible tests

  • Loading branch information...
1 parent 999eeda commit 3a8fbfe2dd78f2c9abca1e55079e3a8f395f254c @maxtaco committed
Showing with 69 additions and 14 deletions.
  1. +36 −0 lib/coffee-script/nodes.js
  2. +10 −0 src/nodes.coffee
  3. +23 −14 test/tame.coffee
View
36 lib/coffee-script/nodes.js
@@ -1388,6 +1388,25 @@
Obj.prototype.children = ['properties'];
+ Obj.prototype.tameWrapContinuation = YES;
+
+ Obj.prototype.tameCpsRotate = function() {
+ var prop, v, _i, _len, _ref2, _results;
+ _ref2 = this.properties;
+ _results = [];
+ for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
+ prop = _ref2[_i];
+ if (prop instanceof Assign) {
+ if ((v = this.tameCpsExprRotate(prop.value))) {
+ _results.push(prop.value = v);
+ } else {
+ _results.push(void 0);
+ }
+ }
+ }
+ return _results;
+ };
+
Obj.prototype.compileNode = function(o) {
var i, idt, indent, join, lastNoncom, node, obj, prop, props, _i, _len;
props = this.properties;
@@ -1456,6 +1475,23 @@
Arr.prototype.filterImplicitObjects = Call.prototype.filterImplicitObjects;
+ Arr.prototype.tameWrapContinuation = YES;
+
+ Arr.prototype.tameCpsRotate = function() {
+ var i, o, v, _len, _ref2, _results;
+ _ref2 = this.objects;
+ _results = [];
+ for (i = 0, _len = _ref2.length; i < _len; i++) {
+ o = _ref2[i];
+ if ((v = this.tameCpsExprRotate(o))) {
+ _results.push(this.objects[i] = v);
+ } else {
+ _results.push(void 0);
+ }
+ }
+ return _results;
+ };
+
Arr.prototype.compileNode = function(o) {
var code, obj, objs;
if (!this.objects.length) return '[]';
View
10 src/nodes.coffee
@@ -1151,6 +1151,11 @@ exports.Obj = class Obj extends Base
children: ['properties']
+ tameWrapContinuation : YES
+ tameCpsRotate : ->
+ for prop in @properties when prop instanceof Assign
+ prop.value = v if (v = @tameCpsExprRotate prop.value)
+
compileNode: (o) ->
props = @properties
propNames = []
@@ -1202,6 +1207,11 @@ exports.Arr = class Arr extends Base
filterImplicitObjects: Call::filterImplicitObjects
+ tameWrapContinuation : YES
+ tameCpsRotate: ->
+ for o,i in @objects
+ @objects[i] = v if (v = @tameCpsExprRotate o)
+
compileNode: (o) ->
return '[]' unless @objects.length
o.indent += TAB
View
37 test/tame.coffee
@@ -412,20 +412,29 @@ atest 'expressions - call args (2)', (cb) ->
x = await slowAdd (await slowAdd 1, 2, defer _), (await slowAdd 3, 4, defer _), defer _
cb(x is 10, {})
-#atest 'arrays and objects', (cb) ->
-# id = "image data"
-# loadImage = (n, cb) ->
-# await delay defer()
-# cb id
-# arr = [
-# (await loadImage "file.jpg", defer()),
-# "another value" ]
-# obj =
-# i : (await loadImage "file.jpg", defer())
-# v : "another value"
-# cb(arr[0] is id and obj.i is id, {})
-#
-#
+atest 'arrays and objects', (cb) ->
+ id = "image data"
+ loadImage = (n, cb) ->
+ await delay defer()
+ cb id
+ arr = [
+ (await loadImage "file.jpg", defer _),
+ "another value" ]
+ obj =
+ i : (await loadImage "file.jpg", defer _)
+ v : "another value"
+ cb(arr[0] is id and obj.i is id, {})
+
+atest 'arrays 2', (cb) ->
+ parrot = (n, cb) ->
+ await delay defer()
+ cb n
+ arr = [
+ (await parrot 1, defer _),
+ [ (await parrot 2, defer _),
+ (await parrot 3, defer _) ],
+ (await parrot 4, defer _) ]
+ cb(arr[0] + arr[1][0] + arr[1][1] + arr[2] is 10, {})
atest 'nesting', (cb) ->
id = "image data"

0 comments on commit 3a8fbfe

Please sign in to comment.
Something went wrong with that request. Please try again.