CursorDocumentSource.js 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. var assert = require("assert"),
  2. CursorDocumentSource = require("../../../../lib/pipeline/documentsources/CursorDocumentSource"),
  3. Cursor = require("../../../../lib/Cursor");
  4. module.exports = {
  5. "CursorDocumentSource": {
  6. "constructor(data)": {
  7. "should fail if CursorWithContext is not provided": function(){
  8. assert.throws(function(){
  9. var cds = new CursorDocumentSource();
  10. });
  11. },
  12. "should get a accept a CursorWithContext and set it internally": function(){
  13. var cwc = new CursorDocumentSource.CursorWithContext();
  14. cwc._cursor = new Cursor( [] );
  15. var cds = new CursorDocumentSource(cwc);
  16. assert.ok(cds._cursorWithContext);
  17. }
  18. },
  19. "#eof": {
  20. "should return true if the cursor is empty": function(){
  21. var cwc = new CursorDocumentSource.CursorWithContext();
  22. cwc._cursor = new Cursor( [] );
  23. var cds = new CursorDocumentSource(cwc);
  24. assert.equal(cds.eof(), true);
  25. },
  26. "should return false if the cursor is non-empty": function(){
  27. var cwc = new CursorDocumentSource.CursorWithContext();
  28. cwc._cursor = new Cursor( [1,2,3] );
  29. var cds = new CursorDocumentSource(cwc);
  30. assert.equal(cds.eof(), false);
  31. }
  32. },
  33. "#advance": {
  34. "should return true if the cursor was advanced": function(){
  35. var cwc = new CursorDocumentSource.CursorWithContext();
  36. cwc._cursor = new Cursor( [1,2,3] );
  37. var cds = new CursorDocumentSource(cwc);
  38. assert.equal(cds.advance(), true);
  39. },
  40. "should return false if the cursor is empty": function(){
  41. var cwc = new CursorDocumentSource.CursorWithContext();
  42. cwc._cursor = new Cursor( [1,2,3] );
  43. var cds = new CursorDocumentSource(cwc);
  44. cds.advance();cds.advance();cds.advance();
  45. assert.equal(cds.advance(), false);
  46. }
  47. },
  48. "#getCurrent": {
  49. "should return the current cursor value": function(){
  50. var cwc = new CursorDocumentSource.CursorWithContext();
  51. cwc._cursor = new Cursor( [1,2,3,4] );
  52. var cds = new CursorDocumentSource(cwc);
  53. assert.equal(cds.getCurrent(), 1);
  54. cds.advance();
  55. assert.equal(cds.getCurrent(), 2);
  56. cds.advance();
  57. assert.equal(cds.getCurrent(), 3);
  58. cds.advance();
  59. assert.equal(cds.getCurrent(), 4);
  60. cds.advance();
  61. assert.equal(cds.getCurrent(), undefined);
  62. }
  63. },
  64. "#dispose": {
  65. "should empty the current cursor": function(){
  66. var cwc = new CursorDocumentSource.CursorWithContext();
  67. cwc._cursor = new Cursor( [1,2,3] );
  68. var cds = new CursorDocumentSource(cwc);
  69. assert.equal(cds.getCurrent(), 1);
  70. cds.advance();
  71. assert.equal(cds.getCurrent(), 2);
  72. cds.dispose();
  73. assert.equal(cds.advance(), false);
  74. assert.equal(cds.eof(), true);
  75. }
  76. }
  77. }
  78. };
  79. if (!module.parent)(new(require("mocha"))()).ui("exports").reporter("spec").addFile(__filename).run();