From a11240549a1dc055f58802f117346403d6d531e4 Mon Sep 17 00:00:00 2001 From: Joshua Baker Date: Mon, 16 Dec 2024 13:32:46 -0600 Subject: [PATCH] Add multiline tests --- tests/config/multiline-errors.conf | 20 ++++++++++++++++++++ tests/parse/main.cpp | 11 +++++++++++ 2 files changed, 31 insertions(+) create mode 100644 tests/config/multiline-errors.conf diff --git a/tests/config/multiline-errors.conf b/tests/config/multiline-errors.conf new file mode 100644 index 0000000..9ea2c28 --- /dev/null +++ b/tests/config/multiline-errors.conf @@ -0,0 +1,20 @@ +# Careful when modifying this file. Line numbers are part of the test. + +multiline = \ + one \ + two \ + three + +# Line numbers reported in errors should match the actual line numbers of the source file +# even after multi-line configs. Any errors reported should use the line number of the +# first line of any multi-line config. + +this \ + should \ + cause \ + error \ + on \ + line \ + 12 + +# A config file cannot end with a bashslash because we are expecting another line! Even in a comment! \ diff --git a/tests/parse/main.cpp b/tests/parse/main.cpp index 0fc05c9..521376d 100755 --- a/tests/parse/main.cpp +++ b/tests/parse/main.cpp @@ -302,6 +302,17 @@ int main(int argc, char** argv, char** envp) { EXPECT(ERRORS2.error, true); const auto ERRORSTR2 = std::string{ERRORS2.getError()}; EXPECT(std::count(ERRORSTR2.begin(), ERRORSTR2.end(), '\n'), 9 - 1); + + Hyprlang::CConfig multilineErrorConfig("./config/multiline-errors.conf", {.verifyOnly = true, .throwAllErrors = true}); + multilineErrorConfig.commence(); + const auto ERRORS3 = multilineErrorConfig.parse(); + EXPECT(ERRORS3.error, true); + const auto ERRORSTR3 = std::string{ERRORS3.getError()}; + + // Error on line 12 + EXPECT(ERRORSTR3.contains("12"), true); + // Backslash at end of file + EXPECT(ERRORSTR3.contains("backslash"), true); } catch (const char* e) { std::cout << Colors::RED << "Error: " << Colors::RESET << e << "\n"; return 1;