UnderscoreCF icon indicating copy to clipboard operation
UnderscoreCF copied to clipboard

Test in Coldfusion 11

Open russplaysguitar opened this issue 10 years ago • 15 comments

Anyone who wants to do this, it would be much appreciated!

russplaysguitar avatar Apr 27 '14 01:04 russplaysguitar

Successfully tested in Lucee 4.5.3 !

artknight avatar Dec 15 '15 20:12 artknight

Good to know!

russplaysguitar avatar Dec 16 '15 19:12 russplaysguitar

I ran the unit tests on CF 11 and all passed.

Aria Media Sagl Via Rompada 40 6987 Caslano Switzerland

+41 (0)91 600 9601 +41 (0)76 303 4477 cell skype: ariamedia

On Wed, Dec 16, 2015 at 9:14 PM, Russ [email protected] wrote:

Good to know!

— Reply to this email directly or view it on GitHub https://github.com/russplaysguitar/UnderscoreCF/issues/43#issuecomment-165228261 .

dnando avatar Dec 16 '15 21:12 dnando

@dnando Great! Now we just need to get the Travis CI stuff updated

russplaysguitar avatar Dec 17 '15 19:12 russplaysguitar

Russ,

Running the unit tests on Lucee 4.5.2.018, I get a single error on testBind, as below:

Can't cast Complex Object Type Struct to String Use Built-In-Function "serialize(Struct):String" to create a String from Struct

/Users/nando/sites/UnderscoreCF/mxunit_tests/functionsTest.cfc (28) /Users/nando/sites/UnderscoreCF/Underscore.cfc (1356) /Users/nando/sites/UnderscoreCF/mxunit_tests/functionsTest.cfc (34) /Users/nando/sites/mxunit/framework/TestCase.cfc (141) /Users/nando/sites/mxunit/framework/decorators/DataProviderDecorator.cfc (31) /Users/nando/sites/mxunit/framework/TestSuiteRunner.cfc (105) /Users/nando/sites/mxunit/framework/TestSuiteRunner.cfc (55) /Users/nando/sites/mxunit/framework/TestSuite.cfc (131) /Users/nando/sites/mxunit/runner/DirectoryTestSuite.cfc (37) /Users/nando/sites/UnderscoreCF/mxunit_tests/runTests.cfm (8)

Here's the test, with line 28 in italics.

public void function testBind() { var context = new MyClass({name : 'moe'}); var func = function(arg, this) { // writeDump(arg); if (isDefined("this.name")) { return "name: " & this.name; } else if (structKeyExists(arguments, "arg")) { return "name: " & arguments.arg; } else { throw "oops"; } }; var bound = _.bind(func, context); assertEquals('name: moe', bound(), 'can bind a function to a context');

// TODO: once OO-style binding is ready // bound = _(func).bind(context); // equal('name: moe', bound(), 'can do OO-style binding');

bound = _.bind(func, {}, 'curly'); assertEquals('name: curly', bound(), 'can bind without specifying a context');

func = function(salutation, name) { return salutation & ': ' & name; };

func = _.bind(func, {}, 'hello'); assertEquals('hello: moe', func('moe'), 'the function was partially applied in advance');

var func2 = _.bind(func, {}, 'curly'); assertEquals('hello: curly', func2(), 'the function was completely applied in advance');

var func = function(salutation, firstname, lastname) { return salutation & ': ' & firstname & ' ' & lastname; }; func = _.bind(func, {}, 'hello', 'moe', 'curly'); assertEquals('hello: moe curly', func(), 'the function was partially applied in advance and can accept multiple arguments'); }

Aria Media Sagl Via Rompada 40 6987 Caslano Switzerland

+41 (0)91 600 9601 +41 (0)76 303 4477 cell skype: ariamedia

On Thu, Dec 17, 2015 at 8:23 PM, Russ [email protected] wrote:

@dnando https://github.com/dnando Great! Now we just need to get the Travis CI stuff updated

— Reply to this email directly or view it on GitHub https://github.com/russplaysguitar/UnderscoreCF/issues/43#issuecomment-165555051 .

dnando avatar Dec 17 '15 20:12 dnando

Thanks for testing that out. Looks like that's the same error that Travis gets on the Railo 4.1+ and Lucee 4.5.1+.

I remember trying to resolve this issue when it first occurred, but was unable to figure it out at the time. I should probably give it another shot!

russplaysguitar avatar Dec 18 '15 19:12 russplaysguitar

Hey,

I think I might have figured out something related. Between JRE7 and JRE8 java changed the algorithm for iterating over HashMaps. In either case, you can't rely on the order of struct keys. It would appear that underscore, by using the for ... in syntax over a struct, is relying on the order of keys.

In memoize we ultmately call map in the hasher and then pluck the first value. Since the returning array from map is being built by "for...in" looping through the keys of the arguments, the order of the array is unpredictable -- yet we are always expecting the first element to be a simple value calling _.first( .toArray( x ) ). This ultimately throws Can't cast Complex Object Type String or some variation of that type of error because the first element of the array could be a complex object and we are immediately trying to use that first value as the key in a StructKeyExists in memoize. It's certainly not the value you think it will be.

jtreher avatar Sep 08 '16 10:09 jtreher

Ah, that makes sense. I can't think of a good way to resolve this yet, given that the behavior in UnderscoreJS relies on arguments to be ordered (even though you normally wouldn't expect that of JS objects either). Any ideas are appreciated.

russplaysguitar avatar Sep 08 '16 22:09 russplaysguitar

In Lucee 5 and prob in ACF12 you can specify ordered structs.

-- Arthur

On Thu, Sep 8, 2016 at 6:28 PM, Russ [email protected] wrote:

Ah, that makes sense. I can't think of a good way to resolve this yet, given that the behavior in UnderscoreJS relies on arguments to be ordered (even though you normally wouldn't expect that of JS objects either). Any ideas are appreciated.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/russplaysguitar/UnderscoreCF/issues/43#issuecomment-245761670, or mute the thread https://github.com/notifications/unsubscribe-auth/AAJoQssQKBYlSD9OJi40FG9c_9x3FH5Bks5qoIvxgaJpZM4B1zc7 .

artknight avatar Sep 08 '16 22:09 artknight

Instead of passing in arguments directly to hasher, I did var _args = CreateObject("java", "java.util.LinkedHashMap").init( arguments ) before calling hasher(x) in memoize and that preserved order. There is going to be a bit of a performance penalty there. Alternatively, in this case, the structs come in with numeric keys that retain position so you could simply do a structKeyArray, sort the array, and then loop over that array. That solution assumes that the struct has keys that indicate sort order.

If you always knew that you were going to be working with the arguments struct, you could just automatically assume that you can loop from 1 to structCount, appending from the array from object[n].

On Thu, Sep 8, 2016 at 6:38 PM, Arthur [email protected] wrote:

In Lucee 5 and prob in ACF12 you can specify ordered structs.

-- Arthur

On Thu, Sep 8, 2016 at 6:28 PM, Russ [email protected] wrote:

Ah, that makes sense. I can't think of a good way to resolve this yet, given that the behavior in UnderscoreJS relies on arguments to be ordered (even though you normally wouldn't expect that of JS objects either). Any ideas are appreciated.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub <https://github.com/russplaysguitar/UnderscoreCF/issues/43#issuecomment- 245761670>, or mute the thread <https://github.com/notifications/unsubscribe- auth/AAJoQssQKBYlSD9OJi40FG9c_9x3FH5Bks5qoIvxgaJpZM4B1zc7>

.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/russplaysguitar/UnderscoreCF/issues/43#issuecomment-245763879, or mute the thread https://github.com/notifications/unsubscribe-auth/ABMyw3U9VJE6aO_bHDkOkT7DVcu367tQks5qoI5ygaJpZM4B1zc7 .

jtreher avatar Sep 09 '16 00:09 jtreher

Alright, so it sounds like the high-level options are:

  1. Use ordered structs, but the drawback is that it would require ACF12/Lucee5.
  2. Use java.util.linkedHashMap, but the drawbacks there are: adding a dependency to Java internals and potentially degrading performance (depending on the implementation?).
  3. Write some special-case handling for the arguments struct (not sure if there's a way to test a struct for whether it is an arguments struct).

Not sure about which of these are viable or not, just providing a summary here.

russplaysguitar avatar Sep 09 '16 19:09 russplaysguitar

I would think to start with #2 until we see that performance is an issue?

elpete avatar Sep 11 '16 00:09 elpete

I'd open to any solution, really. We can always optimize later if necessary.

russplaysguitar avatar Sep 12 '16 18:09 russplaysguitar

Yeah, let's roll with that solution.

jtreher avatar Dec 06 '16 20:12 jtreher

https://github.com/russplaysguitar/UnderscoreCF/pull/54 was submitted back in September, been waiting for someone to make the test cases pass for all of the engines

russplaysguitar avatar Dec 07 '16 00:12 russplaysguitar