Merge pull request #4205 from dloverin/jody-test3

Jody added some new code hint tests
This commit is contained in:
Jason San Jose committed 2013-06-17 13:46:03 -07:00
commit b9d69228bc
7 files changed
+544 -8

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>
@@ -38,7 +38,8 @@ define(function (require, exports, module) {
UnitTestReporter = brackets.getModule("test/UnitTestReporter"),
JSCodeHints = require("main"),
Preferences = require("Preferences"),
ScopeManager = require("ScopeManager");
ScopeManager = require("ScopeManager"),
HintUtils = require("HintUtils");
var extensionPath = FileUtils.getNativeModuleDirectoryPath(module),
testPath = extensionPath + "/unittest-files/basic-test-files/file1.js",
@@ -311,7 +312,10 @@ define(function (require, exports, module) {
/**
* Trigger a jump to definition, and verify that the editor jumped to
* the expected location.
* the expected location. The new location is the variable definition
* or function definition of the variable or function at the current
* cursor location. Jumping to the new location will cause a new editor
* to be opened or open an existing editor.
*
* @param {{line:number, ch:number, file:string}} expectedLocation - the
* line, column, and optionally the new file the editor should jump to. If the
@@ -358,7 +362,6 @@ define(function (require, exports, module) {
// The following call ensures that the document is reloaded
// from disk before each test
DocumentManager.closeAll();
SpecRunnerUtils.destroyMockEditor(testDoc);
testEditor = null;
testDoc = null;
@@ -717,9 +720,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 () {
@@ -1476,5 +1480,170 @@ define(function (require, exports, module) {
});
});
});
describe("regression tests", function () {
// Test maybe valid javascript identifier
// FIXME (issue #3558)
xit("should return true for valid identifier, false for invalid one", function () {
var identifierList = ["ᾩ", "ĦĔĽĻŎ", "〱〱〱〱", "जावास्क्रि",
"KingGeorgeⅦ", "π", "ಠ_ಠ",
"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();
});
// FIXME (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});
});
});
// FIXME (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("regression tests", function () {
afterEach(function () {
tearDownTest();
});
// Test maybe valid javascript identifier
// FIXME (issue #3558)
xit("should return true for valid identifier, false for invalid one", function () {
var identifierList = ["ᾩ", "ĦĔĽĻŎ", "〱〱〱〱", "जावास्क्रि",
"KingGeorgeⅦ", "π", "ಠ_ಠ",
"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();
});
// FIXME (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});
});
});
// FIXME (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});
});
});
});
});
});