Skip to content
This repository was archived by the owner on Feb 24, 2024. It is now read-only.

Commit 2185961

Browse files
committed
Remove redundant empty lines if the parsed file doesn't have system includes
Add unit test for scenario from issue #6.
1 parent 7769c21 commit 2185961

File tree

7 files changed

+33
-2
lines changed

7 files changed

+33
-2
lines changed

src/parse/CppFileMerger.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@ export default class CppFileMerger {
3636
systemIncludesContent,
3737
content,
3838
sourceFilesContent
39-
].join(EOL);
39+
]
40+
.filter(content => !!content)
41+
.join(EOL);
4042

4143
return removeDoubleEmptyLines(finalContent);
4244
}

test/data/circularDependencies/expected.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,3 @@
55
// first.hpp
66

77
// main.cpp
8-
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#pragma once
2+
3+
#include "b.hpp"
4+
5+
// a.hpp
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
2+
// include/b.hpp
3+
4+
// a.hpp
5+
6+
// main.cpp
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#pragma once
2+
3+
// include/b.hpp
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#include "a.hpp"
2+
3+
// main.cpp

test/unit/parse/CppFileMerger.test.ts

+13
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,16 @@ describe("Merging files with circular dependencies", () => {
4949
expect(content).toEqual(expected);
5050
});
5151
});
52+
53+
describe("Merging source with header including another header from include directory", () => {
54+
const dataDirectory = "test/data/headerIncludeHeaderInSubdirectory";
55+
const merger = new CppFileMerger({
56+
includeDirectory: `${dataDirectory}/include`
57+
});
58+
const content = merger.parse(`${dataDirectory}/main.cpp`);
59+
60+
test("Generated content equals expected", () => {
61+
const expected = fs.readFileSync(`${dataDirectory}/expected.cpp`, "utf-8");
62+
expect(content).toEqual(expected);
63+
});
64+
});

0 commit comments

Comments
 (0)