Need a unique gift idea?
A Pastebin account makes a great Christmas gift
SHARE
TWEET

Untitled

a guest Nov 19th, 2018 74 Never
Upgrade to PRO!
ENDING IN00days00hours00mins00secs
 
  1. var xapian = require('../xapian-binding');
  2. var xapiantesting = require('./testing-xapian');
  3.  
  4. var tests=
  5. [
  6.   {
  7.     name: 'initialize doc',
  8.     fatal: true,
  9.     action: function(objects, sync, fn) { objects.doc = new xapian.Document(); fn(null); }
  10.   },
  11.   {
  12.     name: 'set_data invalid arguments',
  13.     obj: 'doc',
  14.     method: 'set_data',
  15.     parameters: [],
  16.     result: function(err, result, fn) { fn(err == 'arguments are (string, [function])'); }
  17.   },
  18.   {
  19.     name: 'set_data hello world',
  20.     obj: 'doc',
  21.     method: 'set_data',
  22.     parameters: ["hello world"],
  23.     result: function(err, result, fn) { fn(err == null); }
  24.   },
  25.   {
  26.     name: 'get_data',
  27.     obj: 'doc',
  28.     method: 'get_data',
  29.     parameters: [],
  30.     result: function(err, result, fn) { fn(err == null && result == 'hello world'); }
  31.   },
  32.   {
  33.     name: 'add_value fudge',
  34.     obj: 'doc',
  35.     method: 'add_value',
  36.     parameters: [1, "fudge"],
  37.     result: function(err, result, fn) { fn(err == null); }
  38.   },
  39.   {
  40.     name: 'add_value chocolate',
  41.     obj: 'doc',
  42.     method: 'add_value',
  43.     parameters: [2, "chocolate"],
  44.     result: function(err, result, fn) { fn(err == null); }
  45.   },
  46.   {
  47.     name: 'get_value',
  48.     obj: 'doc',
  49.     method: 'get_value',
  50.     parameters: [1],
  51.     result: function(err, result, fn) { fn(err == null && result === 'fudge'); }
  52.   },
  53.   {
  54.     name: 'get_docid',
  55.     obj: 'doc',
  56.     method: 'get_docid',
  57.     parameters: [],
  58.     result: function(err, result, fn) { fn(err == null && result === 0); }
  59.   },
  60. /*
  61. my $it = $doc->values_begin();
  62. ok( $it ne $doc->values_end() );
  63. ok( "$it" eq "fudge" );
  64. ok( $it->get_value() eq "fudge" );
  65. ok( $it->get_valueno() == 1 );
  66. ++$it;
  67. ok( $it ne $doc->values_end() );
  68. ok( "$it" eq "chocolate" );
  69. ok( $it->get_value() eq "chocolate" );
  70. ok( $it->get_valueno() == 2 );
  71. ++$it;
  72. ok( $it eq $doc->values_end() );
  73. */
  74.   {
  75.     name: 'remove_value',
  76.     obj: 'doc',
  77.     method: 'remove_value',
  78.     parameters: [1],
  79.     result: function(err, result, fn) { fn(err == null); }
  80.   },
  81.   {
  82.     name: 'initialize empty database',
  83.     fatal: true,
  84.     action: function(objects, sync, fn) {
  85.       if (sync) {
  86.         objects.db = new xapian.WritableDatabase('tmptestdb', xapian.DB_CREATE_OR_OVERWRITE);
  87.         fn(null);
  88.       } else {
  89.         new xapian.WritableDatabase('tmptestdb', xapian.DB_CREATE_OR_OVERWRITE, function(err, result) {
  90.           if (err) fn(err);
  91.           else  {
  92.             objects.db = result;
  93.             fn(null);
  94.           }
  95.         });
  96.       }
  97.     }
  98.   },
  99.   {
  100.     name: 'add_document',
  101.     fatal: false,
  102.     action: function(objects, sync, fn) { objects.db.add_document(objects.doc); fn(null); }
  103.   },
  104. ]
  105.  
  106. xapiantesting.runTests('Document basics', tests, true);
  107.  
  108. /*
  109. ok( $doc->get_value(1) eq "" );
  110. ok( $doc->get_value(2) eq "chocolate" );
  111. $doc->clear_values();
  112. ok( $doc->get_value(2) eq "" );
  113.  
  114. my $database = Search::Xapian::WritableDatabase->new();
  115.  
  116. # in <= 0.8.3.0 this added with wdfinc 1
  117. $doc->add_posting( "hello", 1, 100 );
  118. # in <= 0.8.3.0 this added with wdfinc 0
  119. $doc->add_posting( "hello", 2 );
  120. $database->add_document($doc);
  121.  
  122. ok( $database->get_doclength(1) == 101 );
  123.  
  124. $doc = Search::Xapian::Document->new();
  125. # in <= 0.8.3.0 this added with wdfinc 1 (happens to work as it should)
  126. $doc->add_posting( "goodbye", 1, 1 );
  127. # in <= 0.8.3.0 this added with wdfinc 1 (happens to work as it should)
  128. $doc->add_posting( "goodbye", 2, 1 );
  129. # in <= 0.8.3.0 this removed with wdfinc 0
  130. $doc->remove_posting( "goodbye", 2 );
  131. $database->add_document($doc);
  132.  
  133. ok( $database->get_doclength(2) == 1 );
  134.  
  135. $doc = Search::Xapian::Document->new();
  136. # in <= 0.8.3.0 this added with wdfinc 1
  137. $doc->add_term( "a", 100 );
  138. # in <= 0.8.3.0 this added with wdfinc 0
  139. $doc->add_term( "a" );
  140. $database->add_document($doc);
  141.  
  142. ok( $database->get_doclength(3) == 101 );
  143.  
  144. ok( $it = $doc->termlist_begin());
  145. ok( $it ne $doc->termlist_end());
  146. ok( "$it" eq "a" );
  147. ok( $it->get_termname() eq "a" );
  148. ++$it;
  149. ok( $it eq $doc->termlist_end());
  150.  
  151. $doc->add_boolean_term( "b" );
  152. $database->add_document($doc);
  153.  
  154. ok( $database->get_doclength(4) == 101 );
  155.  
  156. $doc->remove_term( "a" );
  157. $database->add_document($doc);
  158.  
  159. ok( $database->get_doclength(5) == 0 );
  160. */
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top