| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 74c19f8 commit cff2a0a
6 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -39,15 +39,11 @@ ConvenientLine.prototype.numLines = function() { | |||
| 39 | 39 | }; | |
| 40 | 40 | ||
| 41 | 41 | /** | |
| 42 | - * Number of characters in the string | ||
| 42 | + * Number of bytes in the string | ||
| 43 | 43 | * @return {Number} | |
| 44 | 44 | */ | |
| 45 | 45 | ConvenientLine.prototype.contentLen = function() { | |
| 46 | - if (!this._cache.contentLen) { | ||
| 47 | - this._cache.contentLen = this.content().length; | ||
| 48 | - } | ||
| 49 | - | ||
| 50 | - return this._cache.contentLen; | ||
| 46 | + return this.raw.contentLen(); | ||
| 51 | 47 | }; | |
| 52 | 48 | ||
| 53 | 49 | /** | |
@@ -74,8 +70,7 @@ ConvenientLine.prototype.content = function() { | |||
| 74 | 70 | if (!this._cache.content) { | |
| 75 | 71 | this._cache.content = new Buffer(this.raw.content()) | |
| 76 | 72 | .slice(0, this.raw.contentLen()) | |
| 77 | - .toString("utf8") | ||
| 78 | - .replace("\n", ""); | ||
| 73 | + .toString("utf8"); | ||
| 79 | 74 | } | |
| 80 | 75 | ||
| 81 | 76 | return this._cache.content; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1286,9 +1286,6 @@ Repository.prototype.stageLines = | |||
| 1286 | 1286 | (!isStaged && (!newLine || newLine.length === 0))) { | |
| 1287 | 1287 | if (hunkLine.origin() !== lineTypes.ADDED) { | |
| 1288 | 1288 | newContent += hunkLine.content(); | |
| 1289 | - if (hunkLine.raw.numLines() !== 0) { | ||
| 1290 | - newContent += "\n"; | ||
| 1291 | - } | ||
| 1292 | 1289 | } | |
| 1293 | 1290 | if ((isStaged && hunkLine.origin() !== lineTypes.DELETED) || | |
| 1294 | 1291 | (!isStaged && hunkLine.origin() !== lineTypes.ADDED)) { | |
@@ -1299,9 +1296,6 @@ Repository.prototype.stageLines = | |||
| 1299 | 1296 | switch (hunkLine.origin()) { | |
| 1300 | 1297 | case lineTypes.ADDED: | |
| 1301 | 1298 | newContent += hunkLine.content(); | |
| 1302 | - if (hunkLine.raw.numLines() !== 0) { | ||
| 1303 | - newContent += "\n"; | ||
| 1304 | - } | ||
| 1305 | 1299 | if (isStaged) { | |
| 1306 | 1300 | oldIndex++; | |
| 1307 | 1301 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -520,10 +520,6 @@ describe("Commit", function() { | |||
| 520 | 520 | " line q\nline r\nline s\nline t\n\nline u\n" + | |
| 521 | 521 | "line v1\nline w\nline x\n \nline y\nline z\n"; | |
| 522 | 522 | ||
| 523 | - function getLineText(line) { | ||
| 524 | - return line.rawContent().substring(0, line.contentLen()); | ||
| 525 | - } | ||
| 526 | - | ||
| 527 | 523 | return NodeGit.Repository.open(reposPath) | |
| 528 | 524 | .then(function(repoResult) { | |
| 529 | 525 | repo = repoResult; | |
@@ -559,33 +555,37 @@ describe("Commit", function() { | |||
| 559 | 555 | //check all hunk lines | |
| 560 | 556 | assert.equal(lines.length, 12); | |
| 561 | 557 | assert.equal(lines[0].origin(), Diff.LINE.CONTEXT); | |
| 562 | - assert.equal(lines[1].contentLen(), 8); | ||
| 563 | 558 | ||
| 564 | - assert.equal(getLineText(lines[1]), "line s"); | ||
| 559 | + assert.equal(lines[1].content().length, 9); | ||
| 560 | + assert.equal(lines[1].content(), "line s\n"); | ||
| 565 | 561 | assert.equal(lines[1].origin(), Diff.LINE.CONTEXT); | |
| 562 | + | ||
| 566 | 563 | assert.equal(lines[2].origin(), Diff.LINE.CONTEXT); | |
| 567 | 564 | ||
| 568 | - assert.equal(lines[3].contentLen(), 0); | ||
| 569 | - assert.equal(getLineText(lines[3]), ""); | ||
| 565 | + assert.equal(lines[3].content().length, 1); | ||
| 566 | + assert.equal(lines[3].content(), "\n"); | ||
| 570 | 567 | assert.equal(lines[3].origin(), Diff.LINE.ADDITION); | |
| 571 | 568 | ||
| 572 | 569 | assert.equal(lines[4].origin(), Diff.LINE.CONTEXT); | |
| 573 | 570 | ||
| 574 | - assert.equal(lines[5].contentLen(), 6); | ||
| 575 | - assert.equal(getLineText(lines[5]), "line v"); | ||
| 571 | + assert.equal(lines[5].content().length, 7); | ||
| 572 | + assert.equal(lines[5].content(), "line v\n"); | ||
| 576 | 573 | assert.equal(lines[5].origin(), Diff.LINE.DELETION); | |
| 577 | - assert.equal(lines[6].contentLen(), 7); | ||
| 578 | - assert.equal(getLineText(lines[6]), "line v1"); | ||
| 574 | + | ||
| 575 | + assert.equal(lines[6].content().length, 8); | ||
| 576 | + assert.equal(lines[6].content(), "line v1\n"); | ||
| 579 | 577 | assert.equal(lines[6].origin(), Diff.LINE.ADDITION); | |
| 580 | 578 | ||
| 581 | 579 | assert.equal(lines[7].origin(), Diff.LINE.CONTEXT); | |
| 580 | + | ||
| 582 | 581 | assert.equal(lines[8].origin(), Diff.LINE.CONTEXT); | |
| 583 | 582 | ||
| 584 | - assert.equal(lines[9].contentLen(), 3); | ||
| 585 | - assert.equal(getLineText(lines[9]), "\t\t\t"); | ||
| 583 | + assert.equal(lines[9].content().length, 4); | ||
| 584 | + assert.equal(lines[9].content(), "\t\t\t\n"); | ||
| 586 | 585 | assert.equal(lines[9].origin(), Diff.LINE.ADDITION); | |
| 587 | 586 | ||
| 588 | 587 | assert.equal(lines[10].origin(), Diff.LINE.CONTEXT); | |
| 588 | + | ||
| 589 | 589 | assert.equal(lines[11].origin(), Diff.LINE.CONTEXT); | |
| 590 | 590 | }); | |
| 591 | 591 | }); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -7,8 +7,8 @@ var local = path.join.bind(path, __dirname); | |||
| 7 | 7 | ||
| 8 | 8 | describe("ConvenientLine", function() { | |
| 9 | 9 | var repoPath = local("../repos/convenientLineTest"); | |
| 10 | - var unicodeLine = "Ťḥ𝖎ṧ ℓỈ𝓃ệ çǒ𝚗ẗảḭṋṦ Û𝐧ǐ𝗰ṓḍ𝔢"; | ||
| 11 | - var asciiLine = "but this line doesn't"; | ||
| 10 | + var unicodeLine = "Ťḥ𝖎ṧ ℓỈ𝓃ệ çǒ𝚗ẗảḭṋṦ Û𝐧ǐ𝗰ṓḍ𝔢\n"; | ||
| 11 | + var asciiLine = "but this line doesn't\n"; | ||
| 12 | 12 | ||
| 13 | 13 | beforeEach(function() { | |
| 14 | 14 | var test = this; | |
@@ -18,7 +18,7 @@ describe("ConvenientLine", function() { | |||
| 18 | 18 | return repoSetup.commitFileToRepo( | |
| 19 | 19 | repo, | |
| 20 | 20 | "fileWithUnicodeChars", | |
| 21 | - unicodeLine + "\n" + asciiLine + "\n" | ||
| 21 | + unicodeLine + asciiLine | ||
| 22 | 22 | ); | |
| 23 | 23 | }) | |
| 24 | 24 | .then(function(commit) { | |
@@ -46,7 +46,7 @@ describe("ConvenientLine", function() { | |||
| 46 | 46 | it("can parse the byte length of a unicode string", function() { | |
| 47 | 47 | var line = this.unicodeLine; | |
| 48 | 48 | ||
| 49 | - assert.equal(line.contentLen(), 32); | ||
| 49 | + assert.equal(line.contentLen(), Buffer.byteLength(unicodeLine, "utf8")); | ||
| 50 | 50 | }); | |
| 51 | 51 | ||
| 52 | 52 | it("can get a line that contains unicode", function() { | |
@@ -58,7 +58,7 @@ describe("ConvenientLine", function() { | |||
| 58 | 58 | it("can parse the byte length of a ascii string", function() { | |
| 59 | 59 | var line = this.asciiLine; | |
| 60 | 60 | ||
| 61 | - assert.equal(line.contentLen(), 21); | ||
| 61 | + assert.equal(line.contentLen(), Buffer.byteLength(asciiLine, "utf8")); | ||
| 62 | 62 | }); | |
| 63 | 63 | ||
| 64 | 64 | it("can get a line that contains ascii", function() { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -114,17 +114,17 @@ describe("Diff", function() { | |||
| 114 | 114 | assert.equal(lines[2].origin(), Diff.LINE.CONTEXT); | |
| 115 | 115 | ||
| 116 | 116 | var oldContent = "__Before submitting a pull request, please ensure " + | |
| 117 | - "both unit tests and lint checks pass.__"; | ||
| 117 | + "both unit tests and lint checks pass.__\n"; | ||
| 118 | 118 | assert.equal(lines[3].content(), oldContent); | |
| 119 | 119 | assert.equal(lines[3].origin(), Diff.LINE.DELETION); | |
| 120 | - assert.equal(lines[3].contentLen(), oldContent.length); | ||
| 120 | + assert.equal(lines[3].content().length, oldContent.length); | ||
| 121 | 121 | ||
| 122 | 122 | var newContent = "__Before submitting a pull request, please ensure " + | |
| 123 | 123 | "both that you've added unit tests to cover your shiny new code, " + | |
| 124 | - "and that all unit tests and lint checks pass.__"; | ||
| 124 | + "and that all unit tests and lint checks pass.__\n"; | ||
| 125 | 125 | assert.equal(lines[4].content(), newContent); | |
| 126 | 126 | assert.equal(lines[4].origin(), Diff.LINE.ADDITION); | |
| 127 | - assert.equal(lines[4].contentLen(), newContent.length); | ||
| 127 | + assert.equal(lines[4].content().length, newContent.length); | ||
| 128 | 128 | }); | |
| 129 | 129 | }); | |
| 130 | 130 | ||
@@ -182,7 +182,7 @@ describe("Diff", function() { | |||
| 182 | 182 | }) | |
| 183 | 183 | .then(function(lines) { | |
| 184 | 184 | lines.forEach(function(line) { | |
| 185 | - assert(!/\n/.exec(line.content())); | ||
| 185 | + assert(/\n/.exec(line.content())); | ||
| 186 | 186 | assert(/\n/.exec(line.rawContent())); | |
| 187 | 187 | }); | |
| 188 | 188 | }); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -245,7 +245,7 @@ function stagingTest(staging, newFileContent) { | |||
| 245 | 245 | throw ("File change when no file change expected."); | |
| 246 | 246 | } | |
| 247 | 247 | } else { | |
| 248 | - assert(delta.newFile().mode() - delta.oldFile().mode() === | ||
| 248 | + assert(delta.newFile().mode() - delta.oldFile().mode() === | ||
| 249 | 249 | fileModeDifference); | |
| 250 | 250 | } | |
| 251 | 251 | return true; | |
@@ -265,7 +265,7 @@ function stagingTest(staging, newFileContent) { | |||
| 265 | 265 | fileContent) | |
| 266 | 266 | .then(function() { | |
| 267 | 267 | //Then, change the permission locally. | |
| 268 | - return fse.chmod(path.join(test.repository.workdir(), fileName), | ||
| 268 | + return fse.chmod(path.join(test.repository.workdir(), fileName), | ||
| 269 | 269 | 0755 /* new filemode */); | |
| 270 | 270 | }); | |
| 271 | 271 | }) | |
@@ -310,7 +310,7 @@ function stagingTest(staging, newFileContent) { | |||
| 310 | 310 | fileContent) | |
| 311 | 311 | .then(function() { | |
| 312 | 312 | //Then, change the permission locally. | |
| 313 | - return fse.chmod(path.join(test.repository.workdir(), fileName), | ||
| 313 | + return fse.chmod(path.join(test.repository.workdir(), fileName), | ||
| 314 | 314 | 0755 /* new filemode */); | |
| 315 | 315 | }); | |
| 316 | 316 | }) | |
| Back | FazBrowse Home | New Git URL |
0 commit comments