diff --git a/src/extensions/default/HTMLCodeHints/unittests.js b/src/extensions/default/HTMLCodeHints/unittests.js index 79a784b230e..06ed7cdb5ab 100644 --- a/src/extensions/default/HTMLCodeHints/unittests.js +++ b/src/extensions/default/HTMLCodeHints/unittests.js @@ -141,6 +141,24 @@ define(function (require, exports, module) { expect(hintList.indexOf("div")).toBe(-1); expect(hintList.indexOf("span")).not.toBe(-1); }); + + it("should list hints between '<' and some trailing spaces", function () { // (bug #1515) + // Replace line 9 with a complete div tag and insert a blank line and the closing div tag. + testDocument.replaceRange("
\n \n
", { line: 9, ch: 2 }); + expect(testDocument.getLine(10)).toBe(" "); + + // Insert a < on line 10 + testDocument.replaceRange("<", { line: 10, ch: 0 }); + testEditor.setCursorPos({ line: 10, ch: 1 }); // cursor between < and some trailing whitespaces + var hintList = expectHints(HTMLCodeHints.tagHintProvider); + verifyTagHints(hintList); + + // Replace '< ' on line 10 with '<\t' + testDocument.replaceRange("<\t", { line: 10, ch: 0 }, { line: 10, ch: 2 }); + testEditor.setCursorPos({ line: 10, ch: 1 }); // cursor between < and some trailing whitespaces + hintList = expectHints(HTMLCodeHints.tagHintProvider); + verifyTagHints(hintList); + }); }); describe("Attribute name hint provider", function () { @@ -259,12 +277,45 @@ define(function (require, exports, module) { expectNoHints(HTMLCodeHints.attrHintProvider); }); - it("should NOT list hints between two tags", function () { // (bug #1510) + it("should NOT list hints between begin 'div' and end 'div' tag", function () { // (bug #1510) // replace line 9 with a complete div tag and insert a blank line and the closing div tag. - testDocument.replaceRange("
\n \n
", { line: 9, ch: 2 }); + testDocument.replaceRange("
\n \n
", { line: 9, ch: 2 }); testEditor.setCursorPos({ line: 10, ch: 2 }); // cursor between whitespaces on the newly inserted blank line expectNoHints(HTMLCodeHints.attrHintProvider); + + testEditor.setCursorPos({ line: 9, ch: 7 }); // cursor to the right of
+ expectNoHints(HTMLCodeHints.attrHintProvider); + + testEditor.setCursorPos({ line: 11, ch: 2 }); // cursor to the left of
+ expectNoHints(HTMLCodeHints.attrHintProvider); + }); + + it("should NOT list hints between an empty tag and 'body' end tag", function () { // (bug #1519) + // replace line 9 with an input tag and insert two extra blank lines with some whitespaces. + testDocument.replaceRange("\n \n ", { line: 9, ch: 2 }, { line: 9, ch: 7 }); + + // Set cursor between whitespaces on one of the newly inserted blank lines. + testEditor.setCursorPos({ line: 11, ch: 2 }); + expectNoHints(HTMLCodeHints.attrHintProvider); + }); + + it("should NOT list hints between the 'body' begin tag and 'h1' begin tag", function () { // (bug #1519) + // Insert two blank lines with some whitespaces before line 5. + testDocument.replaceRange("\n \n ", { line: 5, ch: 0 }); + + // Set cursor between whitespaces on one of the newly inserted blank lines. + testEditor.setCursorPos({ line: 7, ch: 2 }); + expectNoHints(HTMLCodeHints.attrHintProvider); + }); + + it("should NOT list hints between the 'h1' end tag and 'h3' begin tag", function () { // (bug #1519) + // Insert two blank lines with some whitespaces before line 5. + testDocument.replaceRange("\n \n ", { line: 6, ch: 0 }); + + // Set cursor between whitespaces on one of the newly inserted blank lines. + testEditor.setCursorPos({ line: 8, ch: 2 }); + expectNoHints(HTMLCodeHints.attrHintProvider); }); it("should NOT list hints after an HTML comment", function () { // (bug #1440) @@ -497,7 +548,7 @@ define(function (require, exports, module) { expectCursorAt({ line: 9, ch: 16 }); // cursor after the closing quote }); - it("should insert the selected attribute value with the closing quote", function () { + it("should insert the selected attribute value WITHOUT begin or end quote", function () { testDocument.replaceRange("dir=", { line: 9, ch: 7 }); // insert dir= after
" || ctx.token.string === "/>" || + (ctx.token.string.charAt(0) === "<" && ctx.token.string.charAt(1) === "/"))) { + return createTagInfo(); + } + // If it wasn't an attr value, assume it was an empty attr (ie. attr with no value) if (!tagInfo.tagName) { tagInfo = _getTagInfoStartingFromAttrName(ctx, true); @@ -406,12 +413,12 @@ define(function (require, exports, module) { if (ctx.token.className === "tag") { // Check if the user just typed a white space after "<" that made an existing tag invalid. - if (ctx.token.string.indexOf("< ") === 0) { + if (ctx.token.string.match(/^<\s+/) && offset !== 1) { return createTagInfo(); } // Check to see if this is the closing of a tag (either the start or end) - if (ctx.token.string === ">" || + if (ctx.token.string === ">" || ctx.token.string === "/>" || (ctx.token.string.charAt(0) === "<" && ctx.token.string.charAt(1) === "/")) { return createTagInfo(); }