globalizejs/globalize

Code cleanup: Simplify assertRuntimeBind test utility

Open

#486 opened on Aug 23, 2015

View on GitHub
 (0 comments) (0 reactions) (0 assignees)JavaScript (645 forks)batch import
help wantedquick change

Repository metrics

Stars
 (4,759 stars)
PR merge metrics
 (No merged PRs in 30d)

Description

In #436, @jzaefferer said the below. The goal of this issue is following-up with this change.

Actually, this allows a custom tests to be performed by each calling code. For example: https://github.com/jquery/globalize/pull/436/files#diff-9ee4a6f38e08bc680f4668d25dedaff8R30, https://github.com/jquery/globalize/pull/436/files#diff-3b257e2c8b293a57b0336b413514f034R110. Please, just let me know if I misinterpreted your comment.

Its called synchronously with an argument passed by the caller. Thats trivial to do without the callback. From test/functional/number/number-formatter.js:

util.assertRuntimeBind(
    assert,
    Globalize.numberFormatter(),
    "b468386326",
    "Globalize(\"en\").numberFormatter({})",
    function( runtimeArgs ) {
        assert.equal( JSON.stringify( runtimeArgs[ 0 ] ), "[\"\",null,1,0,3,null,null," +
            "null,3,null,\"\",\"#,##0.###\",\"-#,##0.###\",\"-\",\"\",null,\"∞\",\"NaN\",{" +
            "\".\":\".\",\",\":\",\",\"%\":\"%\",\"+\":\"+\",\"-\":\"-\",\"E\":\"E\",\"‰\":" +
            "\"‰\"},null]"
        );
        assert.ok( "generatorString" in runtimeArgs[ 0 ][ 15 ] );
        assert.equal( runtimeArgs[ 0 ][ 15 ].generatorString(), "numberRound()" );
    }
);

turns to

var formatter = Globalize.numberFormatter() 
util.assertRuntimeBind( assert, formatter, "b468386326", "Globalize(\"en\").numberFormatter({})" );
assert.equal( JSON.stringify( formatter.runtimeArgs[ 0 ] ), "[\"\",null,1,0,3,null,null," +
    "null,3,null,\"\",\"#,##0.###\",\"-#,##0.###\",\"-\",\"\",null,\"∞\",\"NaN\",{" +
    "\".\":\".\",\",\":\",\",\"%\":\"%\",\"+\":\"+\",\"-\":\"-\",\"E\":\"E\",\"‰\":" +
    "\"‰\"},null]"
);
assert.ok( "generatorString" in formatter.runtimeArgs[ 0 ][ 15 ] );
assert.equal( formatter.runtimeArgs[ 0 ][ 15 ].generatorString(), "numberRound()" );

And you can drop the noop function arguments and you get simpler stacktraces.

Contributor guide