0
0
mirror of https://github.com/mongodb/mongo.git synced 2024-12-01 09:32:32 +01:00
mongodb/jstests/numberlong.js

56 lines
2.0 KiB
JavaScript
Raw Normal View History

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" );
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 );
assert.eq.automsg( "'{ \"a\" : NumberLong(4) }'", "p" );
2010-06-23 02:53:11 +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" );
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 );
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" );
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 );
assert.eq.automsg( "'{ \"a\" : NumberLong(\"11111111111111111\") }'", "p" );
2010-06-23 02:53:11 +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" );
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 );
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" ); } );