Skip to content

Commit

Permalink
Fix #41 Ignore casing when renaming build stages
Browse files Browse the repository at this point in the history
Signed-off-by: Remy Suen <[email protected]>
  • Loading branch information
rcjsuen committed Dec 22, 2018
1 parent 3ad1030 commit b06bf63
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ All notable changes to this project will be documented in this file.
- ignore variables when validating directories for ARGs and COPYs ([rcjsuen/dockerfile-utils#54](https://github.com/rcjsuen/dockerfile-utils/issues/54))
- allow build stages to be case insensitive when looking up its definition ([#41](https://github.com/rcjsuen/dockerfile-language-service/issues/41))
- allow build stages to be case insensitive when highlighting them ([#41](https://github.com/rcjsuen/dockerfile-language-service/issues/41))
- allow build stages to be case insensitive when renaming them ([#41](https://github.com/rcjsuen/dockerfile-language-service/issues/41))

## [0.0.6] - 2018-08-19
### Added
Expand Down
53 changes: 53 additions & 0 deletions test/dockerRename.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,23 @@ describe("Dockerfile Document Rename tests", function () {
assert.equal(edits.length, 2);
assertEdit(edits[0], "renamed", 0, 13, 0, 22);
assertEdit(edits[1], "renamed", 2, 12, 2, 21);

content = "FROM node AS bootstrap\nCOPY --from=BOOTSTRAP /git/bin/app .";
// cursor in the FROM
range = prepareRename(content, 0, 17);
assertRange(range, 0, 13, 0, 22);
edits = rename(content, 0, 17, "renamed");
assert.equal(edits.length, 2);
assertEdit(edits[0], "renamed", 0, 13, 0, 22);
assertEdit(edits[1], "renamed", 1, 12, 1, 21);

// cursor in the COPY
range = prepareRename(content, 1, 16);
assertRange(range, 1, 12, 1, 21);
edits = rename(content, 1, 16, "renamed");
assert.equal(edits.length, 2);
assertEdit(edits[0], "renamed", 0, 13, 0, 22);
assertEdit(edits[1], "renamed", 1, 12, 1, 21);
});

it("COPY incomplete", function () {
Expand All @@ -94,6 +111,23 @@ describe("Dockerfile Document Rename tests", function () {
assert.equal(edits.length, 2);
assertEdit(edits[0], "renamed", 0, 13, 0, 22);
assertEdit(edits[1], "renamed", 2, 12, 2, 21);

content = "FROM node AS bootstrap\nFROM node\nCOPY --from=BOOTSTRAP";
// cursor in the FROM
range = prepareRename(content, 0, 17);
assertRange(range, 0, 13, 0, 22);
edits = rename(content, 0, 17, "renamed");
assert.equal(edits.length, 2);
assertEdit(edits[0], "renamed", 0, 13, 0, 22);
assertEdit(edits[1], "renamed", 2, 12, 2, 21);

// cursor in the COPY
range = prepareRename(content, 2, 16);
assertRange(range, 2, 12, 2, 21);
edits = rename(content, 2, 16, "renamed");
assert.equal(edits.length, 2);
assertEdit(edits[0], "renamed", 0, 13, 0, 22);
assertEdit(edits[1], "renamed", 2, 12, 2, 21);
});

it("source mismatch", function () {
Expand All @@ -120,6 +154,25 @@ describe("Dockerfile Document Rename tests", function () {
assert.equal(edits.length, 1);
assertEdit(edits[0], "renamed", 0, 13, 0, 22);
});

it("no FROM but identical COPYs", function () {
let content = "FROM node\nCOPY --from=dev\nCOPY --from=dev /git/bin/app .";
// cursor in the first COPY
let range = prepareRename(content, 1, 13);
assertRange(range, 1, 12, 1, 15);
let edits = rename(content, 1, 13, "renamed");
assert.equal(edits.length, 2);
assertEdit(edits[0], "renamed", 1, 12, 1, 15);
assertEdit(edits[1], "renamed", 2, 12, 2, 15);

// cursor in the second COPY
range = prepareRename(content, 2, 13);
assertRange(range, 2, 12, 2, 15);
edits = rename(content, 1, 13, "renamed");
assert.equal(edits.length, 2);
assertEdit(edits[0], "renamed", 1, 12, 1, 15);
assertEdit(edits[1], "renamed", 2, 12, 2, 15);
});
});

describe("invalid", function () {
Expand Down

0 comments on commit b06bf63

Please sign in to comment.