Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/twbs/rewire.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorJohannes <johannes.ewald@roomieplanet.de>2012-09-18 21:00:39 +0400
committerJohannes <johannes.ewald@roomieplanet.de>2012-09-18 21:03:33 +0400
commit1434938354af135fbbecc7b21969f134dc6fdbd2 (patch)
tree745d790927371ca8133da54181e8c9caacdd0559 /test
parent203b81607a82eb360113efbe8f63d2ed454c5a48 (diff)
- Improved strict mode detection
Diffstat (limited to 'test')
-rw-r--r--test/detectStrictMode.test.js16
1 files changed, 13 insertions, 3 deletions
diff --git a/test/detectStrictMode.test.js b/test/detectStrictMode.test.js
index 89ef936..5cde34e 100644
--- a/test/detectStrictMode.test.js
+++ b/test/detectStrictMode.test.js
@@ -2,10 +2,20 @@ var expect = require("expect.js"),
detectStrictMode = require("../lib/detectStrictMode.js");
describe("detectStrictMode", function () {
- it("should detect \"use strict\"; at the beginning of a string and ignore all whitespace before", function () {
+ it("should detect all valid uses of \"use strict\";", function () {
expect(detectStrictMode('"use strict";')).to.be(true);
- expect(detectStrictMode(' "use strict";')).to.be(true);
- expect(detectStrictMode(' \n "use strict";')).to.be(true);
+ expect(detectStrictMode("'use strict';")).to.be(true);
+ expect(detectStrictMode(' "use strict";')).to.be(true);
+ expect(detectStrictMode('\n"use strict";')).to.be(true);
+ expect(detectStrictMode('\r\n"use strict";')).to.be(true);
+ expect(detectStrictMode('"use strict"\r\n')).to.be(true);
+ expect(detectStrictMode('"use strict" ; test();')).to.be(true);
+ });
+ it("should not detect invalid uses of \"use strict\";", function () {
+ expect(detectStrictMode('" use strict ";')).to.be(false);
+ expect(detectStrictMode('"use strict".replace("use", "fail");')).to.be(false);
+ expect(detectStrictMode('"use strict" .replace("use", "fail");')).to.be(false);
+ expect(detectStrictMode(';"use strict";')).to.be(false);
});
it("should not detect \"use strict\"; if it occurs in some nested function", function () {
expect(detectStrictMode('function () {"use strict";}')).to.be(false);