|
| 1 | +if (typeof process !== "undefined") { |
| 2 | + require("amd-loader"); |
| 3 | + require("../test/mockdom"); |
| 4 | +} |
| 5 | + |
| 6 | +define(function(require, exports, module) { |
| 7 | +"use strict"; |
| 8 | + |
| 9 | +var assert = require("assert"); |
| 10 | +var EditSession = require("../edit_session").EditSession; |
| 11 | +var whitespace = require("./whitespace"); |
| 12 | + |
| 13 | +// Execution ORDER: test.setUpSuite, setUp, testFn, tearDown, test.tearDownSuite |
| 14 | +module.exports = { |
| 15 | + timeout: 10000, |
| 16 | + |
| 17 | + "test tab detection": function(next) { |
| 18 | + var s = new EditSession([ |
| 19 | + "define({", |
| 20 | + "\tfoo:1,", |
| 21 | + "\tbar:2,", |
| 22 | + "\tbaz:{,", |
| 23 | + "\t\tx:3", |
| 24 | + "\t}", |
| 25 | + "})" |
| 26 | + ]); |
| 27 | + |
| 28 | + var indent = whitespace.$detectIndentation(s.doc.$lines); |
| 29 | + assert.equal(indent.ch, "\t"); |
| 30 | + assert.equal(indent.length, undefined); |
| 31 | + |
| 32 | + s.insert({row: 0, column: 0}, " "); |
| 33 | + indent = whitespace.$detectIndentation(s.doc.$lines); |
| 34 | + assert.equal(indent.ch, "\t"); |
| 35 | + assert.equal(indent.length, 4); |
| 36 | + |
| 37 | + s.setValue(""); |
| 38 | + indent = whitespace.$detectIndentation(s.doc.$lines); |
| 39 | + assert.ok(!indent); |
| 40 | + |
| 41 | + next(); |
| 42 | + }, |
| 43 | + |
| 44 | + "test empty session": function(next) { |
| 45 | + var s = new EditSession([ |
| 46 | + "define({", |
| 47 | + "foo:1,", |
| 48 | + "})" |
| 49 | + ]); |
| 50 | + var indent = whitespace.$detectIndentation(s.doc.$lines); |
| 51 | + assert.ok(!indent); |
| 52 | + s.insert({row: 1, column: 0}, " x\n "); |
| 53 | + |
| 54 | + indent = whitespace.$detectIndentation(s.doc.$lines); |
| 55 | + assert.equal(indent.ch, " "); |
| 56 | + assert.equal(indent.length, 4); |
| 57 | + |
| 58 | + next(); |
| 59 | + }, |
| 60 | + |
| 61 | + "!test one line": function(next) { |
| 62 | + var s = new EditSession([ |
| 63 | + "define({", |
| 64 | + " foo:1,", |
| 65 | + "})" |
| 66 | + ]); |
| 67 | + var indent = whitespace.$detectIndentation(s.doc.$lines); |
| 68 | + assert.equal(indent.ch, " "); |
| 69 | + assert.equal(indent.length, 4); |
| 70 | + |
| 71 | + next(); |
| 72 | + }, |
| 73 | + |
| 74 | + "test 1 width indents": function(next) { |
| 75 | + var s = new EditSession([ |
| 76 | + "define({", |
| 77 | + " foo:1,", |
| 78 | + "})", |
| 79 | + "define({", |
| 80 | + " bar:1,", |
| 81 | + "})", |
| 82 | + " t", |
| 83 | + " t", |
| 84 | + " t", |
| 85 | + " t", |
| 86 | + " t", |
| 87 | + " t", |
| 88 | + " t", |
| 89 | + " t" |
| 90 | + ]); |
| 91 | + var indent = whitespace.$detectIndentation(s.doc.$lines); |
| 92 | + // assert.equal(indent.ch, " "); |
| 93 | + // assert.equal(indent.length, 4); |
| 94 | + |
| 95 | + s = new EditSession([ |
| 96 | + "{", |
| 97 | + " foo:1,", |
| 98 | + " bar: {", |
| 99 | + " baz:2", |
| 100 | + " }", |
| 101 | + "}" |
| 102 | + ]); |
| 103 | + indent = whitespace.$detectIndentation(s.doc.$lines); |
| 104 | + assert.equal(indent.ch, " "); |
| 105 | + assert.equal(indent.length, 1); |
| 106 | + |
| 107 | + next(); |
| 108 | + }, |
| 109 | + |
| 110 | +}; |
| 111 | + |
| 112 | +}); |
| 113 | + |
| 114 | +if (typeof module !== "undefined" && module === require.main) { |
| 115 | + require("asyncjs").test.testcase(module.exports).exec(); |
| 116 | +} |
0 commit comments