2010-06-23 04:18:07 +02:00
|
|
|
assert.eq.automsg( "0", "new NumberLong()" );
|
|
|
|
|
2010-06-23 02:53:11 +02:00
|
|
|
n = new NumberLong( 4 );
|
|
|
|
assert.eq.automsg( "4", "n" );
|
|
|
|
assert.eq.automsg( "4", "n.toNumber()" );
|
|
|
|
assert.eq.automsg( "8", "n + 4" );
|
2010-08-29 06:20:19 +02:00
|
|
|
assert.eq.automsg( "'NumberLong(4)'", "n.toString()" );
|
|
|
|
assert.eq.automsg( "'NumberLong(4)'", "tojson( n )" );
|
2010-06-23 02:53:11 +02:00
|
|
|
a = {}
|
|
|
|
a.a = n;
|
|
|
|
p = tojson( a );
|
2010-08-29 06:20:19 +02:00
|
|
|
assert.eq.automsg( "'{ \"a\" : NumberLong(4) }'", "p" );
|
2010-06-23 02:53:11 +02:00
|
|
|
|
2010-08-29 06:20:19 +02:00
|
|
|
assert.eq.automsg( "NumberLong(4 )", "eval( tojson( NumberLong( 4 ) ) )" );
|
2010-06-23 04:18:07 +02:00
|
|
|
assert.eq.automsg( "a", "eval( tojson( a ) )" );
|
|
|
|
|
2010-06-23 02:53:11 +02:00
|
|
|
n = new NumberLong( -4 );
|
|
|
|
assert.eq.automsg( "-4", "n" );
|
|
|
|
assert.eq.automsg( "-4", "n.toNumber()" );
|
|
|
|
assert.eq.automsg( "0", "n + 4" );
|
2010-08-29 06:20:19 +02:00
|
|
|
assert.eq.automsg( "'NumberLong(-4)'", "n.toString()" );
|
|
|
|
assert.eq.automsg( "'NumberLong(-4)'", "tojson( n )" );
|
2010-06-23 02:53:11 +02:00
|
|
|
a = {}
|
|
|
|
a.a = n;
|
|
|
|
p = tojson( a );
|
2010-08-29 06:20:19 +02:00
|
|
|
assert.eq.automsg( "'{ \"a\" : NumberLong(-4) }'", "p" );
|
2010-06-23 02:53:11 +02:00
|
|
|
|
|
|
|
// too big to fit in double
|
|
|
|
n = new NumberLong( "11111111111111111" );
|
|
|
|
assert.eq.automsg( "11111111111111112", "n.toNumber()" );
|
|
|
|
assert.eq.automsg( "11111111111111116", "n + 4" );
|
2010-08-29 06:20:19 +02:00
|
|
|
assert.eq.automsg( "'NumberLong(\"11111111111111111\")'", "n.toString()" );
|
|
|
|
assert.eq.automsg( "'NumberLong(\"11111111111111111\")'", "tojson( n )" );
|
2010-06-23 02:53:11 +02:00
|
|
|
a = {}
|
|
|
|
a.a = n;
|
|
|
|
p = tojson( a );
|
2010-08-29 06:20:19 +02:00
|
|
|
assert.eq.automsg( "'{ \"a\" : NumberLong(\"11111111111111111\") }'", "p" );
|
2010-06-23 02:53:11 +02:00
|
|
|
|
2010-08-29 06:20:19 +02:00
|
|
|
assert.eq.automsg( "NumberLong('11111111111111111' )", "eval( tojson( NumberLong( '11111111111111111' ) ) )" );
|
2010-06-23 04:18:07 +02:00
|
|
|
assert.eq.automsg( "a", "eval( tojson( a ) )" );
|
|
|
|
|
2010-06-23 02:53:11 +02:00
|
|
|
n = new NumberLong( "-11111111111111111" );
|
|
|
|
assert.eq.automsg( "-11111111111111112", "n.toNumber()" );
|
|
|
|
assert.eq.automsg( "-11111111111111108", "n + 4" );
|
2010-08-29 06:20:19 +02:00
|
|
|
assert.eq.automsg( "'NumberLong(\"-11111111111111111\")'", "n.toString()" );
|
|
|
|
assert.eq.automsg( "'NumberLong(\"-11111111111111111\")'", "tojson( n )" );
|
2010-06-23 02:53:11 +02:00
|
|
|
a = {}
|
|
|
|
a.a = n;
|
|
|
|
p = tojson( a );
|
2010-08-29 06:20:19 +02:00
|
|
|
assert.eq.automsg( "'{ \"a\" : NumberLong(\"-11111111111111111\") }'", "p" );
|
2010-06-23 02:53:11 +02:00
|
|
|
|
|
|
|
// parsing
|
2010-06-23 05:44:22 +02:00
|
|
|
assert.throws.automsg( function() { new NumberLong( "" ); } );
|
2010-06-23 02:53:11 +02:00
|
|
|
assert.throws.automsg( function() { new NumberLong( "y" ); } );
|
|
|
|
assert.throws.automsg( function() { new NumberLong( "11111111111111111111" ); } );
|