react 0.7.1 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (203) hide show
  1. package/README.md +15 -228
  2. package/ReactJSErrors.js +40 -0
  3. package/addons.js +4 -0
  4. package/lib/$.js +46 -0
  5. package/lib/CSSCore.js +114 -0
  6. package/lib/CSSProperty.js +90 -0
  7. package/lib/CSSPropertyOperations.js +97 -0
  8. package/lib/CallbackRegistry.js +91 -0
  9. package/lib/ChangeEventPlugin.js +365 -0
  10. package/lib/CompositionEventPlugin.js +212 -0
  11. package/lib/DOMChildrenOperations.js +135 -0
  12. package/lib/DOMProperty.js +266 -0
  13. package/lib/DOMPropertyOperations.js +168 -0
  14. package/lib/Danger.js +186 -0
  15. package/lib/DefaultDOMPropertyConfig.js +187 -0
  16. package/lib/DefaultEventPluginOrder.js +44 -0
  17. package/lib/EnterLeaveEventPlugin.js +112 -0
  18. package/lib/EventConstants.js +73 -0
  19. package/lib/EventListener.js +61 -0
  20. package/lib/EventPluginHub.js +190 -0
  21. package/lib/EventPluginRegistry.js +237 -0
  22. package/lib/EventPluginUtils.js +185 -0
  23. package/lib/EventPropagators.js +179 -0
  24. package/lib/ExecutionEnvironment.js +41 -0
  25. package/lib/LinkedStateMixin.js +46 -0
  26. package/lib/LinkedValueMixin.js +68 -0
  27. package/lib/MobileSafariClickEventPlugin.js +63 -0
  28. package/lib/PooledClass.js +113 -0
  29. package/lib/React.js +71 -0
  30. package/lib/ReactChildren.js +132 -0
  31. package/lib/ReactComponent.js +515 -0
  32. package/lib/ReactComponentBrowserEnvironment.js +140 -0
  33. package/lib/ReactComponentEnvironment.js +24 -0
  34. package/lib/ReactCompositeComponent.js +1020 -0
  35. package/lib/ReactCurrentOwner.js +39 -0
  36. package/lib/ReactDOM.js +194 -0
  37. package/lib/ReactDOMButton.js +64 -0
  38. package/lib/ReactDOMComponent.js +374 -0
  39. package/lib/ReactDOMForm.js +52 -0
  40. package/lib/ReactDOMIDOperations.js +173 -0
  41. package/lib/ReactDOMInput.js +169 -0
  42. package/lib/ReactDOMOption.js +50 -0
  43. package/lib/ReactDOMSelect.js +160 -0
  44. package/lib/ReactDOMSelection.js +189 -0
  45. package/lib/ReactDOMTextarea.js +136 -0
  46. package/lib/ReactDefaultBatchingStrategy.js +75 -0
  47. package/lib/ReactDefaultInjection.js +91 -0
  48. package/lib/ReactDefaultPerf.js +407 -0
  49. package/lib/ReactErrorUtils.js +46 -0
  50. package/lib/ReactEventEmitter.js +341 -0
  51. package/lib/ReactEventEmitterMixin.js +89 -0
  52. package/lib/ReactEventTopLevelCallback.js +89 -0
  53. package/lib/ReactInputSelection.js +140 -0
  54. package/lib/ReactInstanceHandles.js +322 -0
  55. package/lib/ReactLink.js +54 -0
  56. package/lib/ReactMarkupChecksum.js +53 -0
  57. package/lib/ReactMount.js +617 -0
  58. package/lib/ReactMountReady.js +95 -0
  59. package/lib/ReactMultiChild.js +441 -0
  60. package/lib/ReactMultiChildUpdateTypes.js +36 -0
  61. package/lib/ReactOwner.js +146 -0
  62. package/lib/ReactPerf.js +88 -0
  63. package/lib/ReactPropTransferer.js +128 -0
  64. package/lib/ReactPropTypes.js +158 -0
  65. package/lib/ReactReconcileTransaction.js +161 -0
  66. package/lib/ReactServerRendering.js +62 -0
  67. package/lib/ReactStateSetters.js +111 -0
  68. package/lib/ReactTextComponent.js +94 -0
  69. package/lib/ReactTransitionEvents.js +97 -0
  70. package/lib/ReactTransitionGroup.js +112 -0
  71. package/lib/ReactTransitionKeySet.js +111 -0
  72. package/lib/ReactTransitionableChild.js +152 -0
  73. package/lib/ReactUpdates.js +145 -0
  74. package/lib/ReactWithAddons.js +41 -0
  75. package/lib/SelectEventPlugin.js +217 -0
  76. package/lib/SimpleEventPlugin.js +365 -0
  77. package/lib/SyntheticClipboardEvent.js +45 -0
  78. package/lib/SyntheticCompositionEvent.js +51 -0
  79. package/lib/SyntheticEvent.js +163 -0
  80. package/lib/SyntheticFocusEvent.js +44 -0
  81. package/lib/SyntheticKeyboardEvent.js +56 -0
  82. package/lib/SyntheticMouseEvent.js +85 -0
  83. package/lib/SyntheticTouchEvent.js +50 -0
  84. package/lib/SyntheticUIEvent.js +45 -0
  85. package/lib/SyntheticWheelEvent.js +63 -0
  86. package/lib/Transaction.js +251 -0
  87. package/lib/ViewportMetrics.js +37 -0
  88. package/lib/accumulate.js +54 -0
  89. package/lib/adler32.js +39 -0
  90. package/lib/containsNode.js +49 -0
  91. package/lib/copyProperties.js +54 -0
  92. package/lib/createArrayFrom.js +94 -0
  93. package/lib/createNodesFromMarkup.js +93 -0
  94. package/lib/createObjectFrom.js +61 -0
  95. package/lib/cx.js +44 -0
  96. package/lib/dangerousStyleValue.js +57 -0
  97. package/lib/emptyFunction.js +43 -0
  98. package/lib/escapeTextForBrowser.js +47 -0
  99. package/lib/ex.js +49 -0
  100. package/lib/filterAttributes.js +45 -0
  101. package/lib/flattenChildren.js +54 -0
  102. package/lib/forEachAccumulated.js +36 -0
  103. package/lib/ge.js +76 -0
  104. package/lib/getActiveElement.js +33 -0
  105. package/lib/getEventTarget.js +36 -0
  106. package/lib/getMarkupWrap.js +108 -0
  107. package/lib/getNodeForCharacterOffset.js +80 -0
  108. package/lib/getReactRootElementInContainer.js +40 -0
  109. package/lib/getTextContentAccessor.js +40 -0
  110. package/lib/getUnboundedScrollPosition.js +45 -0
  111. package/lib/hyphenate.js +35 -0
  112. package/lib/invariant.js +54 -0
  113. package/lib/isEventSupported.js +74 -0
  114. package/lib/isNode.js +33 -0
  115. package/lib/isTextInputElement.js +49 -0
  116. package/lib/isTextNode.js +30 -0
  117. package/lib/joinClasses.js +44 -0
  118. package/lib/keyMirror.js +58 -0
  119. package/lib/keyOf.js +41 -0
  120. package/lib/memoizeStringOnly.js +39 -0
  121. package/lib/merge.js +37 -0
  122. package/lib/mergeHelpers.js +137 -0
  123. package/lib/mergeInto.js +45 -0
  124. package/lib/mixInto.js +34 -0
  125. package/lib/mutateHTMLNodeWithMarkup.js +100 -0
  126. package/lib/objMap.js +47 -0
  127. package/lib/objMapKeyVal.js +47 -0
  128. package/lib/performanceNow.js +42 -0
  129. package/lib/shallowEqual.js +49 -0
  130. package/lib/traverseAllChildren.js +127 -0
  131. package/package.json +33 -31
  132. package/react.js +4 -0
  133. package/.npmignore +0 -7
  134. package/.travis.yml +0 -7
  135. package/Jakefile.js +0 -39
  136. package/LICENSE +0 -19
  137. package/browser-test/dist.html +0 -90
  138. package/browser-test/index.html +0 -86
  139. package/browser-test/min.html +0 -90
  140. package/dist/react.js +0 -3141
  141. package/dist/react.min.js +0 -22
  142. package/doc/advanced.md +0 -175
  143. package/doc/color-def.graffle +0 -938
  144. package/doc/color-def.png +0 -0
  145. package/doc/simple.dot +0 -25
  146. package/doc/simple.png +0 -0
  147. package/examples/longer-example.js +0 -41
  148. package/examples/simple.js +0 -45
  149. package/examples/using-ast-directly.js +0 -30
  150. package/examples/using-events1.js +0 -79
  151. package/examples/using-log-events.js +0 -43
  152. package/lib/base-task.js +0 -120
  153. package/lib/cb-task.js +0 -84
  154. package/lib/core.js +0 -138
  155. package/lib/dsl.js +0 -138
  156. package/lib/error.js +0 -55
  157. package/lib/event-collector.js +0 -81
  158. package/lib/event-manager.js +0 -89
  159. package/lib/eventemitter.js +0 -20
  160. package/lib/finalcb-first-task.js +0 -68
  161. package/lib/finalcb-task.js +0 -65
  162. package/lib/id.js +0 -22
  163. package/lib/input-parser.js +0 -56
  164. package/lib/log-events.js +0 -101
  165. package/lib/parse.js +0 -41
  166. package/lib/promise-resolve.js +0 -50
  167. package/lib/promise-task.js +0 -93
  168. package/lib/react.js +0 -59
  169. package/lib/ret-task.js +0 -71
  170. package/lib/sprintf.js +0 -18
  171. package/lib/status.js +0 -14
  172. package/lib/task.js +0 -251
  173. package/lib/track-tasks.js +0 -74
  174. package/lib/validate.js +0 -159
  175. package/lib/vcon.js +0 -113
  176. package/lib/when-task.js +0 -84
  177. package/src/dist.build.requirejs +0 -20
  178. package/test/ast.mocha.js +0 -136
  179. package/test/cb-task.mocha.js +0 -220
  180. package/test/core-deferred.mocha.js +0 -143
  181. package/test/core-when.mocha.js +0 -96
  182. package/test/core.mocha.js +0 -589
  183. package/test/dsl.mocha.js +0 -352
  184. package/test/event-manager.mocha.js +0 -119
  185. package/test/exec-options.mocha.js +0 -48
  186. package/test/finalcb-task.mocha.js +0 -58
  187. package/test/input-parser.mocha.js +0 -86
  188. package/test/log-events.mocha.js +0 -88
  189. package/test/mocha.opts +0 -2
  190. package/test/module-use.mocha.js +0 -164
  191. package/test/promise-auto-resolve.mocha.js +0 -68
  192. package/test/ret-task.mocha.js +0 -220
  193. package/test/task.mocha.js +0 -42
  194. package/test/validate-cb-task.mocha.js +0 -100
  195. package/test/validate-ret-task.mocha.js +0 -110
  196. package/test/validate.mocha.js +0 -324
  197. package/test/vcon.mocha.js +0 -193
  198. package/vendor/chai/chai.js +0 -4251
  199. package/vendor/jquery/jquery-1.7.1.js +0 -9266
  200. package/vendor/jquery/jquery-1.7.1.min.js +0 -4
  201. package/vendor/node/util.js +0 -531
  202. package/vendor/requirejs/require.js +0 -2045
  203. package/vendor/requirejs/require.min.js +0 -36
@@ -1,324 +0,0 @@
1
- /*global react:true util:true sprintf:true validate:true taskUtil:true */
2
-
3
- if (typeof(chai) === 'undefined') {
4
- var chai = require('chai');
5
- }
6
-
7
- if (typeof(react) === 'undefined') {
8
- var react = require('../'); //require('react');
9
- }
10
-
11
- if (typeof(util) === 'undefined') {
12
- var util = require('util');
13
- }
14
-
15
- if (typeof(sprintf) === 'undefined') {
16
- var sprintf = require('../lib/sprintf');
17
- }
18
-
19
- if (typeof(validate) === 'undefined') {
20
- var validate = require('../lib/validate.js');
21
- }
22
-
23
- if (typeof(taskUtil) === 'undefined') {
24
- var taskUtil = require('../lib/task.js');
25
- }
26
-
27
- (function () {
28
- 'use strict';
29
-
30
- var t = chai.assert;
31
-
32
- /**
33
- Testing ...
34
- */
35
-
36
- suite('validate');
37
-
38
- function foo() { }
39
- function bar() { }
40
-
41
- test('empty ast is invalid', function (done) {
42
- t.deepEqual(validate(), ['ast must be an object with inParams, tasks, and outTask']);
43
- t.deepEqual(validate({}), ['ast must be an object with inParams, tasks, and outTask']);
44
- t.deepEqual(validate({ inParams: [] }), ['ast must be an object with inParams, tasks, and outTask']);
45
- t.deepEqual(validate({ tasks: [] }), ['ast must be an object with inParams, tasks, and outTask']);
46
- t.deepEqual(validate({ tasks: [], outTask: {} }), ['ast must be an object with inParams, tasks, and outTask']);
47
- t.deepEqual(validate({ outTask: {} }), ['ast must be an object with inParams, tasks, and outTask']);
48
- done();
49
- });
50
-
51
- test('ast.inParams must be an array of strings', function (done) {
52
- var ast = {
53
- inParams: 'a', //err should be an array
54
- tasks: [{ f: foo, a: [], out: ['bar'], type: 'ret' }],
55
- outTask: { a: ['bar'] }
56
- };
57
- t.deepEqual(validate(ast), ['ast.inParams must be an array of strings']);
58
-
59
- ast.inParams = [1]; //err not an array of strings
60
- t.deepEqual(validate(ast), ['ast.inParams must be an array of strings']);
61
- done();
62
- });
63
-
64
- test('ast.tasks must be an array of tasks', function (done) {
65
- var ast = {
66
- inParams: ['a'],
67
- tasks: 'bar', //err should be array
68
- outTask: { a: ['bar'] }
69
- };
70
- t.deepEqual(validate(ast), ['ast.tasks must be an array of tasks']);
71
- done();
72
- });
73
-
74
- test('each task must be an object', function (done) {
75
- var ast = {
76
- inParams: ['a'],
77
- tasks: [1], //err not array of objects
78
- outTask: { a: ['bar'] }
79
- };
80
- t.deepEqual(validate(ast), ['task must be an object - 1']);
81
- done();
82
-
83
- });
84
-
85
-
86
- test('each task in ast.tasks must match a valid task type', function (done) {
87
- var ast = {
88
- inParams: ['a'],
89
- tasks: [{ type: 'zoo', f: foo, a: [], out: ['bar'] }], //err wrong type
90
- outTask: { a: ['bar'] }
91
- };
92
- var msg = sprintf('task.type should match one of %s - %s',
93
- taskUtil.taskTypeKeys().join(', '), util.inspect(ast.tasks[0]));
94
- t.deepEqual(validate(ast), [msg]);
95
- done();
96
- });
97
-
98
- test('ast.outTask.a should be an array of string param names', function (done) {
99
- var ast = {
100
- inParams: ['a'],
101
- tasks: [{ f: foo, a: [], out: ['bar'], type: 'ret' }],
102
- outTask: { a: ['bar'] }
103
- };
104
- ast.outTask = {}; //err a should be an arr
105
- var msg = sprintf('ast.outTask.a should be an array of string param names - %s',
106
- util.inspect({ type: 'finalcb' }));
107
- t.deepEqual(validate(ast), [msg]);
108
-
109
- ast.outTask = { type: 'finalcb', a: 'bar' }; //err a should be an arr
110
- msg = sprintf('ast.outTask.a should be an array of string param names - %s',
111
- util.inspect(ast.outTask));
112
- t.deepEqual(validate(ast), [msg]);
113
-
114
- ast.outTask = { type: 'finalcb', a: ['bar', 1] }; //err a should be an arr of strings
115
- msg = sprintf('ast.outTask.a should be an array of string param names - %s',
116
- util.inspect(ast.outTask));
117
- t.deepEqual(validate(ast), [msg]);
118
-
119
- ast.outTask = { a: [] }; //valid
120
- t.deepEqual(validate(ast), []);
121
- done();
122
- });
123
-
124
- test('ast.tasks that specify name need to be unique', function (done) {
125
- var ast = {
126
- inParams: ['a'],
127
- tasks: [
128
- { f: foo, a: [], out: ['bar'], name: 'dog' },
129
- { f: foo, a: [], out: ['bar'], name: 'dog' }
130
- ],
131
- outTask: { a: ['bar'] }
132
- };
133
- var msg = sprintf('ast.tasks that specify name need to be unique, duplicate: %s',
134
- 'dog');
135
- t.deepEqual(validate(ast), [msg]);
136
- done();
137
- });
138
-
139
- test('ast.locals should be non-null if passed in', function (done) {
140
- var ast = {
141
- inParams: ['a'],
142
- tasks: [{ f: foo, a: [], out: ['bar'], type: 'ret' }],
143
- outTask: { a: ['bar'] },
144
- locals: null //err should be non-null if passed in
145
- };
146
- t.deepEqual(validate(ast), ['ast.locals should not be null']);
147
-
148
- ast.locals = { };
149
- t.deepEqual(validate(ast), []);
150
- done();
151
- });
152
-
153
- test('non-method string functions need to map to fn in locals or in params', function (done) {
154
- var ast = {
155
- inParams: ['a'],
156
- tasks: [{ f: 'foo', a: [], out: ['bar'], type: 'ret' }],
157
- outTask: { a: ['bar'] },
158
- locals: { }
159
- };
160
- var msg = sprintf('function: %s not found in locals or input params - task[%s]',
161
- 'foo', 0);
162
- t.deepEqual(validate(ast), [msg]);
163
- done();
164
- });
165
-
166
- test('string functions maps to fn in locals', function (done) {
167
- var ast = {
168
- inParams: ['a'],
169
- tasks: [{ f: 'cat.bar', a: [], out: ['bar'], type: 'ret' }],
170
- outTask: { a: ['bar'] },
171
- locals: { cat: { bar: foo }}
172
- };
173
- t.deepEqual(validate(ast), []);
174
- done();
175
- });
176
-
177
- test('string functions maps to fn in inputs', function (done) {
178
- var ast = {
179
- inParams: ['a1', 'dog'],
180
- tasks: [{ f: 'dog.food', a: [], out: ['bar'], type: 'ret' }],
181
- outTask: { a: ['bar'] },
182
- locals: { }
183
- };
184
- t.deepEqual(validate(ast), []);
185
- done();
186
- });
187
-
188
- test('string functions need to map to fn in locals or in params', function (done) {
189
- var ast = {
190
- inParams: ['a'],
191
- tasks: [{ f: 'foo.bar', a: [], out: ['bar'], type: 'ret' }],
192
- outTask: { a: ['bar'] },
193
- locals: { foo: {}}
194
- };
195
- var msg = sprintf('function: %s not found in locals or input params - task[%s]',
196
- 'foo.bar', 0);
197
- t.deepEqual(validate(ast), [msg]);
198
- done();
199
- });
200
-
201
- test('param func str fn need to map to fn in locals or in params', function (done) {
202
- var ast = {
203
- inParams: ['a'],
204
- tasks: [{ f: 'a', a: [], out: ['bar'], type: 'ret' }],
205
- outTask: { a: ['bar'] },
206
- locals: { }
207
- };
208
- t.deepEqual(validate(ast), []);
209
- done();
210
- });
211
-
212
- test('param obj exist func str needs map to fn in locals or in params', function (done) {
213
- var ast = {
214
- inParams: ['a'],
215
- tasks: [{ f: 'a.b', a: [], out: ['bar'], type: 'ret' }],
216
- outTask: { a: ['bar'] },
217
- locals: { }
218
- };
219
- t.deepEqual(validate(ast), []);
220
- done();
221
- });
222
-
223
- test('param obj !exist func str needs map to fn in locals or in params', function (done) {
224
- var ast = {
225
- inParams: ['a'],
226
- tasks: [{ f: 'd.e', a: [], out: ['bar'], type: 'ret' }],
227
- outTask: { a: ['bar'] },
228
- locals: { }
229
- };
230
- t.deepEqual(validate(ast), []);
231
- done();
232
- });
233
-
234
- test('multiple tasks output the same param, must be unique', function (done) {
235
- var ast = {
236
- inParams: ['a'],
237
- tasks: [
238
- { f: foo, a: [], out: ['baz', 'c'] },
239
- { f: bar, a: [], out: ['c'] }
240
- ],
241
- outTask: { a: ['baz'] }
242
- };
243
- var msg = 'multiple tasks output the same param, must be unique. param: c';
244
- t.deepEqual(validate(ast), [msg]);
245
- done();
246
- });
247
-
248
- test('missing or mispelled input variable', function (done) {
249
- var ast = {
250
- inParams: [],
251
- tasks: [
252
- { f: foo, a: [], out: [] },
253
- { f: bar, a: ['abc'], out: [] }
254
- ],
255
- outTask: { a: [] }
256
- };
257
- var msg = 'missing or mispelled variable referenced in flow definition: abc';
258
- t.deepEqual(validate(ast), [msg]);
259
- done();
260
- });
261
-
262
- test('missing or mispelled input variables', function (done) {
263
- var ast = {
264
- inParams: ['aaa', 'bbb'],
265
- tasks: [
266
- { f: foo, a: ['aaa', 'cat'], out: ['ccc'] },
267
- { f: bar, a: ['abc', 'bbb', 'ccc'], out: [] }
268
- ],
269
- outTask: { a: [] }
270
- };
271
- var messages = [
272
- 'missing or mispelled variable referenced in flow definition: cat',
273
- 'missing or mispelled variable referenced in flow definition: abc'
274
- ];
275
- t.deepEqual(validate(ast), messages);
276
- done();
277
- });
278
-
279
- test('missing or mispelled final output variables', function (done) {
280
- var ast = {
281
- inParams: ['aaa'],
282
- tasks: [
283
- { f: foo, a: ['aaa'], out: ['bbb'] },
284
- { f: bar, a: ['bbb'], out: ['ccc'] }
285
- ],
286
- outTask: { a: ['ccc', 'ddd', 'eee'] }
287
- };
288
- var messages = [
289
- 'missing or mispelled variable referenced in flow definition: ddd',
290
- 'missing or mispelled variable referenced in flow definition: eee'
291
- ];
292
- t.deepEqual(validate(ast), messages);
293
- done();
294
- });
295
-
296
- test('missing or mispelled validation ignores properties', function (done) {
297
- var ast = {
298
- inParams: ['obj'],
299
- tasks: [
300
- { f: foo, a: ['obj.foo'], out: [] },
301
- { f: bar, a: ['obj.bar'], out: [] }
302
- ],
303
- outTask: { a: ['obj.cat'] }
304
- };
305
- t.deepEqual(validate(ast), []);
306
- done();
307
- });
308
-
309
- test('missing or mispelled validation ignores literals', function (done) {
310
- var ast = {
311
- inParams: [],
312
- tasks: [
313
- { f: foo, a: ['true', 'false', '123', '123.1', 'null'], out: [] },
314
- { f: bar, a: ['-123', '-123.4', '"wow"', "'hey'"], out: [] },
315
- { f: foo, a: ['"two-words"', "'also-two'", '"two.words"', "'also.two'"], out: [] },
316
- { f: foo, a: ['this'], out: [] }
317
- ],
318
- outTask: { a: [] }
319
- };
320
- t.deepEqual(validate(ast), []);
321
- done();
322
- });
323
-
324
- }());
@@ -1,193 +0,0 @@
1
- /*global react:true VContext:true */
2
-
3
- if (typeof(chai) === 'undefined') {
4
- var chai = require('chai');
5
- }
6
-
7
- if (typeof(react) === 'undefined') {
8
- var react = require('../'); //require('react');
9
- }
10
-
11
- if (typeof(VContext) === 'undefined') {
12
- var VContext = require('../lib/vcon.js');
13
- }
14
-
15
- (function () {
16
- 'use strict';
17
-
18
- var t = chai.assert;
19
-
20
- /**
21
- Testing Variable Context
22
- */
23
-
24
- suite('vcon');
25
-
26
- test('VContext.create with empty args returns empty vCon', function (done) {
27
- t.deepEqual(VContext.create([], []).values, {}, 'should be empty object');
28
- t.deepEqual(VContext.create([], ['a']).values, {}, 'should be empty object');
29
- done();
30
- });
31
-
32
- test('VContext.create with more args than params, ignore extra args', function (done) {
33
- t.deepEqual(VContext.create([1], []).values, {}, 'should be empty object');
34
- t.deepEqual(VContext.create([1, 2], ['a']).values, { a: 1 },
35
- 'should be object with one value');
36
- done();
37
- });
38
-
39
- test('VContext.create sets vCon[paramName] to arg value', function (done) {
40
- t.deepEqual(VContext.create([1, 2], ['a', 'b']).values, { a: 1, b: 2 },
41
- 'should have all values');
42
- done();
43
- });
44
-
45
- test('create with locals is merged with args taking precedence', function (done) {
46
- var locals = { a: 11, c: 30 };
47
- t.deepEqual(VContext.create([1, 2], ['a', 'b'], locals).values,
48
- { a: 1, c: 30, b: 2 }, 'should have merge of values');
49
- done();
50
- });
51
-
52
- test('create with locals should not modify original locals', function (done) {
53
- var locals = { a: 11, c: 30 };
54
- t.deepEqual(VContext.create([1, 2], ['a', 'b'], locals).values,
55
- { a: 1, c: 30, b: 2 }, 'should have merge of values');
56
- t.deepEqual(locals, { a: 11, c: 30 }, 'should not modify original locals object');
57
- done();
58
- });
59
-
60
- test('getVar on null returns null', function (done) {
61
- t.equal(VContext.create([null], ['a']).getVar('a'), null);
62
- t.equal(VContext.create([{ b: null }], ['a']).getVar('a.b'), null);
63
- done();
64
- });
65
-
66
- test('getVar on undefined or null parent returns undefined', function (done) {
67
- t.equal(VContext.create([], []).getVar('a'), undefined);
68
- t.equal(VContext.create([], ['a']).getVar('a'), undefined);
69
- t.equal(VContext.create([], ['a']).getVar('a.b'), undefined);
70
- t.equal(VContext.create([], ['a']).getVar('a.b.c'), undefined);
71
- t.equal(VContext.create([null], ['a']).getVar('a.b'), undefined);
72
- t.equal(VContext.create([null], ['a']).getVar('a.b.c'), undefined);
73
- t.equal(VContext.create([1], ['a']).getVar('a.b'), undefined);
74
- t.equal(VContext.create([1], ['a']).getVar('a.b.c'), undefined);
75
- done();
76
- });
77
-
78
- test('simple getVar returns existing value', function (done) {
79
- t.equal(VContext.create([null], ['a']).getVar('a'), null);
80
- t.equal(VContext.create([1], ['a']).getVar('a'), 1);
81
- t.equal(VContext.create([true], ['a']).getVar('a'), true);
82
- t.equal(VContext.create(['banana'], ['a']).getVar('a'), 'banana');
83
- done();
84
- });
85
-
86
- test('getVar on literals returns the literal', function (done) {
87
- t.equal(VContext.create([], []).getVar(true), true);
88
- t.equal(VContext.create([], []).getVar(false), false);
89
- t.equal(VContext.create([], []).getVar(null), null);
90
- t.equal(VContext.create([], []).getVar('true'), true);
91
- t.equal(VContext.create([], []).getVar('false'), false);
92
- t.equal(VContext.create([], []).getVar('null'), null);
93
- t.equal(VContext.create([], []).getVar(-100), -100);
94
- t.equal(VContext.create([], []).getVar(100), 100);
95
- t.equal(VContext.create([], []).getVar(123.4), 123.4);
96
- t.equal(VContext.create([], []).getVar(-987.6), -987.6);
97
- t.equal(VContext.create([], []).getVar('-100'), -100);
98
- t.equal(VContext.create([], []).getVar('100'), 100);
99
- t.equal(VContext.create([], []).getVar('123.4'), 123.4);
100
- t.equal(VContext.create([], []).getVar('-987.6'), -987.6);
101
- t.equal(VContext.create([], []).getVar('"foo"'), 'foo');
102
- t.equal(VContext.create([], []).getVar("'foo'"), 'foo');
103
- t.equal(VContext.create([], []).getVar("'foo.bar'"), 'foo.bar');
104
- t.equal(VContext.create([], []).getVar("'foo-bar'"), 'foo-bar');
105
- t.equal(VContext.create([], []).getVar("'foo-bar.json'"), 'foo-bar.json');
106
- t.equal(VContext.create([], []).getVar('"foo-bar.json"'), 'foo-bar.json');
107
- t.deepEqual(VContext.create([], [], null, { a: 1}).getVar('this'), { a: 1});
108
- done();
109
- });
110
-
111
- test('getVar for property returns the property', function (done) {
112
- var o = { b: 100};
113
- t.equal(VContext.create([o], ['a']).getVar('a.b'), 100);
114
- o = { b: { c: 200 }};
115
- t.equal(VContext.create([o], ['a']).getVar('a.b.c'), 200);
116
- done();
117
- });
118
-
119
- test('setVar will create objects if needed', function (done) {
120
- var v = VContext.create([], []);
121
- v.setVar('foo.bar.baz', 100);
122
- t.deepEqual(v.values, { foo: { bar: { baz: 100}}});
123
- done();
124
- });
125
-
126
- test('simple setVar', function (done) {
127
- var v = VContext.create([], []);
128
- v.setVar('foo', 100);
129
- t.deepEqual(v.values, { foo: 100});
130
- done();
131
- });
132
-
133
- test('setVar will not affect other vars', function (done) {
134
- var v = VContext.create([{ bar: 1}], ['foo']);
135
- v.setVar('foo.baz', 2);
136
- t.deepEqual(v.values, { foo: { bar: 1, baz: 2 }});
137
- done();
138
- });
139
-
140
- test('setVar with null key, will not set anything', function (done) {
141
- var v = VContext.create([{ bar: 1}], ['foo']);
142
- v.setVar(null, 2);
143
- t.deepEqual(v.values, { foo: { bar: 1 }});
144
- done();
145
- });
146
-
147
- test('setVar with undefined key, will not set anything', function (done) {
148
- var v = VContext.create([{ bar: 1}], ['foo']);
149
- v.setVar(undefined, 2);
150
- t.deepEqual(v.values, { foo: { bar: 1 }});
151
- done();
152
- });
153
-
154
- test('saveResults will set values for params and :LAST_RESULTS', function (done) {
155
- var v = VContext.create([], []);
156
- v.saveResults(['foo', 'bar', 'cat'], [1, 'hello', null]);
157
- t.deepEqual(v.values, { foo: 1, bar: 'hello', cat: null,
158
- ':LAST_RESULTS': [1, 'hello', null] });
159
- done();
160
- });
161
-
162
- test('saveResults set :LAST_RESULT w/all even params is short', function (done) {
163
- var v = VContext.create([], []);
164
- v.saveResults(['foo'], [1, 'hello', null]);
165
- t.deepEqual(v.values, { foo: 1,
166
- ':LAST_RESULTS': [1, 'hello', null] });
167
- done();
168
- });
169
-
170
- test('saveResults will set values for params and :LAST_RESULTS', function (done) {
171
- var v = VContext.create([], []);
172
- v.saveResults(['foo', 'bar', 'cat'], [1, 'hello', null]);
173
- t.deepEqual(v.values, { foo: 1, bar: 'hello', cat: null,
174
- ':LAST_RESULTS': [1, 'hello', null] });
175
- done();
176
- });
177
-
178
- test('saveResults upgrades undefined to null, but :LAST_RESULT is exact', function (done) {
179
- var v = VContext.create([], []);
180
- v.saveResults(['foo', 'bar', 'baz'], [1, undefined]);
181
- t.deepEqual(v.values, { foo: 1, bar: null, baz: null,
182
- ':LAST_RESULTS': [1, undefined] });
183
- done();
184
- });
185
-
186
- test('saveResults null params skips saving, :LAST_RESULT is exact', function (done) {
187
- var v = VContext.create([], []);
188
- v.saveResults(['foo', null], [1, 20]); //skip second param
189
- t.deepEqual(v.values, { foo: 1, ':LAST_RESULTS': [1, 20] });
190
- done();
191
- });
192
-
193
- }());