pythonic_test.js 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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. define(function(require, exports, module) {
  33. "use strict";
  34. var PythonMode = require("../python").Mode;
  35. var EditSession = require("../../edit_session").EditSession;
  36. var assert = require("../../test/assertions");
  37. module.exports = {
  38. "test: bracket folding": function() {
  39. var session = new EditSession([
  40. '[ ',
  41. 'stuff',
  42. ']',
  43. '[ ',
  44. '{ ',
  45. '[ #-'
  46. ]);
  47. var mode = new PythonMode();
  48. session.setFoldStyle("markbeginend");
  49. session.setMode(mode);
  50. assert.equal(session.getFoldWidget(0), "start");
  51. assert.equal(session.getFoldWidget(1), "");
  52. assert.equal(session.getFoldWidget(2), "");
  53. assert.equal(session.getFoldWidget(3), "start");
  54. assert.equal(session.getFoldWidget(4), "start");
  55. assert.equal(session.getFoldWidget(5), "");
  56. assert.range(session.getFoldWidgetRange(0), 0, 1, 2, 0);
  57. assert.equal(session.getFoldWidgetRange(3), null);
  58. assert.equal(session.getFoldWidgetRange(5), null);
  59. },
  60. "test: indentation folding": function() {
  61. var session = new EditSession([
  62. 'def a: #',
  63. '',
  64. ' b:',
  65. ' c',
  66. ' ',
  67. ' c',
  68. '',
  69. ' ',
  70. ''
  71. ]);
  72. var mode = new PythonMode();
  73. session.setFoldStyle("markbeginend");
  74. session.setMode(mode);
  75. assert.equal(session.getFoldWidget(0), "start");
  76. assert.equal(session.getFoldWidget(1), "");
  77. assert.equal(session.getFoldWidget(2), "start");
  78. assert.range(session.getFoldWidgetRange(0), 0, 6, 5, 3);
  79. assert.range(session.getFoldWidgetRange(2), 2, 3, 5, 3);
  80. }
  81. };
  82. });
  83. if (typeof module !== "undefined" && module === require.main)
  84. require("asyncjs").test.testcase(module.exports).exec();