Skip to content

Commit

Permalink
fixing unit tests after merge
Browse files Browse the repository at this point in the history
  • Loading branch information
tvoliter committed Jun 21, 2012
1 parent df2cf81 commit d6c7520
Show file tree
Hide file tree
Showing 4 changed files with 126 additions and 68 deletions.
68 changes: 34 additions & 34 deletions src/extensions/default/JavaScriptQuickEdit/unittests.js
Expand Up @@ -23,7 +23,7 @@


/*jslint vars: true, plusplus: true, devel: true, browser: true, nomen: true, indent: 4, maxerr: 50 */
/*global define: false, describe: false, it: false, xit: false, expect: false, beforeEach: false, afterEach: false, waitsFor: false, runs: false, $: false, brackets: false */
/*global define: false, describe: false, it: false, xit: false, expect: false, beforeEach: false, afterEach: false, waitsFor: false, runs: false, $: false, brackets: false, waitsForDone */

define(function (require, exports, module) {
'use strict';
Expand Down Expand Up @@ -202,42 +202,42 @@ define(function (require, exports, module) {
});

it("should ignore tokens that are not function calls or references", function () {
var editor,
extensionRequire,
jsQuickEditMain,
tokensFile = "tokens.js",
promise,
offsets;
var editor,
extensionRequire,
jsQuickEditMain,
tokensFile = "tokens.js",
promise,
offsets;

initInlineTest(tokensFile);
initInlineTest(tokensFile);

runs(function () {
extensionRequire = testWindow.brackets.getModule("utils/ExtensionLoader").getRequireContextForExtension("JavaScriptQuickEdit");
jsQuickEditMain = extensionRequire("main");
editor = EditorManager.getCurrentFullEditor();
offsets = this.infos[tokensFile];

// regexp token
promise = jsQuickEditMain.javaScriptFunctionProvider(editor, offsets[0]);
expect(promise).toBeNull();

// multi-line comment
promise = jsQuickEditMain.javaScriptFunctionProvider(editor, offsets[1]);
expect(promise).toBeNull();

// single-line comment
promise = jsQuickEditMain.javaScriptFunctionProvider(editor, offsets[2]);
expect(promise).toBeNull();

// string, double quotes
promise = jsQuickEditMain.javaScriptFunctionProvider(editor, offsets[3]);
expect(promise).toBeNull();
runs(function () {
extensionRequire = testWindow.brackets.getModule("utils/ExtensionLoader").getRequireContextForExtension("JavaScriptQuickEdit");
jsQuickEditMain = extensionRequire("main");
editor = EditorManager.getCurrentFullEditor();
offsets = this.infos[tokensFile];

// string, single quotes
promise = jsQuickEditMain.javaScriptFunctionProvider(editor, offsets[4]);
expect(promise).toBeNull();
});
});
// regexp token
promise = jsQuickEditMain.javaScriptFunctionProvider(editor, offsets[0]);
expect(promise).toBeNull();

// multi-line comment
promise = jsQuickEditMain.javaScriptFunctionProvider(editor, offsets[1]);
expect(promise).toBeNull();

// single-line comment
promise = jsQuickEditMain.javaScriptFunctionProvider(editor, offsets[2]);
expect(promise).toBeNull();

// string, double quotes
promise = jsQuickEditMain.javaScriptFunctionProvider(editor, offsets[3]);
expect(promise).toBeNull();

// string, single quotes
promise = jsQuickEditMain.javaScriptFunctionProvider(editor, offsets[4]);
expect(promise).toBeNull();
});
});

it("should open a function with form: function functionName()", function () {
initInlineTest("test1main.js", 0);
Expand Down
2 changes: 1 addition & 1 deletion src/language/JSUtils.js
Expand Up @@ -421,7 +421,7 @@ define(function (require, exports, module) {
PerfUtils.createPerfMeasurement("JSUTILS_REGEXP", "RegExp search for all functions");
PerfUtils.createPerfMeasurement("JSUTILS_END_OFFSET", "Find end offset for a single matched function");

exports.findAllMatchingFunctionsInText = findAllMatchingFunctionsInText; // For testing only
exports.findAllMatchingFunctionsInText = findAllMatchingFunctionsInText;
exports._getFunctionEndOffset = _getFunctionEndOffset; // For testing only
exports.findMatchingFunctions = findMatchingFunctions;
});
78 changes: 68 additions & 10 deletions test/spec/CSSUtils-test.js
Expand Up @@ -1098,19 +1098,39 @@ define(function (require, exports, module) {
SpecRunnerUtils.closeTestWindow();
});

it("should return the correct offsets if the file has changed", function () {
var didOpen = false,
gotError = false;

function fileChangedTest(buildCache) {
var doc,
didOpen = false,
gotError = false,
functions = null;

runs(function () {
FileViewController.openAndSelectDocument(testPath + "/simple.css", FileViewController.PROJECT_MANAGER)
FileViewController.openAndSelectDocument(testPath + "/edit.js", FileViewController.PROJECT_MANAGER)
.done(function () { didOpen = true; })
.fail(function () { gotError = true; });
});

waitsFor(function () { return didOpen && !gotError; }, "FileViewController.addToWorkingSetAndSelect() timeout", 1000);

var rules = null;
// Populate JSUtils cache
if (buildCache) {
runs(function () {
FileIndexManager.getFileInfoList("all")
.done(function (fileInfos) {
// Look for "edit2" function
JSUtils.findMatchingFunctions("edit2", fileInfos)
.done(function (result) { functions = result; });
});
});

waitsFor(function () { return functions !== null; }, "JSUtils.findMatchingFunctions() timeout", 1000);

runs(function () {
expect(functions.length).toBe(1);
expect(functions[0].lineStart).toBe(7);
expect(functions[0].lineEnd).toBe(9);
});
}

runs(function () {
var doc = DocumentManager.getCurrentDocument();
Expand All @@ -1130,23 +1150,53 @@ define(function (require, exports, module) {
expect(rules[0].lineStart).toBe(16);
expect(rules[0].lineEnd).toBe(18);
});
}

it("should return the correct offsets if the file has changed", function () {
fileChangedTest(false);
});

it("should return a newly created rule in an unsaved file", function () {
it("should return the correct offsets if the results were cached and the file has changed", function () {
fileChangedTest(true);
});

function insertFunctionTest(buildCache) {
var didOpen = false,
gotError = false;
gotError = false,
functions = null;

runs(function () {
FileViewController.openAndSelectDocument(testPath + "/simple.css", FileViewController.PROJECT_MANAGER)
FileViewController.openAndSelectDocument(testPath + "/edit.js", FileViewController.PROJECT_MANAGER)
.done(function () { didOpen = true; })
.fail(function () { gotError = true; });
});

waitsFor(function () { return didOpen && !gotError; }, "FileViewController.addToWorkingSetAndSelect() timeout", 1000);

var rules = null;
// Populate JSUtils cache
if (buildCache) {
runs(function () {
// Look for the selector we're about to create--we shouldn't find it yet
FileIndexManager.getFileInfoList("all")
.done(function (fileInfos) {
// Look for "TESTFUNCTION" function
JSUtils.findMatchingFunctions("TESTFUNCTION", fileInfos)
.done(function (result) {
functions = result;
});
});
});

waitsFor(function () { return functions !== null; }, "JSUtils.findMatchingFunctions() timeout", 1000);

runs(function () {
expect(functions.length).toBe(0);
});
}

runs(function () {
// reset result functions array
functions = null;
var doc = DocumentManager.getCurrentDocument();

// Add a new selector to the file
Expand All @@ -1164,6 +1214,14 @@ define(function (require, exports, module) {
expect(rules[0].lineStart).toBe(24);
expect(rules[0].lineEnd).toBe(26);
});
}

it("should return a newly created function in an unsaved file", function () {
insertFunctionTest(false);
});

it("should return a newly created function in an unsaved file that already has cached results", function () {
insertFunctionTest(true);
});
});
}); //describe("CSS Parsing")
Expand Down
46 changes: 23 additions & 23 deletions test/spec/JSUtils-test.js
Expand Up @@ -31,8 +31,8 @@ define(function (require, exports, module) {
var DocumentManager, // loaded from brackets.test
FileIndexManager, // loaded from brackets.test
FileViewController, // loaded from brackets.test
JSUtils, // loaded from brackets.test


JSUtils = require("language/JSUtils"),
FileUtils = require("file/FileUtils"),
NativeFileSystem = require("file/NativeFileSystem").NativeFileSystem,
SpecRunnerUtils = require("spec/SpecRunnerUtils");
Expand All @@ -47,11 +47,11 @@ define(function (require, exports, module) {
return this.actual.functionName.trim() === expected;
};

var simpleJsFileEntry = new NativeFileSystem.FileEntry(testPath + "/unittest-files/simple.js");
var jQueryJsFileEntry = new NativeFileSystem.FileEntry(testPath + "/unittest-files/jquery-1.7.js");
var braceEndJsFileEntry = new NativeFileSystem.FileEntry(testPath + "/unittest-files/braceEnd.js");
var eofJsFileEntry = new NativeFileSystem.FileEntry(testPath + "/unittest-files/eof.js");
var eof2JsFileEntry = new NativeFileSystem.FileEntry(testPath + "/unittest-files/eof2.js");
var simpleJsFileEntry = new NativeFileSystem.FileEntry(testPath + "/simple.js");
var jQueryJsFileEntry = new NativeFileSystem.FileEntry(testPath + "/jquery-1.7.js");
var braceEndJsFileEntry = new NativeFileSystem.FileEntry(testPath + "/braceEnd.js");
var eofJsFileEntry = new NativeFileSystem.FileEntry(testPath + "/eof.js");
var eof2JsFileEntry = new NativeFileSystem.FileEntry(testPath + "/eof2.js");

function init(spec, fileEntry) {
spec.fileJsContent = null;
Expand Down Expand Up @@ -352,18 +352,18 @@ define(function (require, exports, module) {

function fileChangedTest(buildCache) {
var doc,
didOpen = false,
gotError = false,
functions = null;

runs(function () {
FileViewController.openAndSelectDocument(testPath + "/edit.js", FileViewController.PROJECT_MANAGER)
.done(function () { didOpen = true; })
.fail(function () { gotError = true; });
runs(function () {
waitsForDone(
FileViewController.openAndSelectDocument(
testPath + "/edit.js",
FileViewController.PROJECT_MANAGER
),
"openAndSelectDocument"
);
});

waitsFor(function () { return didOpen && !gotError; }, "FileViewController.addToWorkingSetAndSelect() timeout", 1000);

// Populate JSUtils cache
if (buildCache) {
runs(function () {
Expand Down Expand Up @@ -419,18 +419,18 @@ define(function (require, exports, module) {
});

function insertFunctionTest(buildCache) {
var didOpen = false,
gotError = false,
functions = null;
var functions = null;

runs(function () {
FileViewController.openAndSelectDocument(testPath + "/edit.js", FileViewController.PROJECT_MANAGER)
.done(function () { didOpen = true; })
.fail(function () { gotError = true; });
waitsForDone(
FileViewController.openAndSelectDocument(
testPath + "/edit.js",
FileViewController.PROJECT_MANAGER
),
"openAndSelectDocument"
);
});

waitsFor(function () { return didOpen && !gotError; }, "FileViewController.addToWorkingSetAndSelect() timeout", 1000);

// Populate JSUtils cache
if (buildCache) {
runs(function () {
Expand Down

0 comments on commit d6c7520

Please sign in to comment.