diff options
| author | Joel Klinghed <the_jk@spawned.biz> | 2025-09-28 22:53:30 +0200 |
|---|---|---|
| committer | Joel Klinghed <the_jk@spawned.biz> | 2025-09-29 09:39:17 +0200 |
| commit | 1e9e51dae1c01bab7562911b958c47528b8011c8 (patch) | |
| tree | 73e0c97545d1cf833a4205c8ced41c822b4bb348 /test/errors.cc | |
| parent | 0ca22c7d6d650c80906bd1217fccf32066cc2502 (diff) | |
java: Add tokens
Only parses Java 8 tokens for now.
Diffstat (limited to 'test/errors.cc')
| -rw-r--r-- | test/errors.cc | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/test/errors.cc b/test/errors.cc new file mode 100644 index 0000000..7d77000 --- /dev/null +++ b/test/errors.cc @@ -0,0 +1,47 @@ +#include "errors.hh" + +#include "location.hh" + +#include <gtest/gtest.h> +#include <memory> +#include <sstream> + +namespace { + +void generate(src::Errors& errors) { + errors.err(src::Location(1, 10), "Fatal error"); + errors.warn(src::Location(2, 0), "This is a warning"); + errors.dbg(src::Location(10, 1000), "Debugging"); + errors.err(src::Location(2, 100), "Another errors error"); +} + +} // namespace + +TEST(errors, ignore) { + auto errors = src::ignore_errors(); + generate(*errors); + EXPECT_EQ(0, errors->errors()); + EXPECT_EQ(0, errors->warnings()); +} + +TEST(errors, stream) { + std::stringstream ss; + std::shared_ptr<src::ErrorsOutput> output = src::errors_output_ios(ss); + auto errors = src::file_errors("filename", output); + generate(*errors); + EXPECT_EQ(2, errors->errors()); + EXPECT_EQ(1, errors->warnings()); + + EXPECT_EQ(R"(filename:1:10: Error: Fatal error +filename:2:0: Warning: This is a warning +filename:10:1000: Debug: Debugging +filename:2:100: Error: Another errors error +)", + ss.str()); +} + +TEST(location, out) { + std::stringstream ss; + ss << src::Location(1, 10); + EXPECT_EQ("1:10", ss.str()); +} |
