-
Notifications
You must be signed in to change notification settings - Fork 7.5k
HTML attributes code hinting filter #2263
Changes from 4 commits
d587f36
7335f94
0aae4e6
3306701
07be375
844c5fe
c48b3ad
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -246,6 +246,92 @@ define(function (require, exports, module) { | |
| var tag = HTMLUtils.getTagInfo(myEditor, pos); | ||
| expect(tag).toEqual(HTMLUtils.createTagInfo()); | ||
| }); | ||
|
|
||
| it("should not find attributes in an empty editor", function () { | ||
| var pos = {"ch": 0, "line": 0}; | ||
| var attrs = HTMLUtils.getTagAttributes(myEditor, pos); | ||
| expect(attrs).toEqual([]); | ||
| }); | ||
|
|
||
| it("should not find attributes before the tag is opened", function () { | ||
| var pos = {"ch": 0, "line": 0}; | ||
| setContentAndUpdatePos(pos, | ||
| ['<html>', '<body>', '<div class="clearfix">'], | ||
| '', '<p id="pid" class="pclass" lang="plang" align="palign" title="">test</p>', | ||
| [ '</div>', '</body>', '</html>']); | ||
| var attrs = HTMLUtils.getTagAttributes(myEditor, pos); | ||
| expect(attrs).toEqual([]); | ||
| }); | ||
|
|
||
| it("should not find attributes if there isn't a valid tag", function () { | ||
| var pos = {"ch": 0, "line": 0}; | ||
| setContentAndUpdatePos(pos, | ||
| ['<html>', '<body>', '<div class="clearfix">'], | ||
| '<', ' id="pid" class="pclass" lang="plang" align="palign" title="">test</p>', | ||
| [ '</div>', '</body>', '</html>']); | ||
| var attrs = HTMLUtils.getTagAttributes(myEditor, pos); | ||
| expect(attrs).toEqual([]); | ||
| }); | ||
|
|
||
| it("should not find attributes after the tag is closed", function () { | ||
| var pos = {"ch": 0, "line": 0}; | ||
| setContentAndUpdatePos(pos, | ||
| ['<html>', '<body>', '<div class="clearfix">'], | ||
| '<p id="pid" class="pclass" lang="plang" align="palign" title="">test</p>', '', | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How about moving
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In that case that would become the same as the one where it "should find all the tag attributes before closing the tag", right? I'll just remove this one then.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm... I thought the result will be empty as the cursor is after the begin tag. ie. after
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The test, as is right now, expects indeed an empty list. I thought you wanted me to pass What would you want to do with this test?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, the test case you're referring to has the cursor before (or to the left of)
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, I see it now. I had totally missed the Nice catch btw. I've changed it and it was returning the list of attributes instead of empty for that case, so I'll commit a fix with the changes. |
||
| [ '</div>', '</body>', '</html>']); | ||
| var attrs = HTMLUtils.getTagAttributes(myEditor, pos); | ||
| expect(attrs).toEqual([]); | ||
| }); | ||
|
|
||
| it("should find all the tag attributes immediately after the tag", function () { | ||
| var pos = {"ch": 0, "line": 0}; | ||
| setContentAndUpdatePos(pos, | ||
| ['<html>', '<body>', '<div class="clearfix">'], | ||
| '<p ', 'id="pid" class="pclass" lang="plang" align="palign" title="ptitle">test</p>', | ||
| [ '</div>', '</body>', '</html>']); | ||
| var attrs = HTMLUtils.getTagAttributes(myEditor, pos); | ||
| expect(attrs.sort()).toEqual(["id", "class", "lang", "align", "title"].sort()); | ||
| }); | ||
|
|
||
| it("should find all the tag attributes before closing the tag", function () { | ||
| var pos = {"ch": 0, "line": 0}; | ||
| setContentAndUpdatePos(pos, | ||
| ['<html>', '<body>', '<div class="clearfix">'], | ||
| '<p id="pid" class="pclass" lang="plang" align="palign" title="ptitle" ', '>test</p>', | ||
| [ '</div>', '</body>', '</html>']); | ||
| var attrs = HTMLUtils.getTagAttributes(myEditor, pos); | ||
| expect(attrs.sort()).toEqual(["id", "class", "lang", "align", "title"].sort()); | ||
| }); | ||
|
|
||
| it("should find all the tag attributes backward and forward", function () { | ||
| var pos = {"ch": 0, "line": 0}; | ||
| setContentAndUpdatePos(pos, | ||
| ['<html>', '<body>', '<div class="clearfix">'], | ||
| '<p id="pid" class="pclass" lang="plang" ', 'align="palign" title="ptitle">test</p>', | ||
| [ '</div>', '</body>', '</html>']); | ||
| var attrs = HTMLUtils.getTagAttributes(myEditor, pos); | ||
| expect(attrs.sort()).toEqual(["id", "class", "lang", "align", "title"].sort()); | ||
| }); | ||
|
|
||
| it("should find valid attributes marked as errors by the tokenizer", function () { | ||
| var pos = {"ch": 0, "line": 0}; | ||
| setContentAndUpdatePos(pos, | ||
| ['<html>', '<body>', '<div class="clearfix">'], | ||
| '<p id="pid" c', ' class="pclass" lang="plang" align="palign" title="ptitle">test</p>', | ||
| [ '</div>', '</body>', '</html>']); | ||
| var attrs = HTMLUtils.getTagAttributes(myEditor, pos); | ||
| expect(attrs.sort()).toEqual(["id", "class", "lang", "align", "title"].sort()); | ||
| }); | ||
|
|
||
| it("should not find attributes in nested tags", function () { | ||
| var pos = {"ch": 0, "line": 0}; | ||
| setContentAndUpdatePos(pos, | ||
| ['<html>', '<body>', '<div class="clearfix">'], | ||
| '<p ', 'id="pid" class="pclass" lang="plang" align="palign" title="ptitle"><span style="sstyle"></span></p>', | ||
| [ '</div>', '</body>', '</html>']); | ||
| var attrs = HTMLUtils.getTagAttributes(myEditor, pos); | ||
| expect(attrs.sort()).toEqual(["id", "class", "lang", "align", "title"].sort()); | ||
| }); | ||
| }); | ||
| }); | ||
| }); | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Our coding guideline is to use double quotes for all strings and the one nested inside then can use a single quote. So can you switch to double-quotes in all your test cases?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, no problem, will fix that.
I actually copy/pasted from one of the tests above and all the existing ones have the quotes inverted. Do you want me to change those as a bonus, or should we let them be for now?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, please do change them if you don't mind.