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

NumberLong shell output changed to NumberLong(111111111111) or NumberLong(11111) (when absolute value < 2^30) SERVER-1659

Signed-off-by: Eliot Horowitz <eliot@10gen.com>
This commit is contained in:
Wojciech Piekutowski 2010-08-29 00:20:19 -04:00 committed by Eliot Horowitz
parent 8864cfafff
commit b42dd5c67e
4 changed files with 31 additions and 26 deletions

View File

@ -541,7 +541,7 @@ namespace JSTests {
ASSERT( s->exec( "c = {c:a.a.toString()}", "foo", false, true, false ) );
out = s->getObject( "c" );
stringstream ss;
ss << "NumberLong( \"" << val << "\" )";
ss << "NumberLong(\"" << val << "\")";
ASSERT_EQUALS( ss.str(), out.firstElement().valuestr() );
ASSERT( s->exec( "d = {d:a.a.toNumber()}", "foo", false, true, false ) );

View File

@ -4,50 +4,50 @@ 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 )" );
assert.eq.automsg( "'NumberLong(4)'", "n.toString()" );
assert.eq.automsg( "'NumberLong(4)'", "tojson( n )" );
a = {}
a.a = n;
p = tojson( a );
assert.eq.automsg( "'{ \"a\" : NumberLong( 4 ) }'", "p" );
assert.eq.automsg( "'{ \"a\" : NumberLong(4) }'", "p" );
assert.eq.automsg( "NumberLong( 4 )", "eval( tojson( NumberLong( 4 ) ) )" );
assert.eq.automsg( "NumberLong(4 )", "eval( tojson( NumberLong( 4 ) ) )" );
assert.eq.automsg( "a", "eval( tojson( a ) )" );
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 )" );
assert.eq.automsg( "'NumberLong(-4)'", "n.toString()" );
assert.eq.automsg( "'NumberLong(-4)'", "tojson( n )" );
a = {}
a.a = n;
p = tojson( a );
assert.eq.automsg( "'{ \"a\" : NumberLong( -4 ) }'", "p" );
assert.eq.automsg( "'{ \"a\" : NumberLong(-4) }'", "p" );
// 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 )" );
assert.eq.automsg( "'NumberLong(\"11111111111111111\")'", "n.toString()" );
assert.eq.automsg( "'NumberLong(\"11111111111111111\")'", "tojson( n )" );
a = {}
a.a = n;
p = tojson( a );
assert.eq.automsg( "'{ \"a\" : NumberLong( \"11111111111111111\" ) }'", "p" );
assert.eq.automsg( "'{ \"a\" : NumberLong(\"11111111111111111\") }'", "p" );
assert.eq.automsg( "NumberLong( '11111111111111111' )", "eval( tojson( NumberLong( '11111111111111111' ) ) )" );
assert.eq.automsg( "NumberLong('11111111111111111' )", "eval( tojson( NumberLong( '11111111111111111' ) ) )" );
assert.eq.automsg( "a", "eval( tojson( a ) )" );
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 )" );
assert.eq.automsg( "'NumberLong(\"-11111111111111111\")'", "n.toString()" );
assert.eq.automsg( "'NumberLong(\"-11111111111111111\")'", "tojson( n )" );
a = {}
a.a = n;
p = tojson( a );
assert.eq.automsg( "'{ \"a\" : NumberLong( \"-11111111111111111\" ) }'", "p" );
assert.eq.automsg( "'{ \"a\" : NumberLong(\"-11111111111111111\") }'", "p" );
// parsing
assert.throws.automsg( function() { new NumberLong( "" ); } );

View File

@ -880,12 +880,14 @@ namespace mongo {
JSBool numberlong_tostring(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval){
Convertor c(cx);
stringstream ss;
if ( c.hasProperty( obj, "top" ) ) {
long long val = c.toNumberLongUnsafe( obj );
ss << "NumberLong( \"" << val << "\" )";
} else {
ss << "NumberLong( " << c.getNumber( obj, "floatApprox" ) << " )";
}
long long val = c.toNumberLongUnsafe( obj );
const long long limit = 2LL << 30;
if ( val <= -limit || limit <= val )
ss << "NumberLong(\"" << val << "\")";
else
ss << "NumberLong(" << val << ")";
string ret = ss.str();
return *rval = c.toval( ret.c_str() );
}

View File

@ -719,11 +719,14 @@ namespace mongo {
v8::Handle<v8::Object> it = args.This();
stringstream ss;
if ( !it->Has( v8::String::New( "top" ) ) ) {
ss << "NumberLong( " << it->Get( v8::String::New( "floatApprox" ) )->NumberValue() << " )";
} else {
ss << "NumberLong( \"" << numberLongVal( it ) << "\" )";
}
long long val = numberLongVal( it );
const long long limit = 2LL << 30;
if ( val <= -limit || limit <= val )
ss << "NumberLong(\"" << val << "\")";
else
ss << "NumberLong(" << val << ")";
string ret = ss.str();
return v8::String::New( ret.c_str() );
}