globalizejs/globalize

Code cleanup: Simplify assertRuntimeBind test utility

Open

#486 ouverte le 23 août 2015

Voir sur GitHub
 (0 commentaires) (0 réactions) (0 assignés)JavaScript (645 forks)batch import
help wantedquick change

Métriques du dépôt

Stars
 (4 759 stars)
Métriques de merge PR
 (Aucune PR mergée en 30 j)

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.

Guide contributeur