-
Notifications
You must be signed in to change notification settings - Fork 7.6k
Smallish cleanups to docs & unit tests; improve a few tests #3429
Changes from 6 commits
5dc6489
045fae6
f59be5a
7250b96
8d94d0d
98f23f2
9df7830
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 |
---|---|---|
|
@@ -175,7 +175,7 @@ define(function (require, exports, module) { | |
/** | ||
* Resolves a language ID to a Language object. | ||
* File names have a higher priority than file extensions. | ||
* @param {!string} id Identifier for this language, use only letters a-z or digits 0-9 and _ inbetween (i.e. "cpp", "foo_bar", "c99") | ||
* @param {!string} id Identifier for this language: lowercase letters, digits, and _ separators (e.g. "cpp", "foo_bar", "c99") | ||
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. Strings are not-nullable by default, so 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. I'd prefer to leave this as-is for now -- we're very inconsistent about flagging nullability at all in most docs, so having it marked explicitly (even if matching the default) seems useful since it indicates someone definitely thought about whether it's nullable or not. If we ever do a big sweep and clean up all our JSDocs, it seems safe to start leaving it unspecified when matching the default... but maybe not just yet. One of these days I still want to write an extension that runs Closure on your code to give type safety warnings -- sort of a JSLint/Hint on steroids. I think that would make it much easier for us to actually use Closure annotations properly... As it stands, I bet it's hard to find a file in our codebase that doesn't contain at least one incorrect type annotation :-( 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. We are really inconsistent about flagging nullability, but I started to fix them on some files I updated and I know others did too. Not a big thing, we can fix this another time. It would be nice to have a Closure warning plugin. |
||
* @return {Language} The language with the provided identifier or undefined | ||
*/ | ||
function getLanguage(id) { | ||
|
@@ -322,7 +322,7 @@ define(function (require, exports, module) { | |
|
||
/** | ||
* Sets the identifier for this language or prints an error to the console. | ||
* @param {!string} id Identifier for this language, use only letters a-z or digits 0-9, and _ inbetween (i.e. "cpp", "foo_bar", "c99") | ||
* @param {!string} id Identifier for this language: lowercase letters, digits, and _ separators (e.g. "cpp", "foo_bar", "c99") | ||
* @return {boolean} Whether the ID was valid and set or not | ||
*/ | ||
Language.prototype._setId = function (id) { | ||
|
@@ -350,7 +350,7 @@ define(function (require, exports, module) { | |
|
||
/** | ||
* Sets the human-readable name of this language or prints an error to the console. | ||
* @param {!string} name Human-readable name of the language, as it's commonly referred to (i.e. "C++") | ||
* @param {!string} name Human-readable name of the language, as it's commonly referred to (e.g. "C++") | ||
* @return {boolean} Whether the name was valid and set or not | ||
*/ | ||
Language.prototype._setName = function (name) { | ||
|
@@ -373,7 +373,7 @@ define(function (require, exports, module) { | |
/** | ||
* Loads a mode and sets it for this language. | ||
* | ||
* @param {string|Array.<string>} mode CodeMirror mode (i.e. "htmlmixed"), optionally with a MIME mode defined by that mode ["clike", "text/x-c++src"] | ||
* @param {string|Array.<string>} mode CodeMirror mode (e.g. "htmlmixed"), optionally with a MIME mode defined by that mode ["clike", "text/x-c++src"] | ||
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. This should be |
||
* Unless the mode is located in thirdparty/CodeMirror2/mode/<name>/<name>.js, you need to first load it yourself. | ||
* | ||
* @return {$.Promise} A promise object that will be resolved when the mode is loaded and set | ||
|
@@ -519,7 +519,7 @@ define(function (require, exports, module) { | |
/** | ||
* Sets the prefixes to use for line comments in this language or prints an error to the console. | ||
* @param {!string|Array.<string>} prefix Prefix string or an array of prefix strings | ||
* to use for line comments (i.e. "//" or ["//", "#"]) | ||
* to use for line comments (e.g. "//" or ["//", "#"]) | ||
* @return {boolean} Whether the syntax was valid and set or not | ||
*/ | ||
Language.prototype.setLineCommentSyntax = function (prefix) { | ||
|
@@ -637,13 +637,14 @@ define(function (require, exports, module) { | |
/** | ||
* Defines a language. | ||
* | ||
* @param {!string} id Unique identifier for this language, use only letters a-z or digits 0-9, and _ inbetween (i.e. "cpp", "foo_bar", "c99") | ||
* @param {!string} id Unique identifier for this language: lowercase letters, digits, and _ separators (e.g. "cpp", "foo_bar", "c99") | ||
* @param {!Object} definition An object describing the language | ||
* @param {!string} definition.name Human-readable name of the language, as it's commonly referred to (i.e. "C++") | ||
* @param {Array.<string>} definition.fileExtensions List of file extensions used by this language (i.e. ["php", "php3"]) | ||
* @param {Array.<string>} definition.blockComment Array with two entries defining the block comment prefix and suffix (i.e. ["<!--", "-->"]) | ||
* @param {string|Array.<string>} definition.lineComment Line comment prefixes (i.e. "//" or ["//", "#"]) | ||
* @param {string|Array.<string>} definition.mode CodeMirror mode (i.e. "htmlmixed"), optionally with a MIME mode defined by that mode ["clike", "text/x-c++src"] | ||
* @param {!string} definition.name Human-readable name of the language, as it's commonly referred to (e.g. "C++") | ||
* @param {Array.<string>} definition.fileExtensions List of file extensions used by this language (e.g. ["php", "php3"] or ["coffee.md"] - may contain dots) | ||
* @param {Array.<string>} definition.fileNames List of exact file names (e.g. ["Makefile"] or ["package.json]). Higher precedence than file extension. | ||
* @param {Array.<string>} definition.blockComment Array with two entries defining the block comment prefix and suffix (e.g. ["<!--", "-->"]) | ||
* @param {string|Array.<string>} definition.lineComment Line comment prefixes (e.g. "//" or ["//", "#"]) | ||
* @param {string|Array.<string>} definition.mode CodeMirror mode (e.g. "htmlmixed"), optionally with a MIME mode defined by that mode ["clike", "text/x-c++src"] | ||
* Unless the mode is located in thirdparty/CodeMirror2/mode/<name>/<name>.js, you need to first load it yourself. | ||
* | ||
* @return {$.Promise} A promise object that will be resolved with a Language object | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -253,13 +253,12 @@ define(function (require, exports, module) { | |
* Creates a new general purpose modal dialog using the default template and the template variables given | ||
* as parameters as described. | ||
* | ||
* @param {string} dlgClass A class name identifier for the dialog. | ||
* @param {string=} title The title of the dialog. Can contain HTML markup. If unspecified, the title | ||
* in the JSON file is used unchanged. | ||
* @param {string=} message The message to display in the dialog. Can contain HTML markup. If | ||
* unspecified, the message in the JSON file is used. | ||
* @param {string} dlgClass A class name identifier for the dialog. Typically one of DefaultDialogs.* | ||
* @param {string=} title The title of the dialog. Can contain HTML markup. Defaults to "". | ||
* @param {string=} message The message to display in the dialog. Can contain HTML markup. Defaults to "". | ||
* @param {Array.<{className: string, id: string, text: string>=} buttons An array of buttons where each button | ||
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. I missed a |
||
* has a class, id and text property. The id is used in "data-button-id". It defaults to an Ok button | ||
* has a class, id and text property. The id is used in "data-button-id". Defaults to a single Ok button. | ||
* Typically className is one of DIALOG_BTN_CLASS_*, id is one of DIALOG_BTN_* | ||
* @return {Dialog} | ||
*/ | ||
function showModalDialog(dlgClass, title, message, buttons) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -973,10 +973,10 @@ define(function (require, exports, module) { | |
|
||
// Braces inside string; string inside rule (not inside selector) | ||
css = "a::after { content: ' {' attr(href) '}'; } \n" + | ||
".foo { color:red } \n" + | ||
"a::after { content: \" {\" attr(href) \"}\"; } \n" + | ||
"li::before { content: \"} h4 { color:black }\"; } \n" + | ||
"div { color:green }"; | ||
".foo { color:red } \n" + | ||
"a::after { content: \" {\" attr(href) \"}\"; } \n" + | ||
"li::before { content: \"} h4 { color:black }\"; } \n" + | ||
"div { color:green }"; | ||
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. I just realized that these new JSLint errors are because we are now using an older version of JSLint that before and checked that these aren't errors on a newer version. So we probably shouldn't fix anymore of these errors and I can revert these changes in #4557. 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. Aha, that explains why no one noticed the errors in this file earlier. Good to know! 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. Noticed it when I saw a similar error in EditorCommandHandlers, which I know that didn't had JSLint errors before. |
||
|
||
result = match(css, { tag: "a" }); | ||
expect(result.length).toBe(2); | ||
|
@@ -999,7 +999,7 @@ define(function (require, exports, module) { | |
expect(result.length).toBe(1); | ||
|
||
css = "@import \"null?\\\"{\"; \n" + // a real-world CSS hack similar to the above case | ||
"div { color: red }"; | ||
"div { color: red }"; | ||
result = match(css, { tag: "div" }); | ||
expect(result.length).toBe(1); | ||
|
||
|
@@ -1051,9 +1051,9 @@ define(function (require, exports, module) { | |
expect(result.length).toBe(1); | ||
|
||
css = ".foo\n" + | ||
"{\n" + | ||
" color: red;\n" + | ||
"}"; | ||
"{\n" + | ||
" color: red;\n" + | ||
"}"; | ||
result = match(css, { clazz: "foo" }); | ||
expect(result.length).toBe(1); | ||
}); | ||
|
@@ -1411,29 +1411,23 @@ define(function (require, exports, module) { | |
var testPath = SpecRunnerUtils.getTestPath("/spec/CSSUtils-test-files"), | ||
CSSUtils, | ||
DocumentManager, | ||
FileViewController, | ||
ProjectManager, | ||
brackets; | ||
FileViewController; | ||
|
||
beforeEach(function () { | ||
SpecRunnerUtils.createTestWindowAndRun(this, function (testWindow) { | ||
// Load module instances from brackets.test | ||
brackets = testWindow.brackets; | ||
CSSUtils = testWindow.brackets.test.CSSUtils; | ||
DocumentManager = testWindow.brackets.test.DocumentManager; | ||
FileViewController = testWindow.brackets.test.FileViewController; | ||
ProjectManager = testWindow.brackets.test.ProjectManager; | ||
|
||
SpecRunnerUtils.loadProjectInTestWindow(testPath); | ||
}); | ||
}); | ||
|
||
afterEach(function () { | ||
brackets = null; | ||
CSSUtils = null; | ||
DocumentManager = null; | ||
FileViewController = null; | ||
ProjectManager = null; | ||
SpecRunnerUtils.closeTestWindow(); | ||
}); | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -56,7 +56,7 @@ define(function (require, exports, module) { | |
} | ||
|
||
describe("Editor", function () { | ||
var defaultContent = 'Brackets is going to be awesome!\n'; | ||
var defaultContent = "Brackets is going to be awesome!\n"; | ||
var myDocument, myEditor; | ||
|
||
function createTestEditor(content, languageId) { | ||
|
@@ -110,42 +110,14 @@ define(function (require, exports, module) { | |
myEditor._codeMirror.setValue("new content"); | ||
expect(changeFired).toBe(true); | ||
}); | ||
|
||
}); | ||
|
||
describe("File extension to mode mapping", function () { | ||
|
||
it("should switch to the HTML mode for files ending in .html", function () { | ||
// verify editor content | ||
var mode = LanguageManager.getLanguageForPath("c:/only/testing/the/path.html").getMode(); | ||
expect(mode).toSpecifyModeNamed("text/x-brackets-html"); | ||
}); | ||
|
||
it("should switch modes for UNIX absolute path", function () { | ||
// verify editor content | ||
var mode = LanguageManager.getLanguageForPath("/only/testing/the/path.css").getMode(); | ||
expect(mode).toSpecifyModeNamed(langNames.css.mode); | ||
}); | ||
|
||
it("should switch modes for relative path", function () { | ||
// verify editor content | ||
var mode = LanguageManager.getLanguageForPath("only/testing/the/path.css").getMode(); | ||
expect(mode).toSpecifyModeNamed(langNames.css.mode); | ||
}); | ||
|
||
it("should accept just a file name too", function () { | ||
// verify editor content | ||
var mode = LanguageManager.getLanguageForPath("path.js").getMode(); | ||
expect(mode).toSpecifyModeNamed(langNames.javascript.mode); | ||
}); | ||
|
||
it("should default to plain text for unknown file extensions", function () { | ||
// verify editor content | ||
var mode = LanguageManager.getLanguageForPath("test.foo").getMode(); | ||
it("should set mode based on Document language", function () { | ||
createTestEditor(defaultContent, "html"); | ||
|
||
// "unknown" mode uses it's MIME type instead | ||
expect(mode).toBe("text/plain"); | ||
var htmlLanguage = LanguageManager.getLanguage("html"); | ||
expect(myEditor.getModeForDocument()).toBe(htmlLanguage.getMode()); | ||
}); | ||
|
||
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 tests above were just testing LanguageManager functionality. I simplified & moved those into LanguageManager-test, and in their place added a single test here to make sure the Document's language actually carries through to the Editor's mode (which the old tests never checked). |
||
}); | ||
|
||
describe("Focus", function () { | ||
|
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.
I had to remove this early-exit optimization for now. I doubt it has any discernible impact, but if I'm wrong we can reintroduce it once pull #3117 lands.
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.
Now that #3117 has landed, this could use
CollectionUtils.some
.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.
I think in retrospect I'd actually prefer to leave it using
CollectonUtils.forEach()
, since it keeps the code a little simpler -- and there doesn't seem to be any real need to optimize here.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.
If there isn't nothing to optimize, then we can leave it like this. If not switching to
CollectionUtils.some
is as easy as addingreturn !isFolder
inside the if andreturn false
outside.