Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test in Coldfusion 11 #43

Open
russplaysguitar opened this issue Apr 27, 2014 · 15 comments
Open

Test in Coldfusion 11 #43

russplaysguitar opened this issue Apr 27, 2014 · 15 comments
Milestone

Comments

@russplaysguitar
Copy link
Owner

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

@russplaysguitar russplaysguitar added this to the v2.5 milestone Apr 27, 2014
@artknight
Copy link

Successfully tested in Lucee 4.5.3 !

@russplaysguitar
Copy link
Owner Author

Good to know!

@dnando
Copy link

dnando commented Dec 16, 2015

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
#43 (comment)
.

@russplaysguitar
Copy link
Owner Author

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

@dnando
Copy link

dnando commented Dec 17, 2015

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
#43 (comment)
.

@russplaysguitar
Copy link
Owner Author

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!

@jtreher
Copy link

jtreher commented Sep 8, 2016

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.

@russplaysguitar
Copy link
Owner Author

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.

@artknight
Copy link

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
#43 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAJoQssQKBYlSD9OJi40FG9c_9x3FH5Bks5qoIvxgaJpZM4B1zc7
.

@jtreher
Copy link

jtreher commented Sep 9, 2016

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
<#43 (comment)
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
#43 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/ABMyw3U9VJE6aO_bHDkOkT7DVcu367tQks5qoI5ygaJpZM4B1zc7
.

@russplaysguitar
Copy link
Owner Author

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.

@elpete
Copy link
Contributor

elpete commented Sep 11, 2016

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

@russplaysguitar
Copy link
Owner Author

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

@jtreher
Copy link

jtreher commented Dec 6, 2016

Yeah, let's roll with that solution.

@russplaysguitar
Copy link
Owner Author

#54 was submitted back in September, been waiting for someone to make the test cases pass for all of the engines

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants