Skip to content
This repository has been archived by the owner on Sep 6, 2021. It is now read-only.

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ficristo committed Feb 2, 2016
1 parent 277ea9e commit 87c2d6b
Showing 1 changed file with 60 additions and 0 deletions.
60 changes: 60 additions & 0 deletions test/spec/FindReplace-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1423,6 +1423,66 @@ define(function (require, exports, module) {
expect(/_modules\/Foo-Foo\$&/i.test(myEditor.getSelectedText())).toBe(true);
});
});

it("should replace a string with \\r\\n\\t chars", function () {
runs(function () {
twCommandManager.execute(Commands.CMD_REPLACE);
enterSearchText("Foo");
enterReplaceText("\\r\\n\\t");

var expectedMatch = {start: {line: LINE_FIRST_REQUIRE, ch: 8}, end: {line: LINE_FIRST_REQUIRE, ch: 11}};

expectSelection(expectedMatch);
expect(/Foo/.test(myEditor.getSelectedText())).toBe(true);

expect(tw$("#replace-yes").is(":enabled")).toBe(true);
tw$("#replace-yes").click();

myEditor.setSelection({line: LINE_FIRST_REQUIRE, ch: 8}, {line: LINE_FIRST_REQUIRE, ch: 14});
expect(myEditor.getSelectedText()).toEqual("\\r\\n\\t");
});
});

it("should replace a string with \\r\\n\\t chars in regex mode", function () {
runs(function () {
twCommandManager.execute(Commands.CMD_REPLACE);
toggleRegexp(true);
enterSearchText("Foo");
enterReplaceText("\\\\r\\\\n\\\\t");

var expectedMatch = {start: {line: LINE_FIRST_REQUIRE, ch: 8}, end: {line: LINE_FIRST_REQUIRE, ch: 11}};

expectSelection(expectedMatch);
expect(/Foo/.test(myEditor.getSelectedText())).toBe(true);

expect(tw$("#replace-yes").is(":enabled")).toBe(true);
tw$("#replace-yes").click();

myEditor.setSelection({line: LINE_FIRST_REQUIRE, ch: 8}, {line: LINE_FIRST_REQUIRE, ch: 14});
expect(myEditor.getSelectedText()).toEqual("\\r\\n\\t");
});
});

it("should replace a string with a new line and a tab in regex mode", function () {
runs(function () {
twCommandManager.execute(Commands.CMD_REPLACE);
toggleRegexp(true);
enterSearchText("Foo");
enterReplaceText("\\r\\n\\t");

var expectedMatch = {start: {line: LINE_FIRST_REQUIRE, ch: 8}, end: {line: LINE_FIRST_REQUIRE, ch: 11}};

expectSelection(expectedMatch);
expect(/Foo/.test(myEditor.getSelectedText())).toBe(true);

expect(tw$("#replace-yes").is(":enabled")).toBe(true);
tw$("#replace-yes").click();

myEditor.setSelection({line: LINE_FIRST_REQUIRE, ch: 8}, {line: LINE_FIRST_REQUIRE + 1, ch: 3});
// FIXME: How can be the original line endings converted to \r\n?

This comment has been minimized.

Copy link
@ficristo

ficristo Feb 2, 2016

Author Collaborator

@redmunds Is there an api to easily change the line endings?

This comment has been minimized.

Copy link
@redmunds

redmunds Feb 2, 2016

Contributor

@ficristo Use FileUtils.getPlatformLineEndings()

This comment has been minimized.

Copy link
@ficristo

ficristo Feb 3, 2016

Author Collaborator

@redmunds The problem is the test created with \n line ending.
To test the \r case I need a document with \r\n line ending.
If I understood correctly codemirror always normalize line ending to \n.
So I need to create the test snippet with \r\n line ending or I don't see a way to test the \r case.

This comment has been minimized.

Copy link
@redmunds

redmunds Feb 3, 2016

Contributor

@ficristo Yes, when files are in memory, they are normalized to \n. This simplifies CodeMirror/Brackets code. Lineendings are converted back to the proper platform-specific lineendings when written to disk.

You could create an in-memory file that uses \r\n instead, but I don't think that's useful because users would never hit that case.

Instead, I think your code should automatically convert \r and \r\n to \n so it's correct internally, and then it will get converted to the proper platform-specific lineendings when written to disk.

The API for converting lineendings this is FileUtils.translateLineEndings().

expect(myEditor.getSelectedText()).toEqual("\n\t =");
});
});
});


Expand Down

0 comments on commit 87c2d6b

Please sign in to comment.