modif comtabilite

This commit is contained in:
2019-01-16 16:23:31 +01:00
parent 6b741a9666
commit 9312edc3ae
1844 changed files with 158848 additions and 55874 deletions
+106 -25
View File
@@ -29,6 +29,34 @@ var comments = {
}
var nonTrailingComments = {
jsLeading: {
contents: [
"//# sourceMappingURL=foo.js.map",
"(function(){})"
],
solution: [
"(function(){})"
]
},
mixEmbedded: {
contents: [
"/*! Library Name v1.0.0",
"//# sourceMappingURL=foo.js.map",
"*/",
"(function(){})"
],
solution: [
"/*! Library Name v1.0.0",
"*/",
"(function(){})"
]
}
}
function forEachComment(fn) {
forOf(comments, function(name, comment) {
var description = "the '" + name + "' syntax with "
@@ -37,6 +65,23 @@ function forEachComment(fn) {
})
}
function forEachNonTrailingComment(fn) {
forOf(nonTrailingComments, function(name, comment) {
var description = "the '" + name + "' syntax with "
fn({
contents: comment.contents.join("\n"),
solution: comment.solution.join("\n")
}, description + "regular newlines")
fn({
contents: comment.contents.join("\r\n"),
solution: comment.solution.join("\r\n")
}, description + "Windows newlines")
})
}
function forOf(obj, fn) {
for (var key in obj) {
if (Object.prototype.hasOwnProperty.call(obj, key)) {
@@ -65,6 +110,21 @@ describe("sourceMappingURL", function() {
})
forEachNonTrailingComment(function(comment, description) {
it("gets the url from " + description, function() {
expect(sourceMappingURL.getFrom("code\n" + comment.contents))
.to.equal("foo.js.map")
expect(sourceMappingURL.getFrom("code" + comment.contents))
.to.equal("foo.js.map")
expect(sourceMappingURL.getFrom(comment.contents))
.to.equal("foo.js.map")
})
})
it("returns null if no comment", function() {
expect(sourceMappingURL.getFrom("code"))
@@ -104,6 +164,21 @@ describe("sourceMappingURL", function() {
})
forEachNonTrailingComment(function(comment, description) {
it("returns true for " + description, function() {
expect(sourceMappingURL.existsIn("code\n" + comment.contents))
.to.equal(true)
expect(sourceMappingURL.existsIn("code" + comment.contents))
.to.equal(true)
expect(sourceMappingURL.existsIn(comment.contents))
.to.equal(true)
})
})
it("returns false if no comment", function() {
expect(sourceMappingURL.existsIn("code"))
@@ -137,6 +212,21 @@ describe("sourceMappingURL", function() {
})
forEachNonTrailingComment(function(comment, description) {
it("removes the comment for " + description, function() {
expect(sourceMappingURL.removeFrom("code\n" + comment.contents))
.to.equal("code\n" + comment.solution)
expect(sourceMappingURL.removeFrom("code" + comment.contents))
.to.equal("code" + comment.solution)
expect(sourceMappingURL.removeFrom(comment.contents))
.to.equal(comment.solution)
})
})
it("does nothing if no comment", function() {
expect(sourceMappingURL.removeFrom("code\n"))
@@ -171,6 +261,22 @@ describe("sourceMappingURL", function() {
})
it("inserts a string before an embedded comment", function() {
expect(sourceMappingURL.insertBefore("/*! Library Name v1.0.0\n" +
"//# sourceMappingURL=foo.js.map\n*/\n(function(){})", "code\n"))
.to.equal("/*! Library Name v1.0.0\ncode\n" +
"//# sourceMappingURL=foo.js.map\n*/\n(function(){})")
})
it("inserts a string before a leading comment", function() {
expect(sourceMappingURL.insertBefore("//# sourceMappingURL=foo.js.map\n" +
"(function(){})", "code\n"))
.to.equal("code\n//# sourceMappingURL=foo.js.map\n" +
"(function(){})")
})
it("appends if no comment", function() {
expect(sourceMappingURL.insertBefore("code", "\nmore code"))
.to.equal("code\nmore code")
@@ -220,20 +326,6 @@ describe("sourceMappingURL", function() {
match(comment + "\n\n\t\n \t ")
})
it("only matches " + description + " at the end of files", function() {
noMatch("code\n" + comment + " code")
noMatch("code" + comment + " code")
noMatch("code\n" + comment + "\ncode")
noMatch("code" + comment + "\ncode")
noMatch("code\n" + comment + "\n// Generated by foobar")
noMatch("code" + comment + "\n// Generated by foobar")
noMatch("alert\n('\\" + comment + "')")
noMatch("alert('\\" + comment + "')")
noMatch('alert\n("\\' + comment + '")')
noMatch('alert("\\' + comment + '")')
})
})
@@ -242,17 +334,6 @@ describe("sourceMappingURL", function() {
"/* # sourceMappingURL=foo */"
)
noMatch(
"/*\n" +
" //# sourceMappingURL=foo\n" +
"*/"
)
noMatch(
"/*//# sourceMappingURL=foo\n" +
"*/"
)
noMatch(
"// # sourceMappingURL=foo"
)