config_test.js 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. /* ***** BEGIN LICENSE BLOCK *****
  2. * Distributed under the BSD license:
  3. *
  4. * Copyright (c) 2010, Ajax.org B.V.
  5. * All rights reserved.
  6. *
  7. * Redistribution and use in source and binary forms, with or without
  8. * modification, are permitted provided that the following conditions are met:
  9. * * Redistributions of source code must retain the above copyright
  10. * notice, this list of conditions and the following disclaimer.
  11. * * Redistributions in binary form must reproduce the above copyright
  12. * notice, this list of conditions and the following disclaimer in the
  13. * documentation and/or other materials provided with the distribution.
  14. * * Neither the name of Ajax.org B.V. nor the
  15. * names of its contributors may be used to endorse or promote products
  16. * derived from this software without specific prior written permission.
  17. *
  18. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  19. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  20. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  21. * DISCLAIMED. IN NO EVENT SHALL AJAX.ORG B.V. BE LIABLE FOR ANY
  22. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  23. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  24. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  25. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  26. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  27. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  28. *
  29. * ***** END LICENSE BLOCK ***** */
  30. if (typeof process !== "undefined") {
  31. require("amd-loader");
  32. }
  33. define(function(require, exports, module) {
  34. "use strict";
  35. var config = require("./config");
  36. var assert = require("./test/assertions");
  37. module.exports = {
  38. "test: path resolution" : function() {
  39. config.set("packaged", "true");
  40. var url = config.moduleUrl("kr_theme", "theme");
  41. assert.equal(url, "theme-kr_theme.js");
  42. config.set("basePath", "a/b");
  43. url = config.moduleUrl("m/theme", "theme");
  44. assert.equal(url, "a/b/theme-m.js");
  45. url = config.moduleUrl("m/theme", "ext");
  46. assert.equal(url, "a/b/ext-theme.js");
  47. config.set("workerPath", "c/");
  48. url = config.moduleUrl("foo/1", "worker");
  49. assert.equal(url, "c/worker-1.js");
  50. config.setModuleUrl("foo/1", "a/b1.js");
  51. url = config.moduleUrl("foo/1", "theme");
  52. assert.equal(url, "a/b1.js");
  53. url = config.moduleUrl("snippets/js");
  54. assert.equal(url, "a/b/snippets/js.js");
  55. config.setModuleUrl("snippets/js", "_.js");
  56. url = config.moduleUrl("snippets/js");
  57. assert.equal(url, "_.js");
  58. url = config.moduleUrl("ace/ext/textarea");
  59. assert.equal(url, "a/b/ext-textarea.js");
  60. assert.equal();
  61. },
  62. "test: define options" : function() {
  63. var o = {};
  64. config.defineOptions(o, "test_object", {
  65. opt1: {
  66. set: function(val) {
  67. this.x = val;
  68. },
  69. value: 7,
  70. },
  71. initialValue: {
  72. set: function(val) {
  73. this.x = val;
  74. },
  75. initialValue: 8,
  76. },
  77. opt2: {
  78. get: function(val) {
  79. return this.x;
  80. }
  81. },
  82. forwarded: "model"
  83. });
  84. o.model = {};
  85. config.defineOptions(o.model, "model", {
  86. forwarded: {value: 1}
  87. });
  88. config.resetOptions(o);
  89. config.resetOptions(o.model);
  90. assert.equal(o.getOption("opt1"), 7);
  91. assert.equal(o.getOption("opt2"), 7);
  92. o.setOption("opt1", 8);
  93. assert.equal(o.getOption("opt1"), 8);
  94. assert.equal(o.getOption("opt2"), 8);
  95. assert.equal(o.getOption("forwarded"), 1);
  96. assert.equal(o.getOption("new"), undefined);
  97. o.setOption("new", 0);
  98. assert.equal(o.getOption("new"), undefined);
  99. assert.equal(o.getOption("initialValue"), 8);
  100. o.setOption("initialValue", 7);
  101. assert.equal(o.getOption("opt2"), 7);
  102. config.setDefaultValues("test_object", {
  103. opt1: 1,
  104. forwarded: 2
  105. });
  106. config.resetOptions(o);
  107. assert.equal(o.getOption("opt1"), 1);
  108. assert.equal(o.getOption("forwarded"), 2);
  109. }
  110. };
  111. });
  112. if (typeof module !== "undefined" && module === require.main) {
  113. require("asyncjs").test.testcase(module.exports).exec();
  114. }