-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add config "line_separator" which supports the following options input: Determine line separator by the input content. This is the default. os: Determine line separator by the operating system lf: Use Unix Style ("\n") cr: Use classic Max Style ("\r") crlf: Use Windows Style ("\r\n") Note that the default behavior is changed. The previous behavior is "os", but I think "input" is a more appropriate default.
- Loading branch information
1 parent
78b3d90
commit 2aafa70
Showing
9 changed files
with
218 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
* text=auto eol=lf | ||
*.a filter=lfs diff=lfs merge=lfs -text |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#include <catch2/catch.hpp> | ||
|
||
#include "lua-format.h" | ||
|
||
TEST_CASE("get_line_separator", "line_separator") { | ||
REQUIRE(get_line_separator("\n") == "\n"); | ||
REQUIRE(get_line_separator("\r") == "\r"); | ||
REQUIRE(get_line_separator("\r\n") == "\r\n"); | ||
|
||
REQUIRE(get_line_separator("1\n2\n3\n") == "\n"); | ||
REQUIRE(get_line_separator("1\r\n2\r\n3\r\n") == "\r\n"); | ||
REQUIRE(get_line_separator("1\r2\r3\r") == "\r"); | ||
|
||
// Different separator appears equal times | ||
REQUIRE(get_line_separator("") == "\n"); | ||
REQUIRE(get_line_separator("\r\n\n\r") == "\n"); | ||
REQUIRE(get_line_separator("\n\r") == "\n"); | ||
REQUIRE(get_line_separator("\r\n\r") == "\r\n"); | ||
REQUIRE(get_line_separator("1\r\n2\n3\r") == "\n"); | ||
|
||
// Different separator appears different times | ||
REQUIRE(get_line_separator("1\r\n2\r\n3\n") == "\r\n"); | ||
REQUIRE(get_line_separator("1\n2\r\n3\r\n") == "\r\n"); | ||
REQUIRE(get_line_separator("1\r2\n3\n") == "\n"); | ||
REQUIRE(get_line_separator("1\n2\r3\r") == "\r"); | ||
} | ||
|
||
TEST_CASE("convert_line_separator", "line_separator") { | ||
REQUIRE(convert_line_separator("", "\r\n").empty()); | ||
REQUIRE(convert_line_separator("", "\n").empty()); | ||
REQUIRE(convert_line_separator("", "\r").empty()); | ||
|
||
REQUIRE(convert_line_separator("1\r\n2\r\n3\r\n", "\n") == "1\n2\n3\n"); | ||
REQUIRE(convert_line_separator("1\r\n2\r\n3\r\n", "\r") == "1\r2\r3\r"); | ||
REQUIRE(convert_line_separator("1\r\n2\r\n3\r\n", "\r\n") == "1\r\n2\r\n3\r\n"); | ||
|
||
REQUIRE(convert_line_separator("1\n2\n3\n", "\n") == "1\n2\n3\n"); | ||
REQUIRE(convert_line_separator("1\n2\n3\n", "\r") == "1\r2\r3\r"); | ||
REQUIRE(convert_line_separator("1\n2\n3\n", "\r\n") == "1\r\n2\r\n3\r\n"); | ||
|
||
REQUIRE(convert_line_separator("1\r2\r3\r", "\n") == "1\n2\n3\n"); | ||
REQUIRE(convert_line_separator("1\r2\r3\r", "\r") == "1\r2\r3\r"); | ||
REQUIRE(convert_line_separator("1\r2\r3\r", "\r\n") == "1\r\n2\r\n3\r\n"); | ||
} |