Example #1
0
        it("returns false if neither matcher matches", function () {
            var numberOrAbc = sinonMatch.number.or("abc");

            assert.isFalse(numberOrAbc.test(/.+/));
            assert.isFalse(numberOrAbc.test(new Date()));
            assert.isFalse(numberOrAbc.test({}));
        });
Example #2
0
    it("returns false for string mismatch", function () {
        var match = sinonMatch("Sinon.JS");

        assert.isFalse(match.test(null));
        assert.isFalse(match.test({}));
        assert.isFalse(match.test("sinon"));
        assert.isFalse(match.test("sinon.js"));
    });
Example #3
0
    it("returns false for regexp type mismatch", function () {
        var match = sinonMatch(/.*/);

        assert.isFalse(match.test());
        assert.isFalse(match.test(null));
        assert.isFalse(match.test(123));
        assert.isFalse(match.test({}));
    });
Example #4
0
    it("returns false for number mismatch", function () {
        var match = sinonMatch(1);

        assert.isFalse(match.test());
        assert.isFalse(match.test(null));
        assert.isFalse(match.test(2));
        assert.isFalse(match.test(false));
        assert.isFalse(match.test({}));
    });
Example #5
0
    it("returns false for Symbol mismatch", function () {
        if (typeof Symbol === "function") {
            var match = sinonMatch(Symbol());

            assert.isFalse(match.test());
            assert.isFalse(match.test(Symbol(null)));
            assert.isFalse(match.test(Symbol()));
            assert.isFalse(match.test(Symbol({})));
        }
    });
Example #6
0
    it("returns false if test function in object returns false", function () {
        var match = sinonMatch({ test: function () {
            return false;
        }});

        assert.isFalse(match.test());
    });
Example #7
0
 this.verify = function (ws, db, done, data) {
   if (!data) data = this.sourceData // can pass alternative data array for verification
   assert.isFalse(ws.writable)
   assert.isFalse(ws.readable)
   async.forEach(
       data
     , function (data, callback) {
         db.get(data.key, function (err, value) {
           refute(err)
           assert.equals(+value, +data.value, 'WriteStream data #' + data.key + ' has correct value')
           callback()
         })
       }
     , done
   )
 }
 this.verify = function (rs, data, done) {
   assert.isFalse(rs.writable)
   assert.isFalse(rs.readable)
   assert.equals(this.readySpy.callCount, 1, 'Stream emitted single "ready" event')
   assert.equals(this.endSpy.callCount, 1, 'Stream emitted single "end" event')
   assert.equals(this.dataSpy.callCount, data.length, 'Stream emitted correct number of "data" events')
   data.forEach(function (d, i) {
     var call = this.dataSpy.getCall(i)
     if (call) {
       //console.log('call', i, ':', call.args[0].key, '=', call.args[0].value, '(expected', d.key, '=', d.value, ')')
       assert.equals(call.args.length, 1, 'Stream "data" event #' + i + ' fired with 1 argument')
       assert.equals(+call.args[0].toString(), +d, 'Stream correct "data" event #' + i + ': ' + d)
     }
   }.bind(this))
   done()
 }.bind(this)
Example #9
0
 this.openTestDatabase(function (db) {
   var ws = db.createWriteStream()
   ws.on('error', function (err) {
     refute(err)
   })
   assert.isTrue(ws.writable)
   assert.isFalse(ws.readable)
   ws.on('close', verify.bind(this, ws, db))
   this.sourceData.forEach(function (d) {
     ws.write(d)
     assert.isTrue(ws.writable)
     assert.isFalse(ws.readable)
   })
   assert.isTrue(ws.writable)
   assert.isFalse(ws.readable)
   ws.once('ready', ws.destroy)
 }.bind(this))
Example #10
0
      db.close(function () {
        assert.isFalse(db.isOpen())

        levelup(this.cleanupDirs[0], { errorIfExists: false }, function (err, db) {
          refute(err)
          this.closeableDatabases.push(db)
          assert.isTrue(db.isOpen())
          done()
        }.bind(this))
      }.bind(this))
Example #11
0
                it("fails when maps contain the same keys but different values", function () {
                    var mapOne = new Map();
                    mapOne.set("one", 1);
                    mapOne.set("two", 2);
                    mapOne.set("three", 3);

                    var mapTwo = new Map();
                    mapTwo.set("one", 2);
                    mapTwo.set("two", 4);
                    mapTwo.set("three", 8);

                    var mapThree = new Map();
                    mapThree.set("one", 1);
                    mapThree.set("two", 2);
                    mapThree.set("three", 4);

                    assert.isFalse(sinonMatch.map.contains(mapTwo).test(mapOne));
                    assert.isFalse(sinonMatch.map.contains(mapThree).test(mapOne));
                });
Example #12
0
                it("matches sets with the exact same elements", function () {
                    var setOne = new Set();
                    setOne.add("one");
                    setOne.add("two");
                    setOne.add("three");

                    var setTwo = new Set();
                    setTwo.add("one");
                    setTwo.add("two");
                    setTwo.add("three");

                    var setThree = new Set();
                    setThree.add("one");
                    setThree.add("two");

                    var deepEquals = sinonMatch.set.deepEquals(setOne);
                    assert(deepEquals.test(setTwo));
                    assert.isFalse(deepEquals.test(setThree));
                    assert.isFalse(deepEquals.test(new Set()));
                });
Example #13
0
                it("matches maps with the exact same elements", function () {
                    var mapOne = new Map();
                    mapOne.set("one", 1);
                    mapOne.set("two", 2);
                    mapOne.set("three", 3);

                    var mapTwo = new Map();
                    mapTwo.set("one", 1);
                    mapTwo.set("two", 2);
                    mapTwo.set("three", 3);

                    var mapThree = new Map();
                    mapThree.set("one", 1);
                    mapThree.set("two", 2);

                    var deepEquals = sinonMatch.map.deepEquals(mapOne);
                    assert(deepEquals.test(mapTwo));
                    assert.isFalse(deepEquals.test(mapThree));
                    assert.isFalse(deepEquals.test(new Map()));
                });
        db.batch(this.sourceData.slice(), function (err) {
          refute(err)

          var rs = db.valueStream()
          assert.isFalse(rs.writable)
          assert.isTrue(rs.readable)
          rs.on('ready', this.readySpy)
          rs.on('data', this.dataSpy)
          rs.on('end', this.endSpy)
          rs.on('close', this.verify.bind(this, rs, this.sourceValues, done))
        }.bind(this))
Example #15
0
                it("fails when maps have the same keys but different values", function () {
                    var mapOne = new Map();
                    mapOne.set("one", 1);
                    mapOne.set("two", 2);
                    mapOne.set("three", 3);

                    var mapTwo = new Map();
                    mapTwo.set("one", 2);
                    mapTwo.set("two", 4);
                    mapTwo.set("three", 8);

                    var mapThree = new Map();
                    mapTwo.set("one", 1);
                    mapTwo.set("two", 2);
                    mapTwo.set("three", 4);

                    var deepEquals = sinonMatch.map.deepEquals(mapOne);
                    assert.isFalse(deepEquals.test(mapTwo));
                    assert.isFalse(deepEquals.test(mapThree));
                });
Example #16
0
        levelup(location, function (err, db) { // no options object
          refute(err)
          assert.isObject(db)
          assert.isTrue(db.options.createIfMissing)
          assert.isFalse(db.options.errorIfExists)
          assert.equals(db.options.keyEncoding, 'utf8')
          assert.equals(db.options.valueEncoding, 'utf8')
          assert.equals(db.location, location)

            // read-only properties
          db.location = 'foo'
          assert.equals(db.location, location)

          done()
        })
Example #17
0
 var verify = function (ws, db) {
   assert.isFalse(ws.writable)
   async.forEach(
       this.sourceData
     , function (data, callback) {
         db.get(data.key, function (err, value) {
           // none of them should exist
           assert(err)
           refute(value)
           callback()
         })
       }
     , done
   )
 }
Example #18
0
        db.batch(this.sourceData.slice(), function (err) {
          refute(err)

          // 2) Create an iterator on the current data, pipe it through a SlowStream
          //    to make *sure* that we're going to be reading it for longer than it
          //    takes to overwrite the data in there.

          var rs = db.readStream()
          assert.isFalse(rs.writable)
          assert.isTrue(rs.readable)
          rs = rs.pipe(new SlowStream({ maxWriteInterval: 5 }))
          rs.on('data' , this.dataSpy)
          rs.once('end'  , this.endSpy)
          rs.on('end', function () {
            rs.readable = false
            rs.writable = false
          })

          rs.once('close', delayed.delayed(this.verify.bind(this, rs, done), 0.05))

          process.nextTick(function () {
            // 3) Concoct and write new random data over the top of existing items.
            //    If we're not using a snapshot then then we'd expect the test
            //    to fail because it'll pick up these new values rather than the
            //    old ones.
            var newData = []
              , i
              , k

            for (i = 0; i < 100; i++) {
              k = (i < 10 ? '0' : '') + i
              newData.push({
                  type  : 'put'
                , key   : k
                , value : Math.random()
              })
            }
            // using sync:true here to ensure it's written fully to disk
            db.batch(newData.slice(), { sync: true }, function (err) {
              refute(err)
              // we'll return here faster than it takes the readStream to complete
            })
          }.bind(this))
        }.bind(this))
Example #19
0
                it("matches maps containing the given elements", function () {
                    var mapOne = new Map();
                    mapOne.set("one", 1);
                    mapOne.set("two", 2);
                    mapOne.set("three", 3);

                    var mapTwo = new Map();
                    mapTwo.set("one", 1);
                    mapTwo.set("two", 2);
                    mapTwo.set("three", 3);

                    var mapThree = new Map();
                    mapThree.set("one", 1);
                    mapThree.set("two", 2);

                    var mapFour = new Map();
                    mapFour.set("one", 1);
                    mapFour.set("four", 4);

                    assert(sinonMatch.map.contains(mapTwo).test(mapOne));
                    assert(sinonMatch.map.contains(mapThree).test(mapOne));
                    assert.isFalse(sinonMatch.map.contains(mapFour).test(mapOne));
                });
Example #20
0
                it("matches sets containing the given elements", function () {
                    var setOne = new Set();
                    setOne.add("one");
                    setOne.add("two");
                    setOne.add("three");

                    var setTwo = new Set();
                    setTwo.add("one");
                    setTwo.add("two");
                    setTwo.add("three");

                    var setThree = new Set();
                    setThree.add("one");
                    setThree.add("two");

                    var setFour = new Set();
                    setFour.add("one");
                    setFour.add("four");

                    assert(sinonMatch.set.contains(setTwo).test(setOne));
                    assert(sinonMatch.set.contains(setThree).test(setOne));
                    assert.isFalse(sinonMatch.set.contains(setFour).test(setOne));
                });
Example #21
0
 it("matches arrays ending with the same elements", function () {
     assert(sinonMatch.array.endsWith([2]).test([1, 2]));
     assert(sinonMatch.array.endsWith([1, 2]).test([1, 2]));
     assert.isFalse(sinonMatch.array.endsWith([1, 2, 3]).test([1, 2]));
     assert.isFalse(sinonMatch.array.endsWith([3]).test([1, 2]));
 });
Example #22
0
        it("allows to expect undefined", function () {
            var has = matcher("foo", undefined);

            assert.isFalse(has.test({ foo: 1 }));
        });
Example #23
0
 it("fails when passed a non-set object", function () {
     var contains = sinonMatch.set.contains(new Set());
     assert.isFalse(contains.test({}));
     assert.isFalse(contains.test([]));
 });
Example #24
0
 it("fails when passed a non-set object", function () {
     var deepEquals = sinonMatch.array.deepEquals(new Set());
     assert.isFalse(deepEquals.test({}));
     assert.isFalse(deepEquals.test([]));
 });
Example #25
0
        it("returns false if object has inherited property", function () {
            var hasOwn = sinonMatch.hasOwn("toString");

            assert.isFalse(hasOwn.test({}));
        });
Example #26
0
 it("fails when passed a non-map object", function () {
     var contains = sinonMatch.map.contains(new Map());
     assert.isFalse(contains.test({}));
     assert.isFalse(contains.test([]));
 });
Example #27
0
 it("matches arrays with the exact same elements", function () {
     var deepEquals = sinonMatch.array.deepEquals([1, 2, 3]);
     assert(deepEquals.test([1, 2, 3]));
     assert.isFalse(deepEquals.test([1, 2]));
     assert.isFalse(deepEquals.test([3]));
 });
Example #28
0
            it("fails when passed a non-array object", function () {
                var endsWith = sinonMatch.array.endsWith(["two", "three"]);

                assert.isFalse(endsWith.test({0: "one", 1: "two", 2: "three", length: 3}));
            });
Example #29
0
 it("matches arrays containing all the expected elements", function () {
     assert(sinonMatch.array.contains([2]).test([1, 2, 3]));
     assert(sinonMatch.array.contains([1, 2]).test([1, 2]));
     assert.isFalse(sinonMatch.array.contains([1, 2, 3]).test([1, 2]));
     assert.isFalse(sinonMatch.array.contains([3]).test([1, 2]));
 });
Example #30
0
            it("fails when passed a non-array object", function () {
                var contains = sinonMatch.array.contains(["one", "three"]);

                assert.isFalse(contains.test({0: "one", 1: "two", 2: "three", length: 3}));
            });