File: detectStrictMode.test.js

package info (click to toggle)
node-rewire 6.0.0-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, sid, trixie
  • size: 392 kB
  • sloc: javascript: 1,386; makefile: 2
file content (33 lines) | stat: -rw-r--r-- 1,651 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
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);
        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 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);
    });

});