Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var xapian = require('../xapian-binding');
- var xapiantesting = require('./testing-xapian');
- var tests=
- [
- {
- name: 'initialize doc',
- fatal: true,
- action: function(objects, sync, fn) { objects.doc = new xapian.Document(); fn(null); }
- },
- {
- name: 'set_data invalid arguments',
- obj: 'doc',
- method: 'set_data',
- parameters: [],
- result: function(err, result, fn) { fn(err == 'arguments are (string, [function])'); }
- },
- {
- name: 'set_data hello world',
- obj: 'doc',
- method: 'set_data',
- parameters: ["hello world"],
- result: function(err, result, fn) { fn(err == null); }
- },
- {
- name: 'get_data',
- obj: 'doc',
- method: 'get_data',
- parameters: [],
- result: function(err, result, fn) { fn(err == null && result == 'hello world'); }
- },
- {
- name: 'add_value fudge',
- obj: 'doc',
- method: 'add_value',
- parameters: [1, "fudge"],
- result: function(err, result, fn) { fn(err == null); }
- },
- {
- name: 'add_value chocolate',
- obj: 'doc',
- method: 'add_value',
- parameters: [2, "chocolate"],
- result: function(err, result, fn) { fn(err == null); }
- },
- {
- name: 'get_value',
- obj: 'doc',
- method: 'get_value',
- parameters: [1],
- result: function(err, result, fn) { fn(err == null && result === 'fudge'); }
- },
- {
- name: 'get_docid',
- obj: 'doc',
- method: 'get_docid',
- parameters: [],
- result: function(err, result, fn) { fn(err == null && result === 0); }
- },
- /*
- my $it = $doc->values_begin();
- ok( $it ne $doc->values_end() );
- ok( "$it" eq "fudge" );
- ok( $it->get_value() eq "fudge" );
- ok( $it->get_valueno() == 1 );
- ++$it;
- ok( $it ne $doc->values_end() );
- ok( "$it" eq "chocolate" );
- ok( $it->get_value() eq "chocolate" );
- ok( $it->get_valueno() == 2 );
- ++$it;
- ok( $it eq $doc->values_end() );
- */
- {
- name: 'remove_value',
- obj: 'doc',
- method: 'remove_value',
- parameters: [1],
- result: function(err, result, fn) { fn(err == null); }
- },
- {
- name: 'initialize empty database',
- fatal: true,
- action: function(objects, sync, fn) {
- if (sync) {
- objects.db = new xapian.WritableDatabase('tmptestdb', xapian.DB_CREATE_OR_OVERWRITE);
- fn(null);
- } else {
- new xapian.WritableDatabase('tmptestdb', xapian.DB_CREATE_OR_OVERWRITE, function(err, result) {
- if (err) fn(err);
- else {
- objects.db = result;
- fn(null);
- }
- });
- }
- }
- },
- {
- name: 'add_document',
- fatal: false,
- action: function(objects, sync, fn) { objects.db.add_document(objects.doc); fn(null); }
- },
- ]
- xapiantesting.runTests('Document basics', tests, true);
- /*
- ok( $doc->get_value(1) eq "" );
- ok( $doc->get_value(2) eq "chocolate" );
- $doc->clear_values();
- ok( $doc->get_value(2) eq "" );
- my $database = Search::Xapian::WritableDatabase->new();
- # in <= 0.8.3.0 this added with wdfinc 1
- $doc->add_posting( "hello", 1, 100 );
- # in <= 0.8.3.0 this added with wdfinc 0
- $doc->add_posting( "hello", 2 );
- $database->add_document($doc);
- ok( $database->get_doclength(1) == 101 );
- $doc = Search::Xapian::Document->new();
- # in <= 0.8.3.0 this added with wdfinc 1 (happens to work as it should)
- $doc->add_posting( "goodbye", 1, 1 );
- # in <= 0.8.3.0 this added with wdfinc 1 (happens to work as it should)
- $doc->add_posting( "goodbye", 2, 1 );
- # in <= 0.8.3.0 this removed with wdfinc 0
- $doc->remove_posting( "goodbye", 2 );
- $database->add_document($doc);
- ok( $database->get_doclength(2) == 1 );
- $doc = Search::Xapian::Document->new();
- # in <= 0.8.3.0 this added with wdfinc 1
- $doc->add_term( "a", 100 );
- # in <= 0.8.3.0 this added with wdfinc 0
- $doc->add_term( "a" );
- $database->add_document($doc);
- ok( $database->get_doclength(3) == 101 );
- ok( $it = $doc->termlist_begin());
- ok( $it ne $doc->termlist_end());
- ok( "$it" eq "a" );
- ok( $it->get_termname() eq "a" );
- ++$it;
- ok( $it eq $doc->termlist_end());
- $doc->add_boolean_term( "b" );
- $database->add_document($doc);
- ok( $database->get_doclength(4) == 101 );
- $doc->remove_term( "a" );
- $database->add_document($doc);
- ok( $database->get_doclength(5) == 0 );
- */
Add Comment
Please, Sign In to add comment