summaryrefslogtreecommitdiff
path: root/jstests/core/autocomplete.js
blob: 6511292a8d3114886825aaeaffa1b7e0527faeaf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/**
 * Validate auto complete works for various javascript types implemented by C++.
 */
(function() {
    'use strict';

    function testAutoComplete(prefix) {
        // This method updates a global object with an array of strings on success.
        shellAutocomplete(prefix);
        return __autocomplete__;
    }

    // Create a collection.
    db.auto_complete_coll.insert({});

    // Validate DB auto completion.
    const db_stuff = testAutoComplete('db.');

    // Verify we enumerate built-in methods.
    assert.contains('db.prototype', db_stuff);
    assert.contains('db.hasOwnProperty', db_stuff);
    assert.contains('db.toString(', db_stuff);

    // Verify we have some methods we added.
    assert.contains('db.adminCommand(', db_stuff);
    assert.contains('db.runCommand(', db_stuff);

    // Verify we enumerate collections.
    assert.contains('db.auto_complete_coll', db_stuff);

    // Validate Collection autocompletion.
    const coll_stuff = testAutoComplete('db.auto_complete_coll.');

    // Verify we enumerate built-in methods.
    assert.contains('db.auto_complete_coll.prototype', coll_stuff);
    assert.contains('db.auto_complete_coll.hasOwnProperty', coll_stuff);
    assert.contains('db.auto_complete_coll.toString(', coll_stuff);

    // Verify we have some methods we added.
    assert.contains('db.auto_complete_coll.aggregate(', coll_stuff);
    assert.contains('db.auto_complete_coll.runCommand(', coll_stuff);

    // Validate autocompletion when prefix is specified.
    const empty_stuff = testAutoComplete('');

    assert.contains('Array(', empty_stuff);
    assert.contains('print(', empty_stuff);
    assert.contains('ErrorCodes', empty_stuff);

    // Validate autocompletion returns ErrorCodes when ErrorCodes is specified.
    const error_codes_autocomplete = testAutoComplete('ErrorCodes.');

    assert.contains('ErrorCodes.BadValue', error_codes_autocomplete);
})();