add unit test for #375

This commit is contained in:
Fabian Jakobs 2011-08-10 11:25:33 +02:00
commit 53ab1d5dbe
2 changed files with 38 additions and 13 deletions

View file

@ -352,10 +352,11 @@ var Text = function(parentEl) {
} else if (c == "\u3000") {
// U+3000 is both invisible AND full-width, so must be handled uniquely
var classToUse = self.showInvisibles ? "ace_cjk ace_invisible" : "ace_cjk";
var space = self.showInvisibles ? self.SPACE_CHAR : "";
screenColumn += 1;
return "<span class='" + classToUse + "' style='width:" +
(self.config.characterWidth * 2) +
"px'>" + c + "</span>";
"px'>" + space + "</span>";
} else if (c.match(/[\v\f \u00a0\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u200b\u2028\u2029\u3000]/)) {
if (self.showInvisibles) {
var space = new Array(c.length+1).join(self.SPACE_CHAR);
@ -449,7 +450,8 @@ var Text = function(parentEl) {
else
stringBuilder.push("<span class='ace_invisible'>" + this.EOF_CHAR + "</span>");
}
stringBuilder.push("</div>");
if (!onlyContents)
stringBuilder.push("</div>");
};
this.$renderLine = function(stringBuilder, row, tokens, onlyContents) {

View file

@ -49,29 +49,52 @@ var JavaScriptMode = require("ace/mode/javascript").Mode;
module.exports = {
"test: render line with hard tabs should render the same as lines with soft tabs" : function() {
var session = new EditSession("a\ta\ta\t\na a a \n");
session.setMode(new JavaScriptMode());
var textLayer = new TextLayer(document.createElement("div"));
textLayer.setSession(session);
textLayer.$computeTabString();
textLayer.config = {
setUp: function(next) {
this.session = new EditSession("");
this.session.setMode(new JavaScriptMode());
this.textLayer = new TextLayer(document.createElement("div"));
this.textLayer.setSession(this.session);
this.textLayer.config = {
characterWidth: 10,
lineHeight: 20
};
next()
},
"test: render line with hard tabs should render the same as lines with soft tabs" : function() {
this.session.setValue("a\ta\ta\t\na a a \n");
this.textLayer.$computeTabString();
// row with hard tabs
var row = 0;
var tokens = session.getTokens(row, row)[0].tokens;
var tokens = this.session.getTokens(row, row)[0].tokens;
var stringBuilder = [];
textLayer.$renderLine(stringBuilder, row, tokens);
this.textLayer.$renderLine(stringBuilder, row, tokens);
// row with soft tabs
row = 1;
tokens = session.getTokens(row, row)[0].tokens;
tokens = this.session.getTokens(row, row)[0].tokens;
var stringBuilder2 = [];
textLayer.$renderLine(stringBuilder2, row, tokens);
this.textLayer.$renderLine(stringBuilder2, row, tokens);
assert.equal(stringBuilder.join(""), stringBuilder2.join(""));
},
"test rendering width of ideographic space (U+3000)" : function() {
this.session.setValue("\u3000");
var tokens = this.session.getTokens(0, 0)[0].tokens;
var stringBuilder = [];
this.textLayer.$renderLine(stringBuilder, 0, tokens, true);
assert.equal(stringBuilder.join(""), "<span class='ace_cjk' style='width:20px'></span>");
this.textLayer.setShowInvisibles(true);
var stringBuilder = [];
this.textLayer.$renderLine(stringBuilder, 0, tokens, true);
assert.equal(
stringBuilder.join(""),
"<span class='ace_cjk ace_invisible' style='width:20px'>" + this.textLayer.SPACE_CHAR + "</span>"
+ "<span class='ace_invisible'>&para;</span>"
);
}
};