#1
authoradam <anton@adamansky.com>
Sun, 4 Nov 2012 18:53:39 +0000 (01:53 +0700)
committeradam <anton@adamansky.com>
Sun, 4 Nov 2012 18:53:39 +0000 (01:53 +0700)
node/ejdb_native.cc
node/tests/t2.js

index 7a1f7b2..b0721ad 100644 (file)
@@ -1129,9 +1129,10 @@ finish:
                 return scope.Close(ThrowException(Exception::Error(String::New("Empty cursor"))));
             }
             assert(!(pos < 0 || pos >= rsz)); //m_pos correctly set by s_set_pos
-            void *bsdata = TCLISTVALPTR(c->m_rs, pos);
+            const void *bsdata = TCLISTVALPTR(c->m_rs, pos);
             assert(bsdata);
             bson_iterator it;
+            bson_iterator_from_buffer(&it, (const char*) bsdata);
             bson_type bt = bson_find_fieldpath_value2(*fpath, fpath.length(), &it);
             if (bt == BSON_EOO) {
                 return scope.Close(Undefined());
index 959b1ed..017e11e 100644 (file)
@@ -49,8 +49,6 @@ module.exports.testSaveLoad = function(test) {
     });
 };
 
-/*
-
 module.exports.testQuery1 = function(test) {
     test.ok(jb);
     test.ok(jb.isOpen());
@@ -80,8 +78,6 @@ module.exports.testQuery1 = function(test) {
     });
 };
 
-*/
-
 module.exports.testQuery2 = function(test) {
     test.ok(jb);
     test.ok(jb.isOpen());
@@ -90,7 +86,24 @@ module.exports.testQuery2 = function(test) {
             {$orderby : {name : 1}},
             function(err, cursor, count) {
                 test.ifError(err);
-                console.log("count=" + count);
+                test.ok(cursor);
+                test.equal(2, count);
+                for (var c = 0; cursor.next(); ++c) {
+                    var rv = cursor.object();
+                    if (c != 0) continue;
+                    test.equal(rv["name"], "Bounty");
+                    test.equal(cursor.field("name"), "Bounty");
+                    test.equal(rv["type"], "Cockatoo");
+                    test.equal(cursor.field("type"), "Cockatoo");
+                    test.equal(rv["male"], false);
+                    test.equal(cursor.field("male"), false);
+                    test.equal(rv["age"], 15);
+                    test.equal(cursor.field("age"), 15);
+                    test.equal("" + rv["birthdate"], "" + now);
+                    test.equal("" + cursor.field("birthdate"), "" + now);
+                    test.equal(rv["likes"].join(","), "sugar cane");
+                    test.equal(cursor.field("likes").join(","), "sugar cane");
+                }
                 test.done();
             });