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 Ewald <johannes.ewald@peerigon.com>2015-04-28 01:46:50 +0300
committerJohannes Ewald <johannes.ewald@peerigon.com>2015-04-28 01:46:50 +0300
commitbbbd05cab7260f7db9ffcb4adb2e19bdf661bca9 (patch)
treef1d61fe120ad564e911f72f6c8b0b395083731f4 /test
parent7cd73d4d70f103814035bc8cb5648d71d4960562 (diff)
Fix issue where the strict mode was not detected when a comment was before "strict mode";
Fixes #54
Diffstat (limited to 'test')
-rw-r--r--test/detectStrictMode.test.js12
1 files changed, 11 insertions, 1 deletions
diff --git a/test/detectStrictMode.test.js b/test/detectStrictMode.test.js
index 5cde34e..06eb1c4 100644
--- a/test/detectStrictMode.test.js
+++ b/test/detectStrictMode.test.js
@@ -2,6 +2,7 @@ var expect = require("expect.js"),
detectStrictMode = require("../lib/detectStrictMode.js");
describe("detectStrictMode", 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);
@@ -11,13 +12,22 @@ describe("detectStrictMode", function () {
expect(detectStrictMode('"use strict"\r\n')).to.be(true);
expect(detectStrictMode('"use strict" ; test();')).to.be(true);
});
+
+ it("should be allowed to place comments before \"use strict\";", function () {
+ expect(detectStrictMode('// some comment\n"use strict";')).to.be(true);
+ expect(detectStrictMode('/* yo! */"use strict"; /* another comment */')).to.be(true);
+ expect(detectStrictMode(' // yes yo\r\n\r\n\r\n /*oh yoh*/\r\n//oh snap!\r /* yoh! */"use strict";')).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);
});
-}); \ No newline at end of file
+
+});