Skip to content

Commit

Permalink
Added some more unit tests + cleanup fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
WebsiteDeveloper committed May 1, 2013
1 parent 26784f3 commit 36f2e54
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 34 deletions.
@@ -1,30 +1,44 @@
<p>
<!-- Should show hints -->
Test&
</p>
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<!-- Should show hints -->
<p>
Test&
</p>

<!-- Should show hints -->
<p>
Test&#33; &
</p>
<!-- Should show hints -->
<p>
Test&#33; &
</p>

<!-- Should show hints when cursor inside Entity -->
<p>
Test&acute;
</p>
<!-- Should show hints when cursor inside Entity -->
<p>
Test&acute;
</p>

<!-- Shouldn't show hints inside an opening tag-->
<p&></p>
<!-- Shouldn't show hints inside an opening tag-->
<p&></p>

<!-- Shouldn't show hints inside a closing tag-->
<p></p&>
<!-- Shouldn't show hints inside a closing tag-->
<p></p&>

<!-- Should show hints when semi-colon on the same line -->
<p>
Test ; &
</p>
<!-- Should show hints when semi-colon on the same line -->
<p>
Test ; &
</p>

<!-- Should not hint for & in attribute name -->
<p & ></p>

<!-- Should not hint for & in attribute value -->
<p title="&"></p>

<!-- Should show hints when cursor inside Entity -->
<p>
Test&
</p>
<!-- Should not hint for & in url -->
<a href="https://github.com/adobe/brackets/issues?labels=low+priority&page=1&state=open">link</a>

<!-- Should show multiple hints in same line -->
<p>This &amp; that &amp; the other</p>
</body>
</html>
48 changes: 38 additions & 10 deletions src/extensions/default/HtmlEntityCodeHints/unittests.js
Expand Up @@ -56,39 +56,67 @@ define(function (require, exports, module) {
}

it("should show hints when in Text in paragraph", function () {
testEditorAndDoc.editor.setCursorPos({line: 2, ch: 9});
testEditorAndDoc.editor.setCursorPos({line: 7, ch: 17});

expectHints(hintProvider);
});

it("should show hints when another entity is in the same line", function () {
testEditorAndDoc.editor.setCursorPos({line: 7, ch: 15});
testEditorAndDoc.editor.setCursorPos({line: 12, ch: 23});

expectHints(hintProvider);
});

it("should show hints when cursor inside entity", function () {
testEditorAndDoc.editor.setCursorPos({line: 12, ch: 11});
testEditorAndDoc.editor.setCursorPos({line: 17, ch: 19});

var hints = expectHints(hintProvider);
expect(hints).toEqual(["&amp;acirc; <span class='entity-display-character'>&acirc;</span>",
"&amp;acute; <span class='entity-display-character'>&acute;</span>"]);
});

it("shouldn't show hints when inside an opening tag", function () {
testEditorAndDoc.editor.setCursorPos({line: 16, ch: 3});
testEditorAndDoc.editor.setCursorPos({line: 21, ch: 11});

expectNoHints(hintProvider);
});

it("shouldn't show hints when inside a closing tag", function () {
testEditorAndDoc.editor.setCursorPos({line: 19, ch: 7});
testEditorAndDoc.editor.setCursorPos({line: 24, ch: 15});

expectNoHints(hintProvider);
});

it("should show hints when semi-colon on the same line", function () {
testEditorAndDoc.editor.setCursorPos({line: 23, ch: 13});
testEditorAndDoc.editor.setCursorPos({line: 28, ch: 21});

expectHints(hintProvider);
});

it("shouldn't show hints in attribute name", function () {
testEditorAndDoc.editor.setCursorPos({line: 32, ch: 12});

expectNoHints(hintProvider);
});

it("shouldn't show hints in attribute value", function () {
testEditorAndDoc.editor.setCursorPos({line: 35, ch: 19});

expectNoHints(hintProvider);
});

it("shouldn't show hints in url", function () {
testEditorAndDoc.editor.setCursorPos({line: 38, ch: 78});

expectNoHints(hintProvider);
});

it("should show multiple hints in the same line", function () {
testEditorAndDoc.editor.setCursorPos({line: 41, ch: 17});

expectHints(hintProvider);

testEditorAndDoc.editor.setCursorPos({line: 41, ch: 29});

expectHints(hintProvider);
});
Expand All @@ -99,19 +127,19 @@ define(function (require, exports, module) {
});

it("should replace entity with hint if inside entity", function () {
testEditorAndDoc.editor.setCursorPos({line: 12, ch: 11});
testEditorAndDoc.editor.setCursorPos({line: 17, ch: 19});

var hints = expectHints(hintProvider);
hintProvider.insertHint(hints[0]);
expect(testEditorAndDoc.editor.document.getRange({line: 12, ch: 8}, {line: 12, ch: 15})).toEqual("&acirc;");
expect(testEditorAndDoc.editor.document.getRange({line: 17, ch: 16}, {line: 17, ch: 23})).toEqual("&acirc;");
});

it("should place cursor at the end of the replaced entity", function () {
testEditorAndDoc.editor.setCursorPos({line: 12, ch: 11});
testEditorAndDoc.editor.setCursorPos({line: 17, ch: 19});

var hints = expectHints(hintProvider);
hintProvider.insertHint(hints[0]);
expect(testEditorAndDoc.editor.getCursorPos()).toEqual({line: 12, ch: 15});
expect(testEditorAndDoc.editor.getCursorPos()).toEqual({line: 17, ch: 23});
});
});
});
Expand Down

1 comment on commit 36f2e54

@redmunds
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes so far look good. I thought of 2 more tests for issues found during feature development:

  1. Verify that &#... entities are sorted numerically (not alphabetically).
  2. Test for case that tgriggered this issue: Code hints broken for rest of line after HTML entity adobe/brackets#3339

Please sign in to comment.