Skip to content
This repository has been archived by the owner on Sep 6, 2021. It is now read-only.

Commit

Permalink
Merge pull request #3429 from adobe/pflynn/unit-test-cleanups
Browse files Browse the repository at this point in the history
Smallish cleanups to docs & unit tests; improve a few tests
  • Loading branch information
TomMalbran committed Jul 30, 2013
2 parents 25ab1e8 + 9df7830 commit a02f49b
Show file tree
Hide file tree
Showing 12 changed files with 264 additions and 164 deletions.
49 changes: 19 additions & 30 deletions src/document/DocumentManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -817,43 +817,32 @@ define(function (require, exports, module) {
* @param {boolean} isFolder True if path is a folder; False if it is a file.
*/
function notifyPathNameChanged(oldName, newName, isFolder) {
var i, path;

// Update open documents. This will update _currentDocument too, since
// the current document is always open.
var keysToDelete = [];
for (path in _openDocuments) {
if (_openDocuments.hasOwnProperty(path)) {
if (FileUtils.isAffectedWhenRenaming(path, oldName, newName, isFolder)) {
var doc = _openDocuments[path];

// Copy value to new key
var newKey = path.replace(oldName, newName);
_openDocuments[newKey] = doc;

keysToDelete.push(path);

// Update document file
FileUtils.updateFileEntryPath(doc.file, oldName, newName, isFolder);
doc._notifyFilePathChanged();

if (!isFolder) {
// If the path name is a file, there can only be one matched entry in the open document
// list, which we just updated. Break out of the for .. in loop.
break;
}
}
CollectionUtils.forEach(_openDocuments, function (doc, path) {
if (FileUtils.isAffectedWhenRenaming(path, oldName, newName, isFolder)) {
// Copy value to new key
var newKey = path.replace(oldName, newName);
_openDocuments[newKey] = doc;

keysToDelete.push(path);

// Update document file
FileUtils.updateFileEntryPath(doc.file, oldName, newName, isFolder);
doc._notifyFilePathChanged();
}
}
});

// Delete the old keys
for (i = 0; i < keysToDelete.length; i++) {
delete _openDocuments[keysToDelete[i]];
}
keysToDelete.forEach(function (fullPath) {
delete _openDocuments[fullPath];
});

// Update working set
for (i = 0; i < _workingSet.length; i++) {
FileUtils.updateFileEntryPath(_workingSet[i], oldName, newName, isFolder);
}
_workingSet.forEach(function (fileEntry) {
FileUtils.updateFileEntryPath(fileEntry, oldName, newName, isFolder);
});

// Send a "fileNameChanged" event. This will trigger the views to update.
$(exports).triggerHandler("fileNameChange", [oldName, newName]);
Expand Down
3 changes: 3 additions & 0 deletions src/editor/EditorManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,9 @@ define(function (require, exports, module) {
var editor = document._masterEditor;

if (!editor) {
if (!(document instanceof DocumentManager.Document)) {
throw new Error("_destroyEditorIfUnneeded() should be passed a Document");
}
return;
}

Expand Down
5 changes: 2 additions & 3 deletions src/extensions/default/HTMLCodeHints/unittests.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ define(function (require, exports, module) {
CodeHintManager = brackets.getModule("editor/CodeHintManager"),
HTMLCodeHints = require("main");

describe("HTML Attribute Hinting", function () {
describe("HTML Code Hinting", function () {

var defaultContent = "<!doctype html>\n" +
"<html>\n" +
Expand All @@ -49,7 +49,6 @@ define(function (require, exports, module) {
"</body>\n" +
"</html>\n";

var testWindow;
var testDocument, testEditor;

beforeEach(function () {
Expand Down Expand Up @@ -690,5 +689,5 @@ define(function (require, exports, module) {
});


}); // describe("HTML Attribute Hinting"
}); // describe("HTML Code Hinting"
});
29 changes: 15 additions & 14 deletions src/language/LanguageManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -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")
* @return {Language} The language with the provided identifier or undefined
*/
function getLanguage(id) {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand All @@ -373,9 +373,9 @@ 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"]
* Unless the mode is located in thirdparty/CodeMirror2/mode/<name>/<name>.js, you need to first load it yourself.
*
* @param {(string|Array.<string>)} mode CodeMirror mode (e.g. "htmlmixed"), optionally paired with a MIME mode defined by
* that mode (e.g. ["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 when the mode is loaded and set
*/
Language.prototype._loadAndSetMode = function (mode) {
Expand Down Expand Up @@ -518,8 +518,8 @@ 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 ["//", "#"])
* @param {!(string|Array.<string>)} prefix Prefix string or an array of prefix strings
* to use for line comments (e.g. "//" or ["//", "#"])
* @return {boolean} Whether the syntax was valid and set or not
*/
Language.prototype.setLineCommentSyntax = function (prefix) {
Expand Down Expand Up @@ -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
Expand Down
13 changes: 6 additions & 7 deletions src/widgets/Dialogs.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {Array.<{className: string, id: string, text: string>=} buttons An array of buttons where each button
* has a class, id and text property. The id is used in "data-button-id". It defaults to an Ok button
* @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
* 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) {
Expand Down
24 changes: 9 additions & 15 deletions test/spec/CSSUtils-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 }";

result = match(css, { tag: "a" });
expect(result.length).toBe(2);
Expand All @@ -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);

Expand Down Expand Up @@ -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);
});
Expand Down Expand Up @@ -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();
});

Expand Down
40 changes: 6 additions & 34 deletions test/spec/Editor-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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());
});

});

describe("Focus", function () {
Expand Down
Loading

0 comments on commit a02f49b

Please sign in to comment.