summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDwight <dmerriman@gmail.com>2009-11-30 17:44:37 -0500
committerDwight <dmerriman@gmail.com>2009-11-30 17:44:37 -0500
commit84fbab144fc44c3af8dde09d8ffbb8427b61d077 (patch)
tree1b905f01e04fc53262e14c6c6de2cb55031cdfb7
parent77e5ed58d6967ca0f91299a58dafa10bf185f067 (diff)
parentd538c3c8b4b1d0b2de1623733c5d883edb655f5c (diff)
downloadmongo-84fbab144fc44c3af8dde09d8ffbb8427b61d077.tar.gz
Merge branch 'master' of git@github.com:mongodb/mongo
-rw-r--r--db/concurrency.h2
-rw-r--r--db/json.cpp19
-rw-r--r--dbtests/framework.cpp4
-rw-r--r--dbtests/jsontests.cpp52
-rw-r--r--dbtests/matchertests.cpp2
-rw-r--r--dbtests/namespacetests.cpp2
-rw-r--r--dbtests/querytests.cpp2
-rw-r--r--s/shardkey.cpp2
-rw-r--r--scripting/engine_spidermonkey.cpp3
9 files changed, 79 insertions, 9 deletions
diff --git a/db/concurrency.h b/db/concurrency.h
index 7319b30db63..f7f16aaeedb 100644
--- a/db/concurrency.h
+++ b/db/concurrency.h
@@ -15,6 +15,8 @@
#if BOOST_VERSION >= 103500
#include <boost/thread/shared_mutex.hpp>
+#undef assert
+#define assert xassert
#endif
namespace mongo {
diff --git a/db/json.cpp b/db/json.cpp
index 4735f5250d6..ceb214e97b5 100644
--- a/db/json.cpp
+++ b/db/json.cpp
@@ -248,6 +248,17 @@ namespace mongo {
ObjectBuilder &b;
};
+ struct intValue {
+ intValue( ObjectBuilder &_b ) : b( _b ) {}
+ void operator() ( long long num ) const {
+ if (num >= numeric_limits<int>::min() && num <= numeric_limits<int>::max())
+ b.back()->append( b.fieldName(), (int)num );
+ else
+ b.back()->append( b.fieldName(), num );
+ }
+ ObjectBuilder &b;
+ };
+
struct subobjectEnd {
subobjectEnd( ObjectBuilder &_b ) : b( _b ) {}
void operator() ( const char *start, const char *end ) const {
@@ -435,6 +446,7 @@ public:
str[ stringEnd( self.b ) ] |
singleQuoteStr[ stringEnd( self.b ) ] |
number |
+ integer |
object[ subobjectEnd( self.b ) ] |
array[ arrayEnd( self.b ) ] |
lexeme_d[ str_p( "true" ) ][ trueValue( self.b ) ] |
@@ -470,7 +482,10 @@ public:
// real_p accepts numbers with nonsignificant zero prefixes, which
// aren't allowed in JSON. Oh well.
- number = real_p[ numberValue( self.b ) ];
+ number = strict_real_p[ numberValue( self.b ) ];
+
+ static int_parser<long long, 10, 1, numeric_limits<long long>::digits10 + 1> long_long_p;
+ integer = long_long_p[ intValue(self.b) ];
// We allow a subset of valid js identifier names here.
unquotedFieldName = lexeme_d[ ( alpha_p | ch_p( '$' ) | ch_p( '_' ) ) >> *( ( alnum_p | ch_p( '$' ) | ch_p( '_' )) ) ];
@@ -512,7 +527,7 @@ public:
( ~range_p( 0x00, 0x1f ) & ~ch_p( '/' ) & ( ~ch_p( '\\' ) )[ ch( self.b ) ] ) ) >> str_p( "/" )[ regexValue( self.b ) ]
>> ( *( ch_p( 'i' ) | ch_p( 'g' ) | ch_p( 'm' ) ) )[ regexOptions( self.b ) ] ];
}
- rule< ScannerT > object, members, array, elements, value, str, number,
+ rule< ScannerT > object, members, array, elements, value, str, number, integer,
dbref, dbrefS, dbrefT, oid, oidS, oidT, bindata, date, dateS, dateT,
regex, regexS, regexT, quotedOid, fieldName, unquotedFieldName, singleQuoteStr;
const rule< ScannerT > &start() const {
diff --git a/dbtests/framework.cpp b/dbtests/framework.cpp
index 4cfd6e6e828..b92ee20de5d 100644
--- a/dbtests/framework.cpp
+++ b/dbtests/framework.cpp
@@ -108,8 +108,10 @@ namespace mongo {
}
if ( ! passes ){
+ string s = err.str();
+ log() << "FAIL: " << s << endl;
r->_fails++;
- r->_messages.push_back( err.str() );
+ r->_messages.push_back( s );
}
}
diff --git a/dbtests/jsontests.cpp b/dbtests/jsontests.cpp
index d0c21731254..b7f0a678180 100644
--- a/dbtests/jsontests.cpp
+++ b/dbtests/jsontests.cpp
@@ -900,6 +900,56 @@ namespace JsonTests {
}
};
+ class NumericTypes : public Base {
+ public:
+ void run(){
+ Base::run();
+
+ BSONObj o = fromjson(json());
+
+ ASSERT(o["int"].type() == NumberInt);
+ ASSERT(o["long"].type() == NumberLong);
+ ASSERT(o["double"].type() == NumberDouble);
+
+ ASSERT(o["long"].numberLong() == 9223372036854775807ll);
+ }
+
+ virtual BSONObj bson() const {
+ return BSON( "int" << 123
+ << "long" << 9223372036854775807ll // 2**63 - 1
+ << "double" << 3.14
+ );
+ }
+ virtual string json() const {
+ return "{ \"int\": 123, \"long\": 9223372036854775807, \"double\": 3.14 }";
+ }
+ };
+
+ class NegativeNumericTypes : public Base {
+ public:
+ void run(){
+ Base::run();
+
+ BSONObj o = fromjson(json());
+
+ ASSERT(o["int"].type() == NumberInt);
+ ASSERT(o["long"].type() == NumberLong);
+ ASSERT(o["double"].type() == NumberDouble);
+
+ ASSERT(o["long"].numberLong() == -9223372036854775807ll);
+ }
+
+ virtual BSONObj bson() const {
+ return BSON( "int" << -123
+ << "long" << -9223372036854775807ll // -1 * (2**63 - 1)
+ << "double" << -3.14
+ );
+ }
+ virtual string json() const {
+ return "{ \"int\": -123, \"long\": -9223372036854775807, \"double\": -3.14 }";
+ }
+ };
+
} // namespace FromJsonTests
class All : public Suite {
@@ -978,6 +1028,8 @@ namespace JsonTests {
add< FromJsonTests::SingleQuotes >();
add< FromJsonTests::ObjectId >();
add< FromJsonTests::ObjectId2 >();
+ add< FromJsonTests::NumericTypes >();
+ add< FromJsonTests::NegativeNumericTypes >();
}
} myall;
diff --git a/dbtests/matchertests.cpp b/dbtests/matchertests.cpp
index 08370889d6e..023cc9cda4f 100644
--- a/dbtests/matchertests.cpp
+++ b/dbtests/matchertests.cpp
@@ -70,7 +70,7 @@ namespace MatcherTests {
void run(){
BSONObj query = fromjson( "{ a : { $in : [4,6] } }" );
ASSERT_EQUALS( 4 , query["a"].embeddedObject()["$in"].embeddedObject()["0"].number() );
- ASSERT_EQUALS( NumberDouble , query["a"].embeddedObject()["$in"].embeddedObject()["0"].type() );
+ ASSERT_EQUALS( NumberInt , query["a"].embeddedObject()["$in"].embeddedObject()["0"].type() );
JSMatcher m( query );
diff --git a/dbtests/namespacetests.cpp b/dbtests/namespacetests.cpp
index aabaf8e0066..ff3aa879d06 100644
--- a/dbtests/namespacetests.cpp
+++ b/dbtests/namespacetests.cpp
@@ -553,7 +553,7 @@ namespace NamespaceTests {
id().getKeysFromObject( fromjson( "{a:1,b:[]}" ), keys );
checkSize(1, keys );
cout << "YO : " << *(keys.begin()) << endl;
- ASSERT_EQUALS( NumberDouble , keys.begin()->firstElement().type() );
+ ASSERT_EQUALS( NumberInt , keys.begin()->firstElement().type() );
keys.clear();
}
diff --git a/dbtests/querytests.cpp b/dbtests/querytests.cpp
index 6d579958e01..fc4ddd6fbd9 100644
--- a/dbtests/querytests.cpp
+++ b/dbtests/querytests.cpp
@@ -724,7 +724,7 @@ namespace QueryTests {
ASSERT( userCreateNS( ns() , fromjson( "{ capped : true , size : 2000 }" ) , err , false ) );
for ( int i=0; i<100; i++ ){
insertNext();
- ASSERT( count() < 40 );
+ ASSERT( count() < 45 );
}
int a = count();
diff --git a/s/shardkey.cpp b/s/shardkey.cpp
index eab84b4ec4f..ad91c36cbc2 100644
--- a/s/shardkey.cpp
+++ b/s/shardkey.cpp
@@ -472,7 +472,7 @@ normal:
ShardKeyPattern k( BSON( "key" << 1 ) );
BSONObjBuilder b;
k.getFilter(b, fromjson("{z:3,key:30}"), fromjson("{key:90}"));
- BSONObj x = fromjson("{ key: { $gte: 30.0, $lt: 90.0 } }");
+ BSONObj x = fromjson("{ key: { $gte: 30, $lt: 90 } }");
assert( x.woEqual(b.obj()) );
}
void div(const char *a, const char *res) {
diff --git a/scripting/engine_spidermonkey.cpp b/scripting/engine_spidermonkey.cpp
index e7f0762f43f..3ad76ee1b5c 100644
--- a/scripting/engine_spidermonkey.cpp
+++ b/scripting/engine_spidermonkey.cpp
@@ -913,8 +913,7 @@ namespace mongo {
int x = 0;
assert( x = 1 );
- if ( x != 1 )
- throw -1;
+ uassert( "assert not being executed" , x == 1 );
}
~SMEngine(){