1 |
|
2 | 'use strict';
|
3 |
|
4 | var test = require('tap').test
|
5 | , completeAppend = require('../lib/complete-append')
|
6 | , config = require('../config/current')
|
7 |
|
8 | config.feed.format = {
|
9 | indent : { style: ' ', base: 0 }
|
10 | , quotes : 'single'
|
11 | , json : false
|
12 | , renumber : false
|
13 | , hexadecimal : false
|
14 | , escapeless : false
|
15 | , compact : true
|
16 | , parentheses : false
|
17 | , semicolons : true
|
18 | };
|
19 |
|
20 | test('\nhandles no history case', function (t) {
|
21 | var history = []
|
22 | , append = completeAppend(history)
|
23 |
|
24 | t.equal(append, null, 'returns null')
|
25 | t.end()
|
26 | })
|
27 |
|
28 | test('\nhandles command only case', function (t) {
|
29 | var history = [' .append ']
|
30 | , append = completeAppend(history)
|
31 |
|
32 | t.equal(append, null, 'returns null')
|
33 | t.end()
|
34 | })
|
35 |
|
36 | test('\nappends first expression before command', function (t) {
|
37 | var history = [
|
38 | '2 + 3'
|
39 | , 'var a = true;'
|
40 | , '.append'
|
41 | ].reverse()
|
42 | , expected = '\nvar a = true;\n'
|
43 | , append = completeAppend(history)
|
44 |
|
45 | t.equal(append.raw, expected, 'gets raw')
|
46 | t.notEqual(append.raw, append.highlighted, 'gets highlighted')
|
47 | t.end()
|
48 | })
|
49 |
|
50 | test('\nappends multiline function before commands', function (t) {
|
51 | var history = [
|
52 | 'function foo() {'
|
53 | , ' var a = 2;'
|
54 | , ' return a + 1;'
|
55 | , '}'
|
56 | , ' .clear '
|
57 | , '.append'
|
58 | ].reverse()
|
59 |
|
60 | , expected = '\nfunction foo() {\n var a = 2;\n return a + 1;\n}\n'
|
61 | , append = completeAppend(history)
|
62 |
|
63 | t.equal(append.raw, expected, 'gets raw')
|
64 | t.notEqual(append.raw, append.highlighted, 'gets highlighted')
|
65 | t.end()
|
66 | })
|
67 |
|
68 | test('\ncompletes 3 line function at end of history', function (t) {
|
69 | var history = [
|
70 | '1'
|
71 | , '2'
|
72 | , 'function foo() {'
|
73 | , ' var a = 2;'
|
74 | , ' return a + 1;'
|
75 | , '}'
|
76 | ].reverse()
|
77 | , expected = '\nfunction foo() {\n var a = 2;\n return a + 1;\n}\n'
|
78 | , append = completeAppend(history)
|
79 |
|
80 | t.equal(append.raw, expected, 'gets raw')
|
81 | t.notEqual(append.raw, append.highlighted, 'gets highlighted')
|
82 | t.end()
|
83 | })
|
84 |
|
85 | test('\ncompletes 3 line function at end of history that are badly formatted in a better formatted way', function (t) {
|
86 | var history = [
|
87 | '1'
|
88 | , '2'
|
89 | , 'function foo() {'
|
90 | , 'var a = 2;'
|
91 | , ' return a + 1;'
|
92 | , '}'
|
93 | ].reverse()
|
94 | , expected = '\nfunction foo() {\n var a = 2;\n return a + 1;\n}\n'
|
95 | , append = completeAppend(history)
|
96 |
|
97 | t.equal(append.raw, expected, 'gets raw')
|
98 | t.notEqual(append.raw, append.highlighted, 'gets highlighted')
|
99 | t.end()
|
100 | })
|
101 |
|
102 | test('\ndoes not complete incomplete function at end of history', function (t) {
|
103 | var history = [
|
104 | ' var a = 2;'
|
105 | , ' return a + 1;'
|
106 | , '}'
|
107 | ].reverse()
|
108 | , expected = '\n}\n'
|
109 | , append = completeAppend(history)
|
110 |
|
111 | t.equal(append.raw, expected, 'gets raw')
|
112 | t.equal(append.raw, append.highlighted, 'does not highlight')
|
113 | t.end()
|
114 | })
|
115 |
|
116 | test('\ncompletes 2 + 3 at end of history', function (t) {
|
117 | var history = [
|
118 | '3 + 4'
|
119 | , '2 + 3'
|
120 | ].reverse()
|
121 | , expected = '\n2 + 3;\n'
|
122 | , append = completeAppend(history)
|
123 |
|
124 | t.equal(append.raw, expected, 'gets raw')
|
125 | t.notEqual(append.raw, append.highlighted, 'gets highlighted')
|
126 | t.end()
|
127 | })
|
128 |
|
129 | test('\ncompletes var a = true; at end of history with complete function right before', function (t) {
|
130 | var history = [
|
131 | 'function foo () {'
|
132 | , ' var a = 2;'
|
133 | , ' return a + 1;'
|
134 | , '}'
|
135 | , 'var a = true;'
|
136 | ].reverse()
|
137 | , expected = '\nvar a = true;\n'
|
138 | , append = completeAppend(history)
|
139 |
|
140 | t.equal(append.raw, expected, 'gets raw')
|
141 | t.notEqual(append.raw, append.highlighted, 'gets highlighted')
|
142 | t.end()
|
143 | })
|
144 |
|
145 | test('\ndoes not complete "var a =" at end of history with complete function right before', function (t) {
|
146 | var history = [
|
147 | 'function foo () {'
|
148 | , ' var a = 2;'
|
149 | , ' return a + 1;'
|
150 | , '}'
|
151 | , 'var a ='
|
152 | ].reverse()
|
153 | , expected = '\nvar a =\n'
|
154 | , append = completeAppend(history)
|
155 |
|
156 | t.equal(append.raw, expected, 'gets raw')
|
157 | t.equal(append.raw, append.highlighted, 'does not highlight')
|
158 | t.end()
|
159 | })
|
160 |
|
161 | test('\ncompletes 2 + 3 close to end whan .append is at end of history, thus ignoring .append', function (t) {
|
162 | var history = [
|
163 | '2 + 3'
|
164 | , '.append'
|
165 | ].reverse()
|
166 | , expected = '\n2 + 3;\n'
|
167 | , append = completeAppend(history)
|
168 |
|
169 | t.equal(append.raw, expected, 'gets raw')
|
170 | t.notEqual(append.raw, append.highlighted, 'gets highlighted')
|
171 | t.end()
|
172 | })
|