add more code hint tests for html file and module file

This commit is contained in:
jzhang committed 2013-05-16 14:45:36 -04:00
1 parent 2ddcf52d49
commit bd4feb5611
8 files changed
+351 -12

No files matched your search

@@ -6,8 +6,9 @@
</head>
<body>
<script src="file1.js"></script>
<script src="file2.js"></script>
<script>
var x = "hi";
var x100 = "hi";
</script>
some stuff
@@ -17,19 +18,25 @@
</div>
<script>
function foo(a){
var y = x100;
k = a;
funD("test", 100);
funE(D1, A2.propA);
return "hi";
}
var k = 100;
</script>
<style>
.style:hover { color: rgba(153, 102, 51, 0.63); }
</style>
some other stuff
<div class = "content">
</div>
<script>
foo(10);
</script>
</body>
</html>
@@ -0,0 +1,7 @@
/*jslint vars: true, plusplus: true, devel: true, browser: true, nomen: true, indent: 4, maxerr: 50 */
/*global define, $ */
define(function (require, exports, module) {
"use strict";
exports.name = "Honda";
exports.model = "2013 MDX";
});
@@ -0,0 +1,11 @@
/*jslint vars: true, plusplus: true, devel: true, browser: true, nomen: true, indent: 4, maxerr: 50 */
/*global define, $ */
define(function () {
'use strict';
return {
getCredits: function () {
var credits = "100";
return credits;
}
};
});
@@ -0,0 +1,98 @@
/*jslint vars: true, plusplus: true, devel: true, browser: true, node: true, nomen: true, indent: 4, maxerr: 50 */
/*global brackets, define, require, $ */
define(function (require, exports, module) {
'use strict';
var moduleName = (function () {
// this becomes public due to the reference exposure in the return below
var addMessage = function (test) {
this.publicMethod1(); // a test here to check the method showing
};
var name = "new name";
// this is the "revealed" part of the module
return {
addMessage: addMessage,
name: name
};
}());
moduleName.publicMethod1 = function () { // test for methods:name, addMessage, publicMethod1, priv
};
// extending a new module
var extendedModule = (function (oldModule) {
var parent = oldModule;
parent.privilegedMethod = function () {
};
var privateMethod2 = function () {
// test parent. make sure all methods defined in moduleName showing up here
};
return {
newMethod : function () {
// should see methods for oldModule oldModule., parent.
// should see privateMethod2(
}
};
}(moduleName || {}));//Module object is the existing module to extend.
// test here: check extendedModule
moduleName.addMessage("test");
moduleName.name = " new name";
//parent module
var SearchEngine = (function () {
//Private Method.
var luckyAlgo = function () {
//create one random number.
return Math.floor(Math.random() * 11);
};
//Returning the object
return {
//privileged method.
getYourLuckyNumber : function () {
//Has access to its private method because of closure.
return luckyAlgo();
}
};
}());//Self executing method.
// test SearchEngine.getYourLuckyNumber().toExponential();
SearchEngine.subSearch = (function () {
//Private variable.
var defaultColor = "Orange";
//private method.
var myColorAlgo = function (num) {
switch (num) {
case 1:
defaultColor = "Green";
break;
}
};
return {
getYourLuckyColor : function () {
//access to private variable because of closure.
myColorAlgo(SearchEngine.getYourLuckyNumber());
return defaultColor;
}
};
}());
require(["shirt"], function (myShirt) {
// myShirt. test here
});
var t2 = require("shirt");
var size = t2.size;
var color = t2.color;
t2.material();
var purchaseModule = require('purchase');
purchaseModule.purchaseProduct();
var hondaCar = require('Car');
});
@@ -0,0 +1,11 @@
/*jslint vars: true, plusplus: true, devel: true, browser: true, nomen: true, indent: 4, maxerr: 50 */
/*global define, $ */
define(function (products) {
'use strict';
return {
reserveProduct: function () {
console.log("Function : reserveProduct");
return true;
}
};
});
@@ -0,0 +1,15 @@
/*jslint vars: true, plusplus: true, devel: true, browser: true, nomen: true, indent: 4, maxerr: 50 */
/*global define, $ */
define(["credits", "products"], function (credits, products) {
'use strict';
return {
purchaseProduct: function () {
var credit = credits.getCredits();
if (credit > 0) {
products.reserveProduct();
return true;
}
return false;
}
};
});
@@ -0,0 +1,12 @@
/*jslint vars: true, plusplus: true, devel: true, browser: true, nomen: true, indent: 4, maxerr: 50 */
/*global define, $ */
define(function () {
'use strict';
return {
color: "black",
size: 10,
material: function () {
return "cotton";
}
};
});
@@ -1097,10 +1097,10 @@ define(function (require, exports, module) {
});
it("basic codehints in html file", function () {
var start = { line: 30, ch: 9 },
end = { line: 30, ch: 11 };
var start = { line: 37, ch: 9 },
end = { line: 37, ch: 13};
testDoc.replaceRange("x.", start, start);
testDoc.replaceRange("x100.", start);
testEditor.setCursorPos(end);
var hintObj = expectHints(JSCodeHints.jsHintProvider);
runs(function () {
@@ -1109,7 +1109,7 @@ define(function (require, exports, module) {
});
it("function type hint in html file", function () {
var start = { line: 29, ch: 12 };
var start = { line: 36, ch: 12 };
testEditor.setCursorPos(start);
var hintObj = expectHints(JSCodeHints.jsHintProvider);
@@ -1117,15 +1117,92 @@ define(function (require, exports, module) {
hintsPresentExact(hintObj, ["foo(a: number) -> string"]);
});
});
it("should show function type code hint for function in script file inside html file", function () {
var start = { line: 22, ch: 17 };
testEditor.setCursorPos(start);
var hintObj = expectHints(JSCodeHints.jsHintProvider);
runs(function () {
hintsPresentExact(hintObj, ["funD(a: string, b: number) -> {x, y}"]);
});
});
it("jump-to-def in html file", function () {
var start = { line: 29, ch: 10 };
it("should show function type code hint for function in another script file inside html file", function () {
var start = { line: 23, ch: 17 };
testEditor.setCursorPos(start);
var hintObj = expectHints(JSCodeHints.jsHintProvider);
runs(function () {
hintsPresentExact(hintObj, ["funE(paramE1: D1, paramE2: number)"]);
});
});
it("should show global variable in another script file inside html file", function () {
var start = { line: 27, ch: 8 },
end = { line: 27, ch: 13},
testPosStart = { line: 27, ch: 11},
testPosEnd = { line: 27, ch: 21};
testDoc.replaceRange("arr.m", start);
testEditor.setCursorPos(end);
var hintObj = expectHints(JSCodeHints.jsHintProvider);
runs(function () {
hintsPresent(hintObj, ["my-key"]);
});
selectHint(JSCodeHints.jsHintProvider, hintObj, "my-key");
runs(function () {
expect(testDoc.getRange(testPosStart, testPosEnd)).toEqual("[\"my-key\"]");
});
});
it("should jump to definition inside html file", function () {
var start = { line: 36, ch: 10 };
testEditor.setCursorPos(start);
runs(function () {
editorJumped({line: 18, ch: 20});
editorJumped({line: 19, ch: 20});
});
});
it("should jump to funtion definition to loaded file1", function () {
var start = { line: 22, ch: 15 };
testEditor.setCursorPos(start);
runs(function () {
editorJumped({line: 33, ch: 13});
});
});
it("should jump to funtion definition to loaded file2", function () {
var start = { line: 23, ch: 15 };
testEditor.setCursorPos(start);
runs(function () {
editorJumped({line: 6, ch: 13});
});
});
it("should jump to property definition to loaded file1", function () {
var start = { line: 23, ch: 28 };
testEditor.setCursorPos(start);
runs(function () {
editorJumped({line: 4, ch: 16});
});
});
it("should jump to property definition to loaded file2", function () {
var start = { line: 23, ch: 18 };
testEditor.setCursorPos(start);
runs(function () {
editorJumped({line: 3, ch: 6});
});
});
});
describe("JavaScript Code Hinting without modules", function () {
@@ -1150,6 +1227,107 @@ define(function (require, exports, module) {
});
});
});
describe("JavaScript Code Hinting with modules", function () {
var testPath = extensionPath + "/unittest-files/module-test-files/module_tests.js";
beforeEach(function () {
setupTest(testPath, true);
});
afterEach(function () {
tearDownTest();
});
it("should read methods created in submodule on this", function () {
var start = { line: 8, ch: 17 };
runs(function () {
testEditor.setCursorPos(start);
var hintObj = expectHints(JSCodeHints.jsHintProvider);
hintsPresentExact(hintObj, ["addMessage", "name", "privilegedMethod", "publicMethod1"]);
});
});
it("should read methods created in submodule", function () {
var start = { line: 19, ch: 15 };
runs(function () {
testEditor.setCursorPos(start);
var hintObj = expectHints(JSCodeHints.jsHintProvider);
hintsPresentExact(hintObj, ["addMessage", "name", "privilegedMethod", "publicMethod1"]);
});
});
it("should read properties created in parent module", function () {
var start = { line: 30, ch: 8 },
testPos = { line: 30, ch: 15};
testDoc.replaceRange("parent.", start);
runs(function () {
testEditor.setCursorPos(testPos);
var hintObj = expectHints(JSCodeHints.jsHintProvider);
hintsPresentExact(hintObj, ["addMessage", "name", "privilegedMethod", "publicMethod1"]);
});
});
// bug: wait for tern
xit("should read methods created in submodule module", function () {
var start = { line: 62, ch: 0 },
testPos = { line: 62, ch: 13};
testDoc.replaceRange("SearchEngine.", start);
runs(function () {
testEditor.setCursorPos(testPos);
var hintObj = expectHints(JSCodeHints.jsHintProvider);
hintsPresentExact(hintObj, ["getYourLuckyNumber", "subSearch"]);
});
});
it("should read methods created in parent module", function () {
var start = { line: 78, ch: 41 };
runs(function () {
testEditor.setCursorPos(start);
var hintObj = expectHints(JSCodeHints.jsHintProvider);
hintsPresentExact(hintObj, ["getYourLuckyNumber", "subSearch"]);
});
});
it("should load module by file path from require", function () {
var start = { line: 88, ch: 20 };
runs(function () {
testEditor.setCursorPos(start);
var hintObj = expectHints(JSCodeHints.jsHintProvider);
hintsPresentExact(hintObj, ["color", "material", "size"]);
});
});
// tern bug: https://github.com/marijnh/tern/issues/147
xit("should read properties from exported module", function () {
var start = { line: 96, ch: 0 },
testPos = { line: 96, ch: 9};
testDoc.replaceRange("hondaCar.", start);
runs(function () {
testEditor.setCursorPos(testPos);
var hintObj = expectHints(JSCodeHints.jsHintProvider);
hintsPresentExact(hintObj, ["model", "name"]);
});
});
// bug in test framework? can't run sequencial jump, verification is wrong
xit("should jump to a module, depending module", function () {
var start = { line: 93, ch: 25 },
testPos = { line: 8, ch: 35 };
testEditor.setCursorPos(start);
runs(function () {
editorJumped({line: 5, ch: 23});
});
testEditor.setCursorPos(testPos);
runs(function () {
editorJumped({line: 5, ch: 23});
});
});
});
});
});