add new test cases

This commit is contained in:
jzhang committed 2013-05-24 16:18:10 -04:00
1 parent e664a00d09
commit 3dfead4e05
3 files changed
+321 -6

No files matched your search

@@ -0,0 +1,74 @@
/*jslint vars: true, plusplus: true, devel: true, browser: true, nomen: true, indent: 4, maxerr: 50 */
/*global define, describe, it, xit, expect, beforeEach, afterEach, waitsFor, runs, $, brackets, waitsForDone */
function funD_file3(a, b) {
'use strict';
var f = function () {return {x: a, y: b}; };
return f;
}
var kf3 = funD_file3(10, 20);
kf3();
var hope = {frenchçProp2: "test", frenchçProp1: " new value", frenchçfun:frenchçProp() };
function frenchçProp(){
};
function frenchçProp(){
}
frenchçProp();
var 測试 = "test";
測试 = "new value";
// 測 test code hint
function fun測试(){
}
fun測试(); // test function type
function nonAsciiTest() {
var hope; // unknown type
hope["frenchçProp"] = "";
hope.frenchçProp2 = "test";
hope.frenchçProp = "frenchçProp";
fun測试();
var month = getMonthName(5);
A1.propA = "test";
}
function frenchçProp(){};
frenchçProp();
function UserException(message) {
this.message = message;
this.name = "UserException";
}
function getMonthName(mo) {
mo = mo-1; // Adjust month number for array index (1=Jan, 12=Dec)
var months = new Array("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul",
"Aug", "Sep", "Oct", "Nov", "Dec");
if (months[mo] !== undefined) {
return months[mo];
} else {
throw new UserException("InvalidMonthNo"); // test exception
}
}
function callOtherMethods() {
testTryCatch();
}
function testTryCatch() {
"use strict";
try {
var myMonth = 15; // 15 is out of bound to raise the exception
} catch (e) {
myMonth = 12;
console.log(e.message + e.name); // test e, e.message, e.name
}
try {
var myMonth = 15; // 15 is out of bound to raise the exception
} catch (e2) {
myMonth = 12; // test local variable
console.log(e2.message + e2.name); // test e, e.message, e.name
}
}
@@ -0,0 +1,38 @@
<!DOCTYPE html>
<html>
<head>
<script src="../module-test-files/Car.js"></script>
<script src="../module-test-files/shirt.js"></script>
<script src="../file1.js"></script>
<script src="../file3.js"></script>
<!-- leave follow empty line for later file including -->
<script>
var txt="";
fun測试();
frenchçProp();
nonAsciiTest(); // in quick editor, test jump, function type, code hint list
myTest();
callOtherMethods();
</script>
<script>
function myTest(){
monthName = "test";
simple1();
}
function simple1(){
}
</script>
</head>
<body>
<input type="button" value="View message" onclick="message()">
</body>
</html>
@@ -35,13 +35,16 @@ define(function (require, exports, module) {
DocumentManager = brackets.getModule("document/DocumentManager"),
SpecRunnerUtils = brackets.getModule("spec/SpecRunnerUtils"),
UnitTestReporter = brackets.getModule("test/UnitTestReporter"),
JSCodeHints = require("main");
JSCodeHints = require("main"),
HintUtils = require("HintUtils");
var extensionPath = FileUtils.getNativeModuleDirectoryPath(module),
testPath = extensionPath + "/unittest-files/basic-test-files/file1.js",
testHtmlPath = extensionPath + "/unittest-files/basic-test-files/index.html",
testDoc = null,
testEditor;
testEditor,
testWindow,
self = this;
CommandManager.register("test-file-open", Commands.FILE_OPEN, function (fileInfo) {
// Register a command for FILE_OPEN, which the jump to def code will call
@@ -343,12 +346,36 @@ define(function (require, exports, module) {
// The following call ensures that the document is reloaded
// from disk before each test
DocumentManager.closeAll();
SpecRunnerUtils.destroyMockEditor(testDoc);
if (testDoc !== null) {
SpecRunnerUtils.destroyMockEditor(testDoc);
}
testEditor = null;
testDoc = null;
}
function setupWithTestWindow(testFile) {
runs(function () {
SpecRunnerUtils.createTestWindowAndRun(self, function (w) {
testWindow = w;
// Load module instances from brackets.test
CommandManager = testWindow.brackets.test.CommandManager;
Commands = testWindow.brackets.test.Commands;
EditorManager = testWindow.brackets.test.EditorManager;
DocumentManager = testWindow.brackets.test.DocumentManager;
});
});
runs(function () {
var promise = CommandManager.execute(Commands.FILE_OPEN, {fullPath: testFile});
waitsForDone(promise, "Open " + testPath + " into working set");
});
}
function tearDownTestWindow() {
SpecRunnerUtils.closeTestWindow();
}
describe("JavaScript Code Hinting Basic", function () {
beforeEach(function () {
@@ -694,9 +721,10 @@ define(function (require, exports, module) {
it("should list hints for string, as string assigned to 's', 's' assigned to 'r' and 'r' assigned to 't'", function () {
var start = { line: 26, ch: 0 },
middle = { line: 26, ch: 2 };
middle = { line: 26, ch: 6 };
testDoc.replaceRange("t.", start, start);
// pad spaces here as tern has issue,without space, no code hint
testDoc.replaceRange(" t.", start);
testEditor.setCursorPos(middle);
var hintObj = expectHints(JSCodeHints.jsHintProvider);
runs(function () {
@@ -1328,5 +1356,180 @@ define(function (require, exports, module) {
});
});
});
describe("regression tests", function () {
afterEach(function () {
tearDownTest();
});
// Test maybe valid javascript identifier
xit("#3558:should return true for valid identifier, false for invalid one", function () {
var identifierList = ["ᾩ", "ĦĔĽĻŎ", "〱〱〱〱", "जावास्क्रि",
"KingGeorgeⅦ", "π", "ಠ_ಠ", "\u006C\u006F\u006C\u0077\u0061\u0074",
"price_9̶9̶_89", "$_3423", "TRUE", "FALSE", "IV"];
var invalidIdentifierList = [" break", "\tif", "\ntrade"];
invalidIdentifierList.forEach(function (element) {
var result = HintUtils.maybeIdentifier(element);
expect(result).toBe(false);
});
identifierList.forEach(function (element) {
var result = HintUtils.maybeIdentifier(element);
expect(result).toBe(true);
});
});
});
describe("JavaScript Code Hinting with test.html file", function () {
var testFile = extensionPath + "/unittest-files/basic-test-files/test.html";
beforeEach(function () {
setupTest(testFile, true);
});
afterEach(function () {
tearDownTest();
});
// issue #3915
xit("should read function name has double byte chars", function () {
var start = { line: 15, ch: 8 },
testPos = { line: 15, ch: 10 };
runs(function () {
testEditor.setCursorPos(start);
var hintObj = expectHints(JSCodeHints.jsHintProvider);
hintsPresentExact(hintObj, ["fun測试"]);
});
runs(function () {
testEditor.setCursorPos(testPos);
var hintObj = expectHints(JSCodeHints.jsHintProvider);
hintsPresentExact(hintObj, ["fun測试()"]);
});
});
it("should jump to function name with double byte chars", function () {
var start = { line: 16, ch: 9 };
testEditor.setCursorPos(start);
runs(function () {
editorJumped({line: 12, ch: 20});
});
});
// issue #3915
xit("should read function name has non ascii chars", function () {
var start = { line: 16, ch: 16 };
runs(function () {
testEditor.setCursorPos(start);
var hintObj = expectHints(JSCodeHints.jsHintProvider);
hintsPresentExact(hintObj, ["frenchçProp()"]);
});
});
it("should jump to function name with non ascii chars", function () {
var start = { line: 16, ch: 12 };
testEditor.setCursorPos(start);
runs(function () {
editorJumped({line: 12, ch: 20});
});
});
});
describe("JavaScript Code Hinting in quick editor", function () {
var testFile = extensionPath + "/unittest-files/basic-test-files/test.html";
beforeEach(function () {
setupWithTestWindow(testFile);
});
afterEach(tearDownTestWindow);
// framework issue
xit("should see code hint lists in quick editor", function () {
var start = { line: 17, ch: 10 },
testPos = { line: 32, ch: 22};
var previousEditor;
runs(function () {
previousEditor = EditorManager.getActiveEditor();
var openQuickEditor = SpecRunnerUtils.toggleQuickEditAtOffset(EditorManager.getCurrentFullEditor(), start);
waitsForDone(openQuickEditor, "Open quick editor");
JSCodeHints.initializeSession(EditorManager.getActiveEditor(), previousEditor, true);
});
runs(function () {
testEditor = EditorManager.getActiveEditor();
testEditor.setCursorPos(testPos);
var hintObj = expectHints(JSCodeHints.jsHintProvider);
hintsPresentExact(hintObj, ["getMonthName(mo: number)"]);
});
});
it("should see jump to definition on varialbe working in quick editor", function () {
var start = { line: 17, ch: 10 },
testPos = { line: 33, ch: 7},
testJumpPos = { line: 33, ch: 5},
jumpPos = {line: 3, ch: 6};
var previousEditor;
runs(function () {
previousEditor = EditorManager.getActiveEditor();
var openQuickEditor = SpecRunnerUtils.toggleQuickEditAtOffset(EditorManager.getCurrentFullEditor(), start);
waitsForDone(openQuickEditor, "Open quick editor");
JSCodeHints.initializeSession(EditorManager.getActiveEditor(), previousEditor, true);
});
runs(function () {
testEditor = EditorManager.getActiveEditor();
testEditor.setCursorPos(testPos);
var hintObj = expectHints(JSCodeHints.jsHintProvider);
hintsPresentExact(hintObj, ["propA"]);
});
runs(function () {
testEditor = EditorManager.getActiveEditor();
testEditor.setCursorPos(testJumpPos);
editorJumped(jumpPos);
});
});
// framework issue
xit("should see jump to definition on method working in quick editor", function () {
var start = { line: 19, ch: 13 },
testPos = { line: 56, ch: 18},
testPos2 = { line: 56, ch: 12},
jumpPos = {line: 59, ch: 21};
var previousEditor;
runs(function () {
previousEditor = EditorManager.getActiveEditor();
var openQuickEditor = SpecRunnerUtils.toggleQuickEditAtOffset(EditorManager.getCurrentFullEditor(), start);
waitsForDone(openQuickEditor, "Open quick editor");
JSCodeHints.initializeSession(EditorManager.getActiveEditor(), previousEditor, true);
});
runs(function () {
testEditor = EditorManager.getActiveEditor();
testEditor.setCursorPos(testPos);
var hintObj = expectHints(JSCodeHints.jsHintProvider);
hintsPresentExact(hintObj, ["testTryCatch()"]);
});
runs(function () {
testEditor = EditorManager.getActiveEditor();
testEditor.setCursorPos(testPos2);
editorJumped(jumpPos);
});
});
});
});
});