react 0.6.3 → 0.9.0-rc1

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 (218) hide show
  1. package/README.md +10 -222
  2. package/addons.js +1 -0
  3. package/lib/AutoFocusMixin.js +30 -0
  4. package/lib/CSSCore.js +115 -0
  5. package/lib/CSSProperty.js +121 -0
  6. package/lib/CSSPropertyOperations.js +97 -0
  7. package/lib/ChangeEventPlugin.js +387 -0
  8. package/lib/ClientReactRootIndex.js +30 -0
  9. package/lib/CompositionEventPlugin.js +260 -0
  10. package/lib/DOMChildrenOperations.js +165 -0
  11. package/lib/DOMProperty.js +268 -0
  12. package/lib/DOMPropertyOperations.js +181 -0
  13. package/lib/Danger.js +187 -0
  14. package/lib/DefaultDOMPropertyConfig.js +197 -0
  15. package/lib/DefaultEventPluginOrder.js +44 -0
  16. package/lib/EnterLeaveEventPlugin.js +145 -0
  17. package/lib/EventConstants.js +76 -0
  18. package/lib/EventListener.js +69 -0
  19. package/lib/EventPluginHub.js +291 -0
  20. package/lib/EventPluginRegistry.js +260 -0
  21. package/lib/EventPluginUtils.js +214 -0
  22. package/lib/EventPropagators.js +143 -0
  23. package/lib/ExecutionEnvironment.js +44 -0
  24. package/lib/LinkedStateMixin.js +46 -0
  25. package/lib/LinkedValueUtils.js +161 -0
  26. package/lib/MobileSafariClickEventPlugin.js +63 -0
  27. package/lib/PooledClass.js +119 -0
  28. package/lib/React.js +95 -0
  29. package/lib/ReactCSSTransitionGroup.js +65 -0
  30. package/lib/ReactCSSTransitionGroupChild.js +138 -0
  31. package/lib/ReactChildren.js +132 -0
  32. package/lib/ReactComponent.js +550 -0
  33. package/lib/ReactComponentBrowserEnvironment.js +158 -0
  34. package/lib/ReactComponentEnvironment.js +26 -0
  35. package/lib/ReactCompositeComponent.js +1455 -0
  36. package/lib/ReactContext.js +67 -0
  37. package/lib/ReactCurrentOwner.js +39 -0
  38. package/lib/ReactDOM.js +207 -0
  39. package/lib/ReactDOMButton.js +68 -0
  40. package/lib/ReactDOMComponent.js +399 -0
  41. package/lib/ReactDOMForm.js +59 -0
  42. package/lib/ReactDOMIDOperations.js +218 -0
  43. package/lib/ReactDOMImg.js +58 -0
  44. package/lib/ReactDOMInput.js +181 -0
  45. package/lib/ReactDOMOption.js +51 -0
  46. package/lib/ReactDOMSelect.js +179 -0
  47. package/lib/ReactDOMSelection.js +189 -0
  48. package/lib/ReactDOMTextarea.js +140 -0
  49. package/lib/ReactDefaultBatchingStrategy.js +75 -0
  50. package/lib/ReactDefaultInjection.js +115 -0
  51. package/lib/ReactDefaultPerf.js +244 -0
  52. package/lib/ReactDefaultPerfAnalysis.js +199 -0
  53. package/lib/ReactErrorUtils.js +37 -0
  54. package/lib/ReactEventEmitter.js +337 -0
  55. package/lib/ReactEventEmitterMixin.js +57 -0
  56. package/lib/ReactEventTopLevelCallback.js +109 -0
  57. package/lib/ReactInjection.js +39 -0
  58. package/lib/ReactInputSelection.js +140 -0
  59. package/lib/ReactInstanceHandles.js +338 -0
  60. package/lib/ReactLink.js +54 -0
  61. package/lib/ReactMarkupChecksum.js +53 -0
  62. package/lib/ReactMount.js +641 -0
  63. package/lib/ReactMountReady.js +95 -0
  64. package/lib/ReactMultiChild.js +425 -0
  65. package/lib/ReactMultiChildUpdateTypes.js +38 -0
  66. package/lib/ReactOwner.js +154 -0
  67. package/lib/ReactPerf.js +85 -0
  68. package/lib/ReactPropTransferer.js +147 -0
  69. package/lib/ReactPropTypeLocationNames.js +31 -0
  70. package/lib/ReactPropTypeLocations.js +29 -0
  71. package/lib/ReactPropTypes.js +359 -0
  72. package/lib/ReactPutListenerQueue.js +61 -0
  73. package/lib/ReactReconcileTransaction.js +181 -0
  74. package/lib/ReactRootIndex.js +36 -0
  75. package/lib/ReactServerRendering.js +59 -0
  76. package/lib/ReactStateSetters.js +111 -0
  77. package/lib/ReactTextComponent.js +99 -0
  78. package/lib/ReactTransitionChildMapping.js +106 -0
  79. package/lib/ReactTransitionEvents.js +97 -0
  80. package/lib/ReactTransitionGroup.js +187 -0
  81. package/lib/ReactUpdates.js +148 -0
  82. package/lib/ReactWithAddons.js +46 -0
  83. package/lib/SelectEventPlugin.js +200 -0
  84. package/lib/ServerReactRootIndex.js +36 -0
  85. package/lib/SimpleEventPlugin.js +413 -0
  86. package/lib/SyntheticClipboardEvent.js +51 -0
  87. package/lib/SyntheticCompositionEvent.js +51 -0
  88. package/lib/SyntheticDragEvent.js +44 -0
  89. package/lib/SyntheticEvent.js +164 -0
  90. package/lib/SyntheticFocusEvent.js +44 -0
  91. package/lib/SyntheticKeyboardEvent.js +58 -0
  92. package/lib/SyntheticMouseEvent.js +85 -0
  93. package/lib/SyntheticTouchEvent.js +50 -0
  94. package/lib/SyntheticUIEvent.js +45 -0
  95. package/lib/SyntheticWheelEvent.js +66 -0
  96. package/lib/Transaction.js +276 -0
  97. package/lib/ViewportMetrics.js +37 -0
  98. package/lib/accumulate.js +54 -0
  99. package/lib/adler32.js +39 -0
  100. package/lib/cloneWithProps.js +59 -0
  101. package/lib/containsNode.js +49 -0
  102. package/lib/copyProperties.js +54 -0
  103. package/lib/createArrayFrom.js +91 -0
  104. package/lib/createFullPageComponent.js +63 -0
  105. package/lib/createNodesFromMarkup.js +93 -0
  106. package/lib/createObjectFrom.js +61 -0
  107. package/lib/cx.js +44 -0
  108. package/lib/dangerousStyleValue.js +57 -0
  109. package/lib/emptyFunction.js +43 -0
  110. package/lib/escapeTextForBrowser.js +47 -0
  111. package/lib/flattenChildren.js +57 -0
  112. package/lib/forEachAccumulated.js +36 -0
  113. package/lib/getActiveElement.js +34 -0
  114. package/lib/getEventKey.js +85 -0
  115. package/lib/getEventTarget.js +36 -0
  116. package/lib/getMarkupWrap.js +118 -0
  117. package/lib/getNodeForCharacterOffset.js +80 -0
  118. package/lib/getReactRootElementInContainer.js +40 -0
  119. package/lib/getTextContentAccessor.js +42 -0
  120. package/lib/getUnboundedScrollPosition.js +45 -0
  121. package/lib/hyphenate.js +35 -0
  122. package/lib/invariant.js +62 -0
  123. package/lib/isEventSupported.js +70 -0
  124. package/lib/isNode.js +33 -0
  125. package/lib/isTextInputElement.js +49 -0
  126. package/lib/isTextNode.js +30 -0
  127. package/lib/joinClasses.js +44 -0
  128. package/lib/keyMirror.js +58 -0
  129. package/lib/keyOf.js +41 -0
  130. package/lib/memoizeStringOnly.js +39 -0
  131. package/lib/merge.js +37 -0
  132. package/lib/mergeHelpers.js +136 -0
  133. package/lib/mergeInto.js +45 -0
  134. package/lib/mixInto.js +34 -0
  135. package/lib/objMap.js +47 -0
  136. package/lib/objMapKeyVal.js +47 -0
  137. package/lib/onlyChild.js +43 -0
  138. package/lib/performanceNow.js +42 -0
  139. package/lib/shallowEqual.js +49 -0
  140. package/lib/shouldUpdateReactComponent.js +58 -0
  141. package/lib/toArray.js +75 -0
  142. package/lib/traverseAllChildren.js +189 -0
  143. package/lib/warning.js +40 -0
  144. package/package.json +32 -21
  145. package/react.js +1 -0
  146. package/.npmignore +0 -7
  147. package/.travis.yml +0 -5
  148. package/Jakefile.js +0 -39
  149. package/LICENSE +0 -19
  150. package/browser-test/dist.html +0 -90
  151. package/browser-test/index.html +0 -86
  152. package/browser-test/min.html +0 -90
  153. package/dist/react.js +0 -3107
  154. package/dist/react.min.js +0 -22
  155. package/doc/advanced.md +0 -174
  156. package/doc/color-def.graffle +0 -938
  157. package/doc/color-def.png +0 -0
  158. package/doc/simple.dot +0 -25
  159. package/doc/simple.png +0 -0
  160. package/examples/longer-example.js +0 -41
  161. package/examples/simple.js +0 -45
  162. package/examples/using-ast-directly.js +0 -30
  163. package/examples/using-events1.js +0 -79
  164. package/examples/using-log-events.js +0 -43
  165. package/lib/base-task.js +0 -123
  166. package/lib/cb-task.js +0 -84
  167. package/lib/core.js +0 -138
  168. package/lib/dsl.js +0 -138
  169. package/lib/error.js +0 -55
  170. package/lib/event-collector.js +0 -81
  171. package/lib/event-manager.js +0 -89
  172. package/lib/eventemitter.js +0 -20
  173. package/lib/finalcb-first-task.js +0 -68
  174. package/lib/finalcb-task.js +0 -65
  175. package/lib/id.js +0 -22
  176. package/lib/input-parser.js +0 -56
  177. package/lib/log-events.js +0 -101
  178. package/lib/parse.js +0 -41
  179. package/lib/promise-resolve.js +0 -50
  180. package/lib/promise-task.js +0 -93
  181. package/lib/react.js +0 -59
  182. package/lib/ret-task.js +0 -71
  183. package/lib/sprintf.js +0 -18
  184. package/lib/status.js +0 -14
  185. package/lib/task.js +0 -251
  186. package/lib/track-tasks.js +0 -74
  187. package/lib/validate.js +0 -159
  188. package/lib/vcon.js +0 -90
  189. package/lib/when-task.js +0 -85
  190. package/src/dist.build.requirejs +0 -20
  191. package/test/ast.mocha.js +0 -136
  192. package/test/cb-task.mocha.js +0 -220
  193. package/test/core-deferred.mocha.js +0 -143
  194. package/test/core-when.mocha.js +0 -96
  195. package/test/core.mocha.js +0 -589
  196. package/test/dsl.mocha.js +0 -350
  197. package/test/event-manager.mocha.js +0 -119
  198. package/test/exec-options.mocha.js +0 -48
  199. package/test/finalcb-task.mocha.js +0 -58
  200. package/test/input-parser.mocha.js +0 -86
  201. package/test/log-events.mocha.js +0 -88
  202. package/test/mocha.opts +0 -2
  203. package/test/module-use.mocha.js +0 -147
  204. package/test/promise-auto-resolve.mocha.js +0 -68
  205. package/test/ret-task.mocha.js +0 -220
  206. package/test/task.mocha.js +0 -42
  207. package/test/validate-cb-task.mocha.js +0 -100
  208. package/test/validate-ret-task.mocha.js +0 -110
  209. package/test/validate.mocha.js +0 -324
  210. package/test/vcon.mocha.js +0 -193
  211. package/vendor/chai/chai.js +0 -2038
  212. package/vendor/jquery/jquery-1.7.1.js +0 -9266
  213. package/vendor/jquery/jquery-1.7.1.min.js +0 -4
  214. package/vendor/mocha/mocha.css +0 -135
  215. package/vendor/mocha/mocha.js +0 -3589
  216. package/vendor/node/util.js +0 -531
  217. package/vendor/requirejs/require.js +0 -2053
  218. package/vendor/requirejs/require.min.js +0 -33
@@ -1,324 +0,0 @@
1
- 'use strict';
2
- /*global react:true util:true sprintf:true validate:true taskUtil:true */
3
-
4
- if (typeof(chai) === 'undefined') {
5
- var chai = require('chai');
6
- }
7
-
8
- if (typeof(react) === 'undefined') {
9
- var react = require('../'); //require('react');
10
- }
11
-
12
- if (typeof(util) === 'undefined') {
13
- var util = require('util');
14
- }
15
-
16
- if (typeof(sprintf) === 'undefined') {
17
- var sprintf = require('../lib/sprintf');
18
- }
19
-
20
- if (typeof(validate) === 'undefined') {
21
- var validate = require('../lib/validate.js');
22
- }
23
-
24
- if (typeof(taskUtil) === 'undefined') {
25
- var taskUtil = require('../lib/task.js');
26
- }
27
-
28
- (function () {
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
- 'use strict';
2
- /*global react:true VContext:true */
3
-
4
- if (typeof(chai) === 'undefined') {
5
- var chai = require('chai');
6
- }
7
-
8
- if (typeof(react) === 'undefined') {
9
- var react = require('../'); //require('react');
10
- }
11
-
12
- if (typeof(VContext) === 'undefined') {
13
- var VContext = require('../lib/vcon.js');
14
- }
15
-
16
- (function () {
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
- }());