Skip to content

Commit

Permalink
Fix issues reported by codacy
Browse files Browse the repository at this point in the history
Signed-off-by: Jose Ricardo Ziviani <[email protected]>
  • Loading branch information
jrziviani committed Feb 3, 2019
1 parent de80c37 commit e2e5c83
Show file tree
Hide file tree
Showing 10 changed files with 54 additions and 109 deletions.
27 changes: 0 additions & 27 deletions .github/ISSUE_TEMPLATE/bug_report.md

This file was deleted.

20 changes: 0 additions & 20 deletions .github/ISSUE_TEMPLATE/feature_request.md

This file was deleted.

14 changes: 0 additions & 14 deletions .github/PULL_REQUEST_TEMPLATE.md

This file was deleted.

2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ after_success:
- lcov --remove coverage.info '/usr/*' --output-file coverage.info
- lcov --list coverage.info
- bash <(curl -s https://codecov.io/bash) -f coverage.info || "Codecov didn't collect coverage reports"
- coveralls --build-root .build/release --gcov-options '\-lp' -e sample -e .build/release/CMakeFiles -e .build/release/googletest-src -e .build/debug
- coveralls --build-root .build/release --gcov-options '\-lp' -e sample -e .build/release/CMakeFiles -e .build/release/googletest-src -e .build/debug
addons:
apt:
sources:
Expand Down
6 changes: 3 additions & 3 deletions .vs/launch.vs.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
"type": "default",
"project": "CMakeLists.txt",
"projectTarget": "amps_sample.exe (bin\\amps_sample.exe)",
"name": "amps_sample.exe (bin\\amps_sample.exe)"
"args": ["template.tpl"]
"name": "amps_sample.exe (bin\\amps_sample.exe)",
"args": ["template.tpl"]
},
{
"type": "dll",
Expand All @@ -22,4 +22,4 @@
"project": ""
}
]
}
}
10 changes: 5 additions & 5 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ Amps - Simple Template Engine for C++
Index
-----

* [Introduction](#Introduction)
* [What it does](#What-it-does)
* [Building](#Building)
* [Testing](#Testing)
* [Introduction](#Introduction)
* [What it does](#What-it-does)
* [Building](#Building)
* [Testing](#Testing)

Introduction
------------
Expand Down Expand Up @@ -196,6 +196,6 @@ Or building a static library version for both, cleaning the current tree:
Testing
-------

```
```shell
% ./build --test
```
17 changes: 11 additions & 6 deletions include/fileops.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ namespace amps
file.is_file = ((buffer.st_mode & S_IFMT) == S_IFREG) ? true : false;
file.is_directory = ((buffer.st_mode & S_IFMT) == S_IFDIR) ? true : false;
#else
file.is_readable = true;
file.is_writable = false;
file.is_file = true;
file.is_directory = false;
file.is_readable = true;
file.is_writable = false;
file.is_file = true;
file.is_directory = false;
#endif
return file;
}
Expand Down Expand Up @@ -72,8 +72,13 @@ namespace amps
return "";
}

std::string content(MAX_READ_SZ + 1, '\0');
file.read(&content[0], static_cast<std::streamsize>(MAX_READ_SZ));
std::string content;
file.seekg(0, std::ios::end);
content.reserve(file.tellg());
file.seekg(0, std::ios::beg);

content.assign((std::istreambuf_iterator<char>(file)),
std::istreambuf_iterator<char>());
return content;
}

Expand Down
16 changes: 8 additions & 8 deletions src/engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,16 @@ namespace amps
return;
}

string content(MAX_READ_SZ + 1, '\0');
std::string content;
file.seekg(0, std::ios::end);
content.reserve(file.tellg());
file.seekg(0, std::ios::beg);

while (true) {
file.read(&content[0], static_cast<streamsize>(MAX_READ_SZ));
scanner_.do_scan(content);
content.assign((std::istreambuf_iterator<char>(file)),
std::istreambuf_iterator<char>());

scanner_.do_scan(content);

if (file.eof()) {
break;
}
}
}

std::string engine::render(const user_map &um)
Expand Down
18 changes: 8 additions & 10 deletions test/test_compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,14 @@ class compiler_test : public ::testing::Test
void set_file(const std::string &filename)
{
std::ifstream file(filename);
std::string content(1024 + 1, '\0');

while (true) {
file.read(&content[0], static_cast<std::streamsize>(1024));
scan_.do_scan(content);

if (file.eof()) {
break;
}
}
std::string content;
file.seekg(0, std::ios::end);
content.reserve(file.tellg());
file.seekg(0, std::ios::beg);

content.assign((std::istreambuf_iterator<char>(file)),
std::istreambuf_iterator<char>());
scan_.do_scan(content);
}

std::string compile()
Expand Down
33 changes: 18 additions & 15 deletions test/test_scan.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ TEST_F (scan_test, invalid_to_text_blocks)
scan_.do_scan(content);
auto &data = scan_.get_metainfo();

if (data.size() == 0) {
step++;
continue;
}
if (data.size() == 0) {
step++;
continue;
}

switch (step++) {
case 0:
Expand Down Expand Up @@ -77,22 +77,25 @@ TEST_F (scan_test, valid_and_invalid_blocks_all)
using amps::metatype;
using testing::StartsWith;

std::array<metatype, 28> expected = {
std::array<metatype, 33> expected = {
metatype::CODE, metatype::COMMENT, metatype::CODE, metatype::COMMENT, metatype::CODE,
metatype::COMMENT, metatype::TEXT, metatype::TEXT, metatype::TEXT, metatype::TEXT,
metatype::TEXT, metatype::ECHO, metatype::CODE, metatype::CODE, metatype::CODE,
metatype::CODE, metatype::TEXT, metatype::TEXT, metatype::TEXT, metatype::TEXT,
metatype::TEXT, metatype::CODE, metatype::ECHO, metatype::ECHO, metatype::ECHO,
metatype::TEXT, metatype::TEXT,
metatype::TEXT, metatype::ECHO, metatype::TEXT, metatype::CODE, metatype::CODE,
metatype::CODE, metatype::CODE, metatype::TEXT, metatype::TEXT, metatype::TEXT,
metatype::TEXT, metatype::COMMENT, metatype::CODE, metatype::TEXT, metatype::ECHO,
metatype::TEXT, metatype::ECHO, metatype::TEXT, metatype::ECHO, metatype::TEXT,
metatype::COMMENT, metatype::TEXT, metatype::TEXT,
};

std::ifstream file("block.2");
std::string content;

std::string content(512 + 1, '\0');
file.read(&content[0], static_cast<std::streamsize>(512));
content.assign((std::istreambuf_iterator<char>(file)),
std::istreambuf_iterator<char>());
scan_.do_scan(content);
auto &data = scan_.get_metainfo();

auto &data = scan_.get_metainfo();
EXPECT_EQ(data.size(), expected.size());
for (size_t i = 0; i < data.size(); ++i) {
EXPECT_EQ(data[i].type, expected[i]);
}
Expand Down Expand Up @@ -128,9 +131,9 @@ TEST_F (scan_test, valid_and_invalid_blocks)
scan_.do_scan(content);
auto &data = scan_.get_metainfo();

if (data.size() == 0) {
continue;
}
if (data.size() == 0) {
continue;
}

EXPECT_EQ(data[0].type, expected[i]);
if (errors_expected[i].size() > 0 || error_.get_last_error_msg().size() > 0) {
Expand Down

0 comments on commit e2e5c83

Please sign in to comment.