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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
|
/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
/* vim: set ft=javascript ts=2 et sw=2 tw=80: */
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
// Tests that code completion works properly.
"use strict";
const TEST_URI = "data:text/html;charset=utf8,<p>test code completion";
var jsterm;
add_task(function* () {
yield loadTab(TEST_URI);
let hud = yield openConsole();
jsterm = hud.jsterm;
let input = jsterm.inputNode;
// Test typing 'docu'.
input.value = "docu";
input.setSelectionRange(4, 4);
yield complete(jsterm.COMPLETE_HINT_ONLY);
is(input.value, "docu", "'docu' completion (input.value)");
is(jsterm.completeNode.value, " ment", "'docu' completion (completeNode)");
// Test typing 'docu' and press tab.
input.value = "docu";
input.setSelectionRange(4, 4);
yield complete(jsterm.COMPLETE_FORWARD);
is(input.value, "document", "'docu' tab completion");
is(input.selectionStart, 8, "start selection is alright");
is(input.selectionEnd, 8, "end selection is alright");
is(jsterm.completeNode.value.replace(/ /g, ""), "", "'docu' completed");
// Test typing 'window.Ob' and press tab. Just 'window.O' is
// ambiguous: could be window.Object, window.Option, etc.
input.value = "window.Ob";
input.setSelectionRange(9, 9);
yield complete(jsterm.COMPLETE_FORWARD);
is(input.value, "window.Object", "'window.Ob' tab completion");
// Test typing 'document.getElem'.
input.value = "document.getElem";
input.setSelectionRange(16, 16);
yield complete(jsterm.COMPLETE_FORWARD);
is(input.value, "document.getElem", "'document.getElem' completion");
is(jsterm.completeNode.value, " entsByTagNameNS",
"'document.getElem' completion");
// Test pressing tab another time.
yield jsterm.complete(jsterm.COMPLETE_FORWARD);
is(input.value, "document.getElem", "'document.getElem' completion");
is(jsterm.completeNode.value, " entsByTagName",
"'document.getElem' another tab completion");
// Test pressing shift_tab.
complete(jsterm.COMPLETE_BACKWARD);
is(input.value, "document.getElem", "'document.getElem' untab completion");
is(jsterm.completeNode.value, " entsByTagNameNS",
"'document.getElem' completion");
jsterm.clearOutput();
input.value = "docu";
yield complete(jsterm.COMPLETE_HINT_ONLY);
is(jsterm.completeNode.value, " ment", "'docu' completion");
yield jsterm.execute();
is(jsterm.completeNode.value, "", "clear completion on execute()");
// Test multi-line completion works
input.value = "console.log('one');\nconsol";
yield complete(jsterm.COMPLETE_HINT_ONLY);
is(jsterm.completeNode.value, " \n e",
"multi-line completion");
// Test non-object autocompletion.
input.value = "Object.name.sl";
yield complete(jsterm.COMPLETE_HINT_ONLY);
is(jsterm.completeNode.value, " ice", "non-object completion");
// Test string literal autocompletion.
input.value = "'Asimov'.sl";
yield complete(jsterm.COMPLETE_HINT_ONLY);
is(jsterm.completeNode.value, " ice", "string literal completion");
jsterm = null;
});
function complete(type) {
let updated = jsterm.once("autocomplete-updated");
jsterm.complete(type);
return updated;
}
|