Browse Source

Everywhere: Move everything in namescape Util => ruc

master
Riyyi 2 years ago
parent
commit
be73ba335e
  1. 2
      CMakeLists.txt
  2. 6
      src/ruc/argparser.cpp
  3. 4
      src/ruc/argparser.h
  4. 10
      src/ruc/file.cpp
  5. 4
      src/ruc/file.h
  6. 0
      src/ruc/format/.clang-tidy
  7. 10
      src/ruc/format/builder.cpp
  8. 4
      src/ruc/format/builder.h
  9. 10
      src/ruc/format/color.cpp
  10. 19
      src/ruc/format/color.h
  11. 12
      src/ruc/format/format.cpp
  12. 17
      src/ruc/format/format.h
  13. 10
      src/ruc/format/formatter.cpp
  14. 10
      src/ruc/format/formatter.h
  15. 8
      src/ruc/format/log.cpp
  16. 30
      src/ruc/format/log.h
  17. 16
      src/ruc/format/parser.cpp
  18. 6
      src/ruc/format/parser.h
  19. 6
      src/ruc/format/print.cpp
  20. 17
      src/ruc/format/print.h
  21. 8
      src/ruc/genericlexer.cpp
  22. 4
      src/ruc/genericlexer.h
  23. 8
      src/ruc/json/array.cpp
  24. 9
      src/ruc/json/array.h
  25. 18
      src/ruc/json/fromjson.h
  26. 12
      src/ruc/json/job.cpp
  27. 6
      src/ruc/json/job.h
  28. 15
      src/ruc/json/json.h
  29. 8
      src/ruc/json/lexer.cpp
  30. 8
      src/ruc/json/lexer.h
  31. 8
      src/ruc/json/object.cpp
  32. 6
      src/ruc/json/object.h
  33. 18
      src/ruc/json/parser.cpp
  34. 6
      src/ruc/json/parser.h
  35. 12
      src/ruc/json/serializer.cpp
  36. 6
      src/ruc/json/serializer.h
  37. 16
      src/ruc/json/tojson.h
  38. 20
      src/ruc/json/value.cpp
  39. 38
      src/ruc/json/value.h
  40. 14
      src/ruc/meta/assert.h
  41. 0
      src/ruc/meta/compiler.h
  42. 8
      src/ruc/meta/concepts.h
  43. 8
      src/ruc/meta/odr.h
  44. 6
      src/ruc/shell.cpp
  45. 4
      src/ruc/shell.h
  46. 4
      src/ruc/singleton.h
  47. 6
      src/ruc/system.cpp
  48. 4
      src/ruc/system.h
  49. 6
      src/ruc/timer.cpp
  50. 4
      src/ruc/timer.h
  51. 15
      src/util/json/json.h
  52. 6
      test/macro.h
  53. 2
      test/main.cpp
  54. 6
      test/testcase.h
  55. 14
      test/testsuite.cpp
  56. 8
      test/testsuite.h
  57. 180
      test/unit/testutilargparser.cpp
  58. 232
      test/unit/testutilformat.cpp
  59. 166
      test/unit/testutiljson.cpp
  60. 8
      test/unit/testutilshell.cpp
  61. 27
      test/unit/testutilsystem.cpp

2
CMakeLists.txt

@ -63,7 +63,7 @@ target_include_directories(${PROJECT} PRIVATE
# Unit test library target
# Define source files
file(GLOB TEST_LIBRARY_SOURCES "test/*.cpp" "src/util/timer.cpp")
file(GLOB TEST_LIBRARY_SOURCES "test/*.cpp" "src/ruc/timer.cpp")
add_library(${PROJECT}-test STATIC ${TEST_LIBRARY_SOURCES})
target_include_directories(${PROJECT}-test PRIVATE

6
src/util/argparser.cpp → src/ruc/argparser.cpp

@ -14,9 +14,9 @@
#include <string_view>
#include <vector>
#include "util/argparser.h"
#include "ruc/argparser.h"
namespace Util {
namespace ruc {
ArgParser::ArgParser()
{
@ -565,4 +565,4 @@ AcceptFunction ArgParser::getAcceptFunction(std::vector<std::string>& value)
};
}
} // namespace Util
} // namespace ruc

4
src/util/argparser.h → src/ruc/argparser.h

@ -13,7 +13,7 @@
#include <string_view>
#include <vector>
namespace Util {
namespace ruc {
using AcceptFunction = std::function<bool(const char*)>;
@ -117,4 +117,4 @@ private:
std::vector<Argument> m_arguments;
};
} // namespace Util
} // namespace ruc

10
src/util/file.cpp → src/ruc/file.cpp

@ -10,10 +10,10 @@
#include <memory> // make_unique
#include <string>
#include "util/file.h"
#include "util/meta/assert.h"
#include "ruc/file.h"
#include "ruc/meta/assert.h"
namespace Util {
namespace ruc {
File::File(const std::string& path)
: m_path(path)
@ -50,7 +50,7 @@ File File::create(const std::string& path)
std::ofstream { path };
}
return Util::File(path);
return File(path);
}
// -----------------------------------------
@ -86,4 +86,4 @@ File& File::flush()
return *this;
}
} // namespace Util
} // namespace ruc

4
src/util/file.h → src/ruc/file.h

@ -8,7 +8,7 @@
#include <string>
namespace Util {
namespace ruc {
class File {
public:
@ -31,4 +31,4 @@ private:
std::string m_data;
};
} // namespace Util
} // namespace ruc

0
src/util/format/.clang-tidy → src/ruc/format/.clang-tidy

10
src/util/format/builder.cpp → src/ruc/format/builder.cpp

@ -14,11 +14,11 @@
#include <string>
#include <string_view>
#include "util/format/builder.h"
#include "util/format/parser.h"
#include "util/meta/assert.h"
#include "ruc/format/builder.h"
#include "ruc/format/parser.h"
#include "ruc/meta/assert.h"
namespace Util::Format {
namespace ruc::format {
void Builder::putLiteral(std::string_view literal)
{
@ -219,4 +219,4 @@ void Builder::putString(std::string_view string, char fill, Align align, size_t
};
}
} // namespace Util::Format
} // namespace ruc::format

4
src/util/format/builder.h → src/ruc/format/builder.h

@ -11,7 +11,7 @@
#include <sstream> // stringstream
#include <string_view>
namespace Util::Format {
namespace ruc::format {
class Builder {
public:
@ -68,7 +68,7 @@ private:
std::stringstream& m_builder;
};
} // namespace Util::Format
} // namespace ruc::format
#if 0
// Defaults based on type

10
src/util/format/color.cpp → src/ruc/format/color.cpp

@ -10,11 +10,11 @@
#include <string>
#include <string_view>
#include "util/format/color.h"
#include "util/format/format.h"
#include "util/meta/assert.h"
#include "ruc/format/color.h"
#include "ruc/format/format.h"
#include "ruc/meta/assert.h"
namespace Util::Format {
namespace ruc::format {
TextStyle::TextStyle(Emphasis emphasis)
: m_emphasis(emphasis)
@ -173,4 +173,4 @@ ColorPrintOperatorStyle print(FILE* file, const TextStyle& style)
return ColorPrintOperatorStyle(file, style);
}
} // namespace Util::Format
} // namespace ruc::format

19
src/util/format/color.h → src/ruc/format/color.h

@ -12,9 +12,9 @@
#include <sstream> // stringstream
#include <string_view>
#include "util/format/format.h"
#include "ruc/format/format.h"
namespace Util::Format {
namespace ruc::format {
enum class TerminalColor : uint8_t {
None = 0,
@ -138,19 +138,16 @@ private:
template<typename T>
const ColorPrintOperatorStyle& operator<<(const ColorPrintOperatorStyle& colorPrintOperatorStyle, const T& value)
{
_format(const_cast<ColorPrintOperatorStyle&>(colorPrintOperatorStyle).builder(), value);
Formatter<T> formatter;
formatter.format(const_cast<ColorPrintOperatorStyle&>(colorPrintOperatorStyle).builder(), value);
return colorPrintOperatorStyle;
}
ColorPrintOperatorStyle print(const TextStyle& style);
ColorPrintOperatorStyle print(FILE* file, const TextStyle& style);
} // namespace Util::Format
} // namespace ruc::format
namespace Util {
using Util::Format::format;
using Util::Format::formatTo;
using Util::Format::print;
} // namespace Util
using ruc::format::format;
using ruc::format::formatTo;
using ruc::format::print;

12
src/util/format/format.cpp → src/ruc/format/format.cpp

@ -8,12 +8,12 @@
#include <string>
#include <string_view>
#include "util/format/builder.h"
#include "util/format/format.h"
#include "util/format/parser.h"
#include "util/meta/assert.h"
#include "ruc/format/builder.h"
#include "ruc/format/format.h"
#include "ruc/format/parser.h"
#include "ruc/meta/assert.h"
namespace Util::Format {
namespace ruc::format {
void variadicFormatImpl(Builder& builder, Parser& parser, TypeErasedParameters& parameters)
{
@ -73,4 +73,4 @@ FormatOperatorStyle formatTo(std::string& output)
return FormatOperatorStyle(output);
}
} // namespace Util::Format
} // namespace ruc::format

17
src/util/format/format.h → src/ruc/format/format.h

@ -12,9 +12,9 @@
#include <string>
#include <string_view>
#include "util/format/formatter.h"
#include "ruc/format/formatter.h"
namespace Util::Format {
namespace ruc::format {
class Builder;
class Parser;
@ -103,17 +103,14 @@ private:
template<typename T>
const FormatOperatorStyle& operator<<(const FormatOperatorStyle& formatOperatorStyle, const T& value)
{
_format(const_cast<FormatOperatorStyle&>(formatOperatorStyle).builder(), value);
Formatter<T> formatter;
formatter.format(const_cast<FormatOperatorStyle&>(formatOperatorStyle).builder(), value);
return formatOperatorStyle;
}
FormatOperatorStyle formatTo(std::string& output);
} // namespace Util::Format
namespace Util {
using Util::Format::format;
using Util::Format::formatTo;
} // namespace ruc::format
} // namespace Util
using ruc::format::format;
using ruc::format::formatTo;

10
src/util/format/formatter.cpp → src/ruc/format/formatter.cpp

@ -9,11 +9,11 @@
#include <string>
#include <string_view>
#include "util/format/builder.h"
#include "util/format/formatter.h"
#include "util/format/parser.h"
#include "ruc/format/builder.h"
#include "ruc/format/formatter.h"
#include "ruc/format/parser.h"
namespace Util::Format {
namespace ruc::format {
// Char
@ -114,4 +114,4 @@ type: {%c}
builder.putString(std::string_view(result));
}
} // namespace Util::Format
} // namespace ruc::format

10
src/util/format/formatter.h → src/ruc/format/formatter.h

@ -16,11 +16,11 @@
#include <unordered_map>
#include <vector>
#include "util/format/builder.h"
#include "util/format/parser.h"
#include "util/meta/concepts.h"
#include "ruc/format/builder.h"
#include "ruc/format/parser.h"
#include "ruc/meta/concepts.h"
namespace Util::Format {
namespace ruc::format {
enum class PresentationType : uint8_t {
None,
@ -312,7 +312,7 @@ struct Formatter<Specifier> : Formatter<std::nullptr_t> {
void format(Builder& builder, Specifier value) const;
};
} // namespace Util::Format
} // namespace ruc::format
#if 0

8
src/util/format/log.cpp → src/ruc/format/log.cpp

@ -7,10 +7,10 @@
#include <cstdio> // FILE
#include <string>
#include "util/format/color.h"
#include "util/format/log.h"
#include "ruc/format/color.h"
#include "ruc/format/log.h"
namespace Util::Format {
namespace ruc::format {
std::string formatTimeElapsed()
{
@ -106,4 +106,4 @@ LogOperatorStyle critical()
return LogOperatorStyle(stderr, LogType::Critical);
}
} // namespace Util::Format
} // namespace ruc::format

30
src/util/format/log.h → src/ruc/format/log.h

@ -10,13 +10,13 @@
#include <string>
#include <string_view>
#include "util/format/format.h"
#include "util/format/print.h"
#include "util/timer.h"
#include "ruc/format/format.h"
#include "ruc/format/print.h"
#include "ruc/timer.h"
namespace Util::Format {
namespace ruc::format {
static Util::Timer s_timer;
static Timer s_timer;
enum class LogType : uint8_t {
Trace, // White
@ -82,16 +82,16 @@ LogOperatorStyle warn();
LogOperatorStyle error();
LogOperatorStyle critical();
} // namespace Util::Format
} // namespace ruc::format
namespace Util {
namespace ruc {
using Util::Format::critical;
using Util::Format::debug;
using Util::Format::error;
using Util::Format::info;
using Util::Format::success;
using Util::Format::trace;
using Util::Format::warn;
using ruc::format::critical;
using ruc::format::debug;
using ruc::format::error;
using ruc::format::info;
using ruc::format::success;
using ruc::format::trace;
using ruc::format::warn;
} // namespace Util
} // namespace ruc

16
src/util/format/parser.cpp → src/ruc/format/parser.cpp

@ -11,13 +11,13 @@
#include <string>
#include <string_view>
#include "util/format/builder.h"
#include "util/format/formatter.h"
#include "util/format/parser.h"
#include "util/format/print.h"
#include "util/meta/assert.h"
#include "ruc/format/builder.h"
#include "ruc/format/formatter.h"
#include "ruc/format/parser.h"
#include "ruc/format/print.h"
#include "ruc/meta/assert.h"
namespace Util::Format {
namespace ruc::format {
Parser::Parser(std::string_view format, size_t parameterCount)
: GenericLexer(format)
@ -282,7 +282,7 @@ void Parser::parseSpecifier(Specifier& specifier, ParameterType type)
if (!p) {
p++;
Util::Format::print("{}\n", specifier);
print("{}\n", specifier);
}
}
@ -416,4 +416,4 @@ constexpr void Parser::checkSpecifierType(const Specifier& specifier, ParameterT
}
}
} // namespace Util::Format
} // namespace ruc::format

6
src/util/format/parser.h → src/ruc/format/parser.h

@ -10,9 +10,9 @@
#include <optional>
#include <string_view>
#include "util/genericlexer.h"
#include "ruc/genericlexer.h"
namespace Util::Format {
namespace ruc::format {
class Builder;
struct Specifier;
@ -58,4 +58,4 @@ private:
size_t m_parameterCount { 0 };
};
} // namespace Util::Format
} // namespace ruc::format

6
src/util/format/print.cpp → src/ruc/format/print.cpp

@ -11,9 +11,9 @@
#include <string>
#include <string_view>
#include "util/format/print.h"
#include "ruc/format/print.h"
namespace Util::Format {
namespace ruc::format {
void variadicPrint(FILE* file, std::string_view format, TypeErasedParameters& parameters)
{
@ -49,4 +49,4 @@ PrintOperatorStyle print(FILE* file)
return PrintOperatorStyle(file);
}
} // namespace Util::Format
} // namespace ruc::format

17
src/util/format/print.h → src/ruc/format/print.h

@ -11,10 +11,10 @@
#include <sstream> // stringstream
#include <string_view>
#include "util/format/format.h"
#include "util/timer.h"
#include "ruc/format/format.h"
#include "ruc/timer.h"
namespace Util::Format {
namespace ruc::format {
void variadicPrint(FILE* file, std::string_view format, TypeErasedParameters& parameters);
@ -51,7 +51,8 @@ private:
template<typename T>
const PrintOperatorStyle& operator<<(const PrintOperatorStyle& printOperatorStyle, const T& value)
{
_format(const_cast<PrintOperatorStyle&>(printOperatorStyle).builder(), value);
Formatter<T> formatter;
formatter.format(const_cast<PrintOperatorStyle&>(printOperatorStyle).builder(), value);
return printOperatorStyle;
}
@ -60,10 +61,6 @@ PrintOperatorStyle print(FILE* file);
// -----------------------------------------
} // namespace Util::Format
} // namespace ruc::format
namespace Util {
using Util::Format::print;
} // namespace Util
using ruc::format::print;

8
src/util/genericlexer.cpp → src/ruc/genericlexer.cpp

@ -6,10 +6,10 @@
#include <algorithm> // max, min
#include "util/genericlexer.h"
#include "util/meta/assert.h"
#include "ruc/genericlexer.h"
#include "ruc/meta/assert.h"
namespace Util {
namespace ruc {
GenericLexer::GenericLexer(std::string_view input)
: m_input(input)
@ -68,4 +68,4 @@ bool GenericLexer::consumeSpecific(const char& character)
return true;
}
} // namespace Util
} // namespace ruc

4
src/util/genericlexer.h → src/ruc/genericlexer.h

@ -9,7 +9,7 @@
#include <cstddef> // size_t
#include <string_view>
namespace Util {
namespace ruc {
class GenericLexer {
public:
@ -38,4 +38,4 @@ protected:
std::string_view m_input;
};
} // namespace Util
} // namespace ruc

8
src/util/json/array.cpp → src/ruc/json/array.cpp

@ -4,10 +4,10 @@
* SPDX-License-Identifier: MIT
*/
#include "util/json/array.h"
#include "util/json/value.h"
#include "ruc/json/array.h"
#include "ruc/json/value.h"
namespace Util::JSON {
namespace ruc::json {
void Array::emplace_back(Value element)
{
@ -23,4 +23,4 @@ Value& Array::operator[](size_t index)
return m_elements[index];
}
} // namespace Util::JSON
} // namespace ruc::json

9
src/util/json/array.h → src/ruc/json/array.h

@ -9,9 +9,9 @@
#include <utility> // move
#include <vector>
#include "util/json/parser.h"
#include "ruc/json/parser.h"
namespace Util::JSON {
namespace ruc::json {
class Value;
@ -22,7 +22,8 @@ public:
Array(const std::vector<Value>& elements)
: m_elements(elements)
{}
{
}
Array(const Array& other)
: m_elements(other.m_elements)
@ -53,4 +54,4 @@ private:
std::vector<Value> m_elements;
};
} // namespace Util::JSON
} // namespace ruc::json

18
src/util/json/fromjson.h → src/ruc/json/fromjson.h

@ -14,14 +14,14 @@
#include <utility> // forward
#include <vector>
#include "util/json/array.h"
#include "util/json/object.h"
#include "util/meta/assert.h"
#include "util/meta/odr.h"
#include "ruc/json/array.h"
#include "ruc/json/object.h"
#include "ruc/meta/assert.h"
#include "ruc/meta/odr.h"
namespace Util::JSON {
namespace ruc::json {
namespace Detail {
namespace detail {
// Required for containers with Json::Value type
template<typename Json>
@ -107,15 +107,15 @@ struct fromJsonFunction {
}
};
} // namespace Detail
} // namespace detail
// Anonymous namespace prevents multiple definition of the reference
namespace {
// Function object
constexpr const auto& fromJson = Util::Detail::staticConst<Detail::fromJsonFunction>; // NOLINT(misc-definitions-in-headers,clang-diagnostic-unused-variable)
constexpr const auto& fromJson = ruc::detail::staticConst<detail::fromJsonFunction>; // NOLINT(misc-definitions-in-headers,clang-diagnostic-unused-variable)
} // namespace
} // namespace Util::JSON
} // namespace ruc::json
// Customization Points
// https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/n4381.html

12
src/util/json/job.cpp → src/ruc/json/job.cpp

@ -8,12 +8,12 @@
#include <sstream> // istringstream
#include <string> // getline
#include "util/json/job.h"
#include "util/json/lexer.h"
#include "util/json/parser.h"
#include "util/json/value.h"
#include "ruc/json/job.h"
#include "ruc/json/lexer.h"
#include "ruc/json/parser.h"
#include "ruc/json/value.h"
namespace Util::JSON {
namespace ruc::json {
Job::Job(std::string_view input)
: m_input(input)
@ -111,4 +111,4 @@ void Job::printErrorLine(Token token, const char* message)
std::string(line.length() - token.column, '~').c_str());
}
} // namespace Util::JSON
} // namespace ruc::json

6
src/util/json/job.h → src/ruc/json/job.h

@ -10,9 +10,9 @@
#include <string_view>
#include <vector>
#include "util/json/lexer.h"
#include "ruc/json/lexer.h"
namespace Util::JSON {
namespace ruc::json {
class Value;
@ -38,4 +38,4 @@ private:
std::vector<Token> m_tokens;
};
} // namespace Util::JSON
} // namespace ruc::json

15
src/ruc/json/json.h

@ -0,0 +1,15 @@
/*
* Copyright (C) 2022 Riyyi
*
* SPDX-License-Identifier: MIT
*/
#pragma once
#include "ruc/json/value.h"
namespace ruc {
using Json = ruc::json::Value;
} // namespace ruc

8
src/util/json/lexer.cpp → src/ruc/json/lexer.cpp

@ -7,10 +7,10 @@
#include <cstddef>
#include <string>
#include "util/json/job.h"
#include "util/json/lexer.h"
#include "ruc/json/job.h"
#include "ruc/json/lexer.h"
namespace Util::JSON {
namespace ruc::json {
Lexer::Lexer(Job* job)
: GenericLexer(job->input())
@ -214,4 +214,4 @@ bool Lexer::consumeLiteral()
return consumeNumberOrLiteral(Token::Type::Literal);
}
} // namespace Util::JSON
} // namespace ruc::json

8
src/util/json/lexer.h → src/ruc/json/lexer.h

@ -14,9 +14,9 @@
#include <string>
#include <vector>
#include "util/genericlexer.h"
#include "ruc/genericlexer.h"
namespace Util::JSON {
namespace ruc::json {
class Job;
@ -41,7 +41,7 @@ struct Token {
};
// Lexical analyzer
class Lexer final : public Util::GenericLexer {
class Lexer final : public GenericLexer {
public:
Lexer(Job* job);
virtual ~Lexer();
@ -62,4 +62,4 @@ private:
std::vector<Token>* m_tokens { nullptr };
};
} // namespace Util::JSON
} // namespace ruc::json

8
src/util/json/object.cpp → src/ruc/json/object.cpp

@ -4,10 +4,10 @@
* SPDX-License-Identifier: MIT
*/
#include "util/json/object.h"
#include "util/json/value.h"
#include "ruc/json/object.h"
#include "ruc/json/value.h"
namespace Util::JSON {
namespace ruc::json {
void Object::emplace(const std::string& name, Value value)
{
@ -23,4 +23,4 @@ Value& Object::operator[](const std::string& name)
return m_members.at(name);
}
} // namespace Util::JSON
} // namespace ruc::json

6
src/util/json/object.h → src/ruc/json/object.h

@ -10,9 +10,9 @@
#include <string>
#include <utility> // move
#include "util/json/parser.h"
#include "ruc/json/parser.h"
namespace Util::JSON {
namespace ruc::json {
class Value;
@ -49,4 +49,4 @@ private:
std::map<std::string, Value> m_members;
};
} // namespace Util::JSON
} // namespace ruc::json

18
src/util/json/parser.cpp → src/ruc/json/parser.cpp

@ -11,15 +11,15 @@
#include <map>
#include <string> // stod
#include "util/json/array.h"
#include "util/json/job.h"
#include "util/json/lexer.h"
#include "util/json/object.h"
#include "util/json/parser.h"
#include "util/json/value.h"
#include "util/meta/assert.h"
#include "ruc/json/array.h"
#include "ruc/json/job.h"
#include "ruc/json/lexer.h"
#include "ruc/json/object.h"
#include "ruc/json/parser.h"
#include "ruc/json/value.h"
#include "ruc/meta/assert.h"
namespace Util::JSON {
namespace ruc::json {
Parser::Parser(Job* job)
: m_job(job)
@ -494,4 +494,4 @@ Value Parser::consumeObject()
return object;
}
} // namespace Util::JSON
} // namespace ruc::json

6
src/util/json/parser.h → src/ruc/json/parser.h

@ -9,9 +9,9 @@
#include <cstddef> // size_t
#include <vector>
#include "util/json/lexer.h"
#include "ruc/json/lexer.h"
namespace Util::JSON {
namespace ruc::json {
class Job;
class Value;
@ -42,4 +42,4 @@ private:
std::vector<Token>* m_tokens { nullptr };
};
} // namespace Util::JSON
} // namespace ruc::json

12
src/util/json/serializer.cpp → src/ruc/json/serializer.cpp

@ -9,12 +9,12 @@
#include <sstream> // ostringstream
#include <string>
#include "util/json/array.h"
#include "util/json/lexer.h"
#include "util/json/object.h"
#include "util/json/serializer.h"
#include "ruc/json/array.h"
#include "ruc/json/lexer.h"
#include "ruc/json/object.h"
#include "ruc/json/serializer.h"
namespace Util::JSON {
namespace ruc::json {
Serializer::Serializer(const uint32_t indent, const char indentCharacter)
: m_indent(indent)
@ -152,4 +152,4 @@ void Serializer::dumpObject(const Value& value, const uint32_t indentLevel)
m_output += '}';
}
} // namespace Util::JSON
} // namespace ruc::json

6
src/util/json/serializer.h → src/ruc/json/serializer.h

@ -9,9 +9,9 @@
#include <cstdint> // uint32_t
#include <string>
#include "util/json/value.h"
#include "ruc/json/value.h"
namespace Util::JSON {
namespace ruc::json {
class Serializer {
public:
@ -32,4 +32,4 @@ private:
bool m_compact { true };
};
} // namespace Util::JSON
} // namespace ruc::json

16
src/util/json/tojson.h → src/ruc/json/tojson.h

@ -13,13 +13,13 @@
#include <unordered_map>
#include <utility> // forward
#include "util/json/array.h"
#include "util/json/object.h"
#include "util/meta/odr.h"
#include "ruc/json/array.h"
#include "ruc/json/object.h"
#include "ruc/meta/odr.h"
namespace Util::JSON {
namespace ruc::json {
namespace Detail {
namespace detail {
struct jsonConstructor {
template<typename Json>
@ -127,15 +127,15 @@ struct toJsonFunction {
}
};
} // namespace Detail
} // namespace detail
// Anonymous namespace prevents multiple definition of the reference
namespace {
// Function object
constexpr const auto& toJson = Util::Detail::staticConst<Detail::toJsonFunction>; // NOLINT(misc-definitions-in-headers,clang-diagnostic-unused-variable)
constexpr const auto& toJson = ruc::detail::staticConst<detail::toJsonFunction>; // NOLINT(misc-definitions-in-headers,clang-diagnostic-unused-variable)
} // namespace
} // namespace Util::JSON
} // namespace ruc::json
// Customization Points
// https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/n4381.html

20
src/util/json/value.cpp → src/ruc/json/value.cpp

@ -11,15 +11,15 @@
#include <string>
#include <utility> // move, swap
#include "util/format/builder.h"
#include "util/json/array.h"
#include "util/json/job.h"
#include "util/json/object.h"
#include "util/json/serializer.h"
#include "util/json/value.h"
#include "util/meta/assert.h"
#include "ruc/format/builder.h"
#include "ruc/meta/assert.h"
#include "ruc/json/array.h"
#include "ruc/json/job.h"
#include "ruc/json/object.h"
#include "ruc/json/serializer.h"
#include "ruc/json/value.h"
namespace Util::JSON {
namespace ruc::json {
Value::Value(std::nullptr_t)
: Value(Type::Null)
@ -332,9 +332,9 @@ std::ostream& operator<<(std::ostream& output, const Value& value)
return output << value.dump(4);
}
void format(Util::Format::Builder& builder, const Value& value)
void format(ruc::format::Builder& builder, const Value& value)
{
builder.putString(value.dump(4));
}
} // namespace Util::JSON
} // namespace ruc::json

38
src/util/json/value.h → src/ruc/json/value.h

@ -13,18 +13,18 @@
#include <string>
#include <utility> // forward
#include "util/format/builder.h"
#include "util/json/fromjson.h"
#include "util/json/tojson.h"
#include "ruc/format/builder.h"
#include "ruc/json/fromjson.h"
#include "ruc/json/tojson.h"
namespace Util::JSON {
namespace ruc::json {
class Array;
class Object;
class Value {
private:
friend Detail::jsonConstructor;
friend detail::jsonConstructor;
friend class Parser;
friend class Serializer;
@ -134,32 +134,16 @@ private:
std::istream& operator>>(std::istream& input, Value& value);
std::ostream& operator<<(std::ostream& output, const Value& value);
void format(Util::Format::Builder& builder, const Value& value);
void format(ruc::format::Builder& builder, const Value& value);
} // namespace Util::JSON
} // namespace ruc::json
/**
* User-defined string literal
*
* Example usage: auto json = "[ 3.14, true, null ]"_json;
*/
// inline Util::JSON::Value operator"" _json(const char* input, size_t length)
// {
// return Util::JSON::Value::parse(std::string(input, length));
// }
// TODO:
// - find
// - custom iterator
// - begin
// - end
// v parse function that accepts ifstream > redirect to operator>>
// - dump(-1), 0 inserts only newlines, -1 is full compact(?)
// v add timer pause and unpause functions
// v std::prev -> std::next in serializer
// v serializer: output as member, does this speed it up?
// - add Badge pattern, ex: Serializer constructor isnt needed publically
// v Rename namespace Json -> Util::Json, create easy include json.h
// - look into this for correctness
// https://www.json.org/json-en.html
inline ruc::json::Value operator"" _json(const char* input, size_t length)
{
return ruc::json::Value::parse(std::string(input, length));
}

14
src/util/meta/assert.h → src/ruc/meta/assert.h

@ -13,13 +13,13 @@
#include <string>
#include <string_view>
#include "util/format/format.h"
#include "util/meta/compiler.h"
#include "ruc/format/format.h"
#include "ruc/meta/compiler.h"
#define CRASH() asm volatile("int $0x03");
#ifndef NDEBUG
#define VERIFY(expr, ...) (static_cast<bool>(expr) ? (void)0 : Util::__assertion_failed(#expr, __FILE__, __LINE__, FUNCTION_MACRO __VA_OPT__(, ) __VA_ARGS__))
#define VERIFY(expr, ...) (static_cast<bool>(expr) ? (void)0 : ruc::__assertion_failed(#expr, __FILE__, __LINE__, FUNCTION_MACRO __VA_OPT__(, ) __VA_ARGS__))
#define VERIFY_NOT_REACHED() VERIFY(false)
#else
#define VERIFY(expr, ...) (static_cast<bool>(expr) ? (void)0 : CRASH()
@ -27,7 +27,7 @@
#endif
#ifndef NDEBUG
namespace Util {
namespace ruc {
template<typename... Parameters>
inline void __assertion_failed(const char* assertion, const char* file, uint32_t line, const char* function, const Parameters&... parameters)
@ -66,8 +66,8 @@ inline void __assertion_failed(const char* assertion, const char* file, uint32_t
fprintf(stderr, ": ");
// Cant use the formatting library to print asserts caused by the formatting library
std::string_view functionString = function;
if (functionString.find("Util::Format::") != std::string_view::npos
&& functionString.find("Util::GenericLexer::") != std::string_view::npos) {
if (functionString.find("ruc::format::") != std::string_view::npos
&& functionString.find("ruc::GenericLexer::") != std::string_view::npos) {
std::string message;
formatTo(message, parameters...);
fprintf(stderr, "%s", message.c_str());
@ -92,5 +92,5 @@ inline void __assertion_failed(const char* assertion, const char* file, uint32_t
CRASH();
}
} // namespace Util
} // namespace ruc
#endif

0
src/util/meta/compiler.h → src/ruc/meta/compiler.h

8
src/util/meta/concepts.h → src/ruc/meta/concepts.h

@ -8,7 +8,7 @@
#include <type_traits> // is_integral_v, floating_point_v
namespace Util::Concepts {
namespace ruc::concepts {
template<class T>
concept Integral = std::is_integral_v<T>;
@ -16,7 +16,7 @@ concept Integral = std::is_integral_v<T>;
template<typename T>
concept FloatingPoint = std::is_floating_point_v<T>;
} // namespace Util::Concepts
} // namespace ruc::concepts
using Util::Concepts::FloatingPoint;
using Util::Concepts::Integral;
using ruc::concepts::FloatingPoint;
using ruc::concepts::Integral;

8
src/util/meta/odr.h → src/ruc/meta/odr.h

@ -6,15 +6,15 @@
#pragma once
namespace Util {
namespace ruc {
namespace Detail {
namespace detail {
// Avoid ODR (One Definition Rule) violations,
// variable templates are required to have external linkage
template<typename T>
constexpr T staticConst {};
} // namespace Detail
} // namespace detail
} // namespace Util
} // namespace ruc

6
src/util/shell.cpp → src/ruc/shell.cpp

@ -2,9 +2,9 @@
#include <string>
#include <string_view>
#include "util/shell.h"
#include "ruc/shell.h"
namespace Util {
namespace ruc {
Shell::Shell()
{
@ -50,4 +50,4 @@ Shell Shell::operator()(std::string_view command)
return operator()(command.data());
}
} // namespace Util
} // namespace ruc

4
src/util/shell.h → src/ruc/shell.h

@ -9,7 +9,7 @@
#include <string>
#include <string_view>
namespace Util {
namespace ruc {
class Shell {
public:
@ -30,4 +30,4 @@ private:
int m_status { 0 };
};
} // namespace Util
} // namespace ruc

4
src/util/singleton.h → src/ruc/singleton.h

@ -8,7 +8,7 @@
#include <cassert>
namespace Util {
namespace ruc {
template<typename T>
class Singleton {
@ -50,4 +50,4 @@ private:
template<typename T>
T* Singleton<T>::s_instance = nullptr;
} // namespace Util
} // namespace ruc

6
src/util/system.cpp → src/ruc/system.cpp

@ -11,9 +11,9 @@
#include <unistd.h> // close, dup2, execvp, fork, pipe, read
#include <vector>
#include "util/system.h"
#include "ruc/system.h"
namespace Util {
namespace ruc {
System::System()
{
@ -325,4 +325,4 @@ void System::readFromFileDescriptor(int fileDescriptor[2], std::string& output)
close(fileDescriptor[ReadFileDescriptor]);
}
} // namespace Util
} // namespace ruc

4
src/util/system.h → src/ruc/system.h

@ -12,7 +12,7 @@
#include <string_view>
#include <vector>
namespace Util {
namespace ruc {
using LineCallback = std::function<void(std::vector<std::string>&)>;
@ -65,4 +65,4 @@ private:
int m_status { 0 };
};
} // namespace Util
} // namespace ruc

6
src/util/timer.cpp → src/ruc/timer.cpp

@ -2,9 +2,9 @@
#include <cstdint> // uint64_t
#include <cstdio> // printf
#include "util/timer.h"
#include "ruc/timer.h"
namespace Util {
namespace ruc {
Timer::Timer()
: m_running(true)
@ -128,4 +128,4 @@ void Timer::fancyPrint(uint64_t nanoseconds)
}
}
} // namespace Util
} // namespace ruc

4
src/util/timer.h → src/ruc/timer.h

@ -9,7 +9,7 @@
#include <chrono> // high_resolution_clock
#include <cstdint> // uint64_t
namespace Util {
namespace ruc {
using TimePoint = std::chrono::high_resolution_clock::time_point;
@ -48,4 +48,4 @@ private:
TimePoint m_start;
};
} // namespace Util
} // namespace ruc

15
src/util/json/json.h

@ -1,15 +0,0 @@
/*
* Copyright (C) 2022 Riyyi
*
* SPDX-License-Identifier: MIT
*/
#pragma once
#include "util/json/value.h"
namespace Util {
using Json = Util::JSON::Value;
} // namespace Util

6
test/macro.h

@ -20,7 +20,7 @@
if (!(x)) { \
fprintf(stderr, " \033[31;1mFAIL:\033[0m %s:%d: EXPECT(%s) failed\n", \
__FILE__, __LINE__, #x); \
Test::TestSuite::the().currentTestCaseFailed(); \
test::TestSuite::the().currentTestCaseFailed(); \
result; \
}
@ -41,7 +41,7 @@
std::cerr << " \033[31;1mFAIL:\033[0m " << __FILE__ << ":" << __LINE__ \
<< ": EXPECT_EQ(" << #a << ", " << #b ") failed with" \
<< " lhs='" << a << "' and rhs='" << b << "'" << std::endl; \
Test::TestSuite::the().currentTestCaseFailed(); \
test::TestSuite::the().currentTestCaseFailed(); \
result; \
}
@ -62,7 +62,7 @@
std::cerr << " \033[31;1mFAIL:\033[0m " << __FILE__ << ":" << __LINE__ \
<< ": EXPECT_NE(" << #a << ", " << #b ") failed with" \
<< " lhs='" << a << "' and rhs='" << b << "'" << std::endl; \
Test::TestSuite::the().currentTestCaseFailed(); \
test::TestSuite::the().currentTestCaseFailed(); \
result; \
}

2
test/main.cpp

@ -2,7 +2,7 @@
int main(int, const char*[])
{
Test::TestSuite::the().run();
test::TestSuite::the().run();
return 0;
}

6
test/testcase.h

@ -13,14 +13,14 @@
__TEST_CASE_STRUCT(x) \
() \
{ \
Test::TestSuite::the().addCase( \
test::TestSuite::the().addCase( \
{ #x, __TEST_CASE_FUNCTION(x) }); \
} \
}; \
static struct __TEST_CASE_STRUCT(x) __TEST_CASE_STRUCT(x); \
static void __TEST_CASE_FUNCTION(x)()
namespace Test {
namespace test {
using TestFunction = std::function<void()>;
@ -40,6 +40,6 @@ private:
TestFunction m_function;
};
} // namespace Test
} // namespace test
#endif // TEST_CASE_H

14
test/testsuite.cpp

@ -3,10 +3,10 @@
#include <string>
#include <vector>
#include "ruc/timer.h"
#include "testsuite.h"
#include "util/timer.h"
namespace Test {
namespace test {
TestSuite::TestSuite(s)
{
@ -32,7 +32,7 @@ void TestSuite::run()
printf("\n");
printf("---- Running %zu Test Cases ----\n", m_cases.size());
Util::Timer totalTimer;
ruc::Timer totalTimer;
size_t caseFailedCount = 0;
for (size_t i = 0; i < m_cases.size(); ++i) {
@ -40,7 +40,7 @@ void TestSuite::run()
printf(" START %s (%zu/%zu)\n", m_cases.at(i).name(), i + 1, m_cases.size());
m_currentTestCasePassed = true;
Util::Timer caseTimer;
ruc::Timer caseTimer;
m_cases.at(i).function()();
double elapsed = caseTimer.elapsedNanoseconds();
@ -58,7 +58,7 @@ void TestSuite::run()
}
printf("%s %s %s(", state.c_str(), m_cases.at(i).name(), escapeGrey);
Util::Timer::fancyPrint(elapsed);
ruc::Timer::fancyPrint(elapsed);
printf(")%s\n", escapeReset);
}
@ -69,8 +69,8 @@ void TestSuite::run()
m_cases.size());
printf("Time: ");
Util::Timer::fancyPrint(totalTimer.elapsedNanoseconds());
ruc::Timer::fancyPrint(totalTimer.elapsedNanoseconds());
printf("\n");
}
} // namespace Test
} // namespace test

8
test/testsuite.h

@ -4,12 +4,12 @@
#include <cstdio> // FILE
#include <vector>
#include "ruc/singleton.h"
#include "testcase.h"
#include "util/singleton.h"
namespace Test {
namespace test {
class TestSuite final : public Util::Singleton<TestSuite> {
class TestSuite final : public ruc::Singleton<TestSuite> {
public:
TestSuite(s);
virtual ~TestSuite();
@ -31,6 +31,6 @@ private:
std::vector<TestCase> m_cases;
};
} // namespace Test
} // namespace test
#endif // TEST_SUITE_H

180
test/unit/testutilargparser.cpp

@ -3,15 +3,15 @@
#include <vector>
#include "macro.h"
#include "ruc/argparser.h"
#include "testcase.h"
#include "testsuite.h"
#include "util/argparser.h"
bool runParser(std::vector<const char*> arguments, std::function<void(Util::ArgParser&)> initializer = {})
bool runParser(std::vector<const char*> arguments, std::function<void(ruc::ArgParser&)> initializer = {})
{
stdout = Test::TestSuite::the().outputNull();
stdout = test::TestSuite::the().outputNull();
Util::ArgParser parser;
ruc::ArgParser parser;
if (initializer) {
initializer(parser);
}
@ -19,7 +19,7 @@ bool runParser(std::vector<const char*> arguments, std::function<void(Util::ArgP
arguments.insert(arguments.begin(), "app");
auto result = parser.parse(arguments.size(), arguments.data());
stdout = Test::TestSuite::the().outputStd();
stdout = test::TestSuite::the().outputStd();
return result;
}
@ -55,7 +55,7 @@ TEST_CASE(RequiredStringArguments)
// Single required string argument
std::string stringArg1 = "";
auto result = runParser({ "my-required-argument" }, [&](auto& parser) {
parser.addArgument(stringArg1, nullptr, nullptr, nullptr, Util::ArgParser::Required::Yes);
parser.addArgument(stringArg1, nullptr, nullptr, nullptr, ruc::ArgParser::Required::Yes);
});
EXPECT_EQ(result, true);
EXPECT_EQ(stringArg1, "my-required-argument");
@ -63,7 +63,7 @@ TEST_CASE(RequiredStringArguments)
// Single required string argument, not given
stringArg1 = "";
result = runParser({}, [&](auto& parser) {
parser.addArgument(stringArg1, nullptr, nullptr, nullptr, Util::ArgParser::Required::Yes);
parser.addArgument(stringArg1, nullptr, nullptr, nullptr, ruc::ArgParser::Required::Yes);
});
EXPECT_EQ(result, false);
EXPECT_EQ(stringArg1, "");
@ -73,9 +73,9 @@ TEST_CASE(RequiredStringArguments)
std::string stringArg2 = "";
std::string stringArg3 = "";
result = runParser({ "my", "required", "argument" }, [&](auto& parser) {
parser.addArgument(stringArg1, nullptr, nullptr, nullptr, Util::ArgParser::Required::Yes);
parser.addArgument(stringArg2, nullptr, nullptr, nullptr, Util::ArgParser::Required::Yes);
parser.addArgument(stringArg3, nullptr, nullptr, nullptr, Util::ArgParser::Required::Yes);
parser.addArgument(stringArg1, nullptr, nullptr, nullptr, ruc::ArgParser::Required::Yes);
parser.addArgument(stringArg2, nullptr, nullptr, nullptr, ruc::ArgParser::Required::Yes);
parser.addArgument(stringArg3, nullptr, nullptr, nullptr, ruc::ArgParser::Required::Yes);
});
EXPECT_EQ(result, true);
EXPECT_EQ(stringArg1, "my");
@ -87,9 +87,9 @@ TEST_CASE(RequiredStringArguments)
stringArg2 = "";
stringArg3 = "";
result = runParser({}, [&](auto& parser) {
parser.addArgument(stringArg1, nullptr, nullptr, nullptr, Util::ArgParser::Required::Yes);
parser.addArgument(stringArg2, nullptr, nullptr, nullptr, Util::ArgParser::Required::Yes);
parser.addArgument(stringArg3, nullptr, nullptr, nullptr, Util::ArgParser::Required::Yes);
parser.addArgument(stringArg1, nullptr, nullptr, nullptr, ruc::ArgParser::Required::Yes);
parser.addArgument(stringArg2, nullptr, nullptr, nullptr, ruc::ArgParser::Required::Yes);
parser.addArgument(stringArg3, nullptr, nullptr, nullptr, ruc::ArgParser::Required::Yes);
});
EXPECT_EQ(result, false);
EXPECT_EQ(stringArg1, "");
@ -104,7 +104,7 @@ TEST_CASE(OptionalStringArguments)
// Single optional string argument
std::string stringArg1 = "";
auto result = runParser({ "my-optional-argument" }, [&](auto& parser) {
parser.addArgument(stringArg1, nullptr, nullptr, nullptr, Util::ArgParser::Required::Optional);
parser.addArgument(stringArg1, nullptr, nullptr, nullptr, ruc::ArgParser::Required::Optional);
});
EXPECT_EQ(result, true);
EXPECT_EQ(stringArg1, "my-optional-argument");
@ -112,7 +112,7 @@ TEST_CASE(OptionalStringArguments)
// Single optional string argument, not given
stringArg1 = "";
result = runParser({}, [&](auto& parser) {
parser.addArgument(stringArg1, nullptr, nullptr, nullptr, Util::ArgParser::Required::Optional);
parser.addArgument(stringArg1, nullptr, nullptr, nullptr, ruc::ArgParser::Required::Optional);
});
EXPECT_EQ(result, true);
EXPECT_EQ(stringArg1, "");
@ -122,9 +122,9 @@ TEST_CASE(OptionalStringArguments)
std::string stringArg2 = "";
std::string stringArg3 = "";
result = runParser({ "my", "optional", "argument" }, [&](auto& parser) {
parser.addArgument(stringArg1, nullptr, nullptr, nullptr, Util::ArgParser::Required::Optional);
parser.addArgument(stringArg2, nullptr, nullptr, nullptr, Util::ArgParser::Required::Optional);
parser.addArgument(stringArg3, nullptr, nullptr, nullptr, Util::ArgParser::Required::Optional);
parser.addArgument(stringArg1, nullptr, nullptr, nullptr, ruc::ArgParser::Required::Optional);
parser.addArgument(stringArg2, nullptr, nullptr, nullptr, ruc::ArgParser::Required::Optional);
parser.addArgument(stringArg3, nullptr, nullptr, nullptr, ruc::ArgParser::Required::Optional);
});
EXPECT_EQ(result, true);
EXPECT_EQ(stringArg1, "my");
@ -136,9 +136,9 @@ TEST_CASE(OptionalStringArguments)
stringArg2 = "";
stringArg3 = "";
result = runParser({}, [&](auto& parser) {
parser.addArgument(stringArg1, nullptr, nullptr, nullptr, Util::ArgParser::Required::Optional);
parser.addArgument(stringArg2, nullptr, nullptr, nullptr, Util::ArgParser::Required::Optional);
parser.addArgument(stringArg3, nullptr, nullptr, nullptr, Util::ArgParser::Required::Optional);
parser.addArgument(stringArg1, nullptr, nullptr, nullptr, ruc::ArgParser::Required::Optional);
parser.addArgument(stringArg2, nullptr, nullptr, nullptr, ruc::ArgParser::Required::Optional);
parser.addArgument(stringArg3, nullptr, nullptr, nullptr, ruc::ArgParser::Required::Optional);
});
EXPECT_EQ(result, true);
EXPECT_EQ(stringArg1, "");
@ -153,7 +153,7 @@ TEST_CASE(NonRequiredStringArguments)
// Single non-required string argument
std::string stringArg1 = "";
auto result = runParser({ "my-non-required-argument" }, [&](auto& parser) {
parser.addArgument(stringArg1, nullptr, nullptr, nullptr, Util::ArgParser::Required::No);
parser.addArgument(stringArg1, nullptr, nullptr, nullptr, ruc::ArgParser::Required::No);
});
EXPECT_EQ(result, true);
EXPECT_EQ(stringArg1, "my-non-required-argument");
@ -161,7 +161,7 @@ TEST_CASE(NonRequiredStringArguments)
// Single non-required string argument, not given
stringArg1 = "";
result = runParser({}, [&](auto& parser) {
parser.addArgument(stringArg1, nullptr, nullptr, nullptr, Util::ArgParser::Required::No);
parser.addArgument(stringArg1, nullptr, nullptr, nullptr, ruc::ArgParser::Required::No);
});
EXPECT_EQ(result, true);
EXPECT_EQ(stringArg1, "");
@ -171,9 +171,9 @@ TEST_CASE(NonRequiredStringArguments)
std::string stringArg2 = "";
std::string stringArg3 = "";
result = runParser({ "my", "non-required", "argument" }, [&](auto& parser) {
parser.addArgument(stringArg1, nullptr, nullptr, nullptr, Util::ArgParser::Required::No);
parser.addArgument(stringArg2, nullptr, nullptr, nullptr, Util::ArgParser::Required::No);
parser.addArgument(stringArg3, nullptr, nullptr, nullptr, Util::ArgParser::Required::No);
parser.addArgument(stringArg1, nullptr, nullptr, nullptr, ruc::ArgParser::Required::No);
parser.addArgument(stringArg2, nullptr, nullptr, nullptr, ruc::ArgParser::Required::No);
parser.addArgument(stringArg3, nullptr, nullptr, nullptr, ruc::ArgParser::Required::No);
});
EXPECT_EQ(result, true);
EXPECT_EQ(stringArg1, "my");
@ -185,9 +185,9 @@ TEST_CASE(NonRequiredStringArguments)
stringArg2 = "";
stringArg3 = "";
result = runParser({}, [&](auto& parser) {
parser.addArgument(stringArg1, nullptr, nullptr, nullptr, Util::ArgParser::Required::No);
parser.addArgument(stringArg2, nullptr, nullptr, nullptr, Util::ArgParser::Required::No);
parser.addArgument(stringArg3, nullptr, nullptr, nullptr, Util::ArgParser::Required::No);
parser.addArgument(stringArg1, nullptr, nullptr, nullptr, ruc::ArgParser::Required::No);
parser.addArgument(stringArg2, nullptr, nullptr, nullptr, ruc::ArgParser::Required::No);
parser.addArgument(stringArg3, nullptr, nullptr, nullptr, ruc::ArgParser::Required::No);
});
EXPECT_EQ(result, true);
EXPECT_EQ(stringArg1, "");
@ -202,7 +202,7 @@ TEST_CASE(VectorStringArguments)
// Required vector string argument, not given
std::vector<std::string> vectorArg1 = {};
auto result = runParser({}, [&](auto& parser) {
parser.addArgument(vectorArg1, nullptr, nullptr, nullptr, Util::ArgParser::Required::Yes);
parser.addArgument(vectorArg1, nullptr, nullptr, nullptr, ruc::ArgParser::Required::Yes);
});
EXPECT_EQ(result, false);
EXPECT_EQ(vectorArg1.size(), 0);
@ -210,7 +210,7 @@ TEST_CASE(VectorStringArguments)
// Required vector string argument, one given
vectorArg1 = {};
result = runParser({ "foo" }, [&](auto& parser) {
parser.addArgument(vectorArg1, nullptr, nullptr, nullptr, Util::ArgParser::Required::Yes);
parser.addArgument(vectorArg1, nullptr, nullptr, nullptr, ruc::ArgParser::Required::Yes);
});
EXPECT_EQ(result, true);
EXPECT_EQ(vectorArg1.size(), 1);
@ -221,7 +221,7 @@ TEST_CASE(VectorStringArguments)
// Required vector string argument, two given
vectorArg1 = {};
result = runParser({ "hello", "world" }, [&](auto& parser) {
parser.addArgument(vectorArg1, nullptr, nullptr, nullptr, Util::ArgParser::Required::Yes);
parser.addArgument(vectorArg1, nullptr, nullptr, nullptr, ruc::ArgParser::Required::Yes);
});
EXPECT_EQ(result, true);
EXPECT_EQ(vectorArg1.size(), 2);
@ -240,9 +240,9 @@ TEST_CASE(CombinationOfNonRequiredArguments)
double doubleArg1 = 0;
std::string stringArg1 = "";
auto result = runParser({ "optional argument" }, [&](auto& parser) {
parser.addArgument(intArg1, nullptr, nullptr, nullptr, Util::ArgParser::Required::Optional);
parser.addArgument(doubleArg1, nullptr, nullptr, nullptr, Util::ArgParser::Required::Optional);
parser.addArgument(stringArg1, nullptr, nullptr, nullptr, Util::ArgParser::Required::Optional);
parser.addArgument(intArg1, nullptr, nullptr, nullptr, ruc::ArgParser::Required::Optional);
parser.addArgument(doubleArg1, nullptr, nullptr, nullptr, ruc::ArgParser::Required::Optional);
parser.addArgument(stringArg1, nullptr, nullptr, nullptr, ruc::ArgParser::Required::Optional);
});
EXPECT_EQ(result, true);
EXPECT_EQ(intArg1, 0);
@ -254,9 +254,9 @@ TEST_CASE(CombinationOfNonRequiredArguments)
doubleArg1 = 0;
stringArg1 = "";
result = runParser({ "999.999", "optional argument" }, [&](auto& parser) {
parser.addArgument(intArg1, nullptr, nullptr, nullptr, Util::ArgParser::Required::Optional);
parser.addArgument(doubleArg1, nullptr, nullptr, nullptr, Util::ArgParser::Required::Optional);
parser.addArgument(stringArg1, nullptr, nullptr, nullptr, Util::ArgParser::Required::Optional);
parser.addArgument(intArg1, nullptr, nullptr, nullptr, ruc::ArgParser::Required::Optional);
parser.addArgument(doubleArg1, nullptr, nullptr, nullptr, ruc::ArgParser::Required::Optional);
parser.addArgument(stringArg1, nullptr, nullptr, nullptr, ruc::ArgParser::Required::Optional);
});
EXPECT_EQ(result, true);
EXPECT_EQ(intArg1, 0);
@ -268,9 +268,9 @@ TEST_CASE(CombinationOfNonRequiredArguments)
doubleArg1 = 0;
stringArg1 = "";
result = runParser({ "999,999", "optional argument" }, [&](auto& parser) {
parser.addArgument(intArg1, nullptr, nullptr, nullptr, Util::ArgParser::Required::Optional);
parser.addArgument(doubleArg1, nullptr, nullptr, nullptr, Util::ArgParser::Required::Optional);
parser.addArgument(stringArg1, nullptr, nullptr, nullptr, Util::ArgParser::Required::Optional);
parser.addArgument(intArg1, nullptr, nullptr, nullptr, ruc::ArgParser::Required::Optional);
parser.addArgument(doubleArg1, nullptr, nullptr, nullptr, ruc::ArgParser::Required::Optional);
parser.addArgument(stringArg1, nullptr, nullptr, nullptr, ruc::ArgParser::Required::Optional);
});
EXPECT_EQ(result, false);
EXPECT_EQ(intArg1, 0);
@ -282,9 +282,9 @@ TEST_CASE(CombinationOfNonRequiredArguments)
intArg1 = 0;
doubleArg1 = 0;
result = runParser({ "999.999", "optional argument" }, [&](auto& parser) {
parser.addArgument(stringArg1, nullptr, nullptr, nullptr, Util::ArgParser::Required::Optional);
parser.addArgument(intArg1, nullptr, nullptr, nullptr, Util::ArgParser::Required::Optional);
parser.addArgument(doubleArg1, nullptr, nullptr, nullptr, Util::ArgParser::Required::Optional);
parser.addArgument(stringArg1, nullptr, nullptr, nullptr, ruc::ArgParser::Required::Optional);
parser.addArgument(intArg1, nullptr, nullptr, nullptr, ruc::ArgParser::Required::Optional);
parser.addArgument(doubleArg1, nullptr, nullptr, nullptr, ruc::ArgParser::Required::Optional);
});
EXPECT_EQ(result, false);
EXPECT_EQ(stringArg1, "999.999");
@ -360,7 +360,7 @@ TEST_CASE(SingleRequiredStringOptions)
// Single required string short option
std::string stringOpt1 = "";
auto result = runParser({ "-s", "my-required-argument" }, [&](auto& parser) {
parser.addOption(stringOpt1, 's', nullptr, nullptr, nullptr, nullptr, Util::ArgParser::Required::Yes);
parser.addOption(stringOpt1, 's', nullptr, nullptr, nullptr, nullptr, ruc::ArgParser::Required::Yes);
});
EXPECT_EQ(result, true);
EXPECT_EQ(stringOpt1, "my-required-argument");
@ -368,7 +368,7 @@ TEST_CASE(SingleRequiredStringOptions)
// Single required string short option, given directly after
stringOpt1 = "";
result = runParser({ "-smy-required-argument" }, [&](auto& parser) {
parser.addOption(stringOpt1, 's', nullptr, nullptr, nullptr, nullptr, Util::ArgParser::Required::Yes);
parser.addOption(stringOpt1, 's', nullptr, nullptr, nullptr, nullptr, ruc::ArgParser::Required::Yes);
});
EXPECT_EQ(result, true);
EXPECT_EQ(stringOpt1, "my-required-argument");
@ -376,7 +376,7 @@ TEST_CASE(SingleRequiredStringOptions)
// Single required string short option, empty given
stringOpt1 = "";
result = runParser({ "-s" }, [&](auto& parser) {
parser.addOption(stringOpt1, 's', nullptr, nullptr, nullptr, nullptr, Util::ArgParser::Required::Yes);
parser.addOption(stringOpt1, 's', nullptr, nullptr, nullptr, nullptr, ruc::ArgParser::Required::Yes);
});
EXPECT_EQ(result, false);
EXPECT_EQ(stringOpt1, "");
@ -384,7 +384,7 @@ TEST_CASE(SingleRequiredStringOptions)
// Single required string short option, not given
stringOpt1 = "";
result = runParser({}, [&](auto& parser) {
parser.addOption(stringOpt1, 's', nullptr, nullptr, nullptr, nullptr, Util::ArgParser::Required::Yes);
parser.addOption(stringOpt1, 's', nullptr, nullptr, nullptr, nullptr, ruc::ArgParser::Required::Yes);
});
EXPECT_EQ(result, true);
EXPECT_EQ(stringOpt1, "");
@ -392,7 +392,7 @@ TEST_CASE(SingleRequiredStringOptions)
// Single required string long option
stringOpt1 = "";
result = runParser({ "--string", "my-required-argument" }, [&](auto& parser) {
parser.addOption(stringOpt1, '\0', "string", nullptr, nullptr, nullptr, Util::ArgParser::Required::Yes);
parser.addOption(stringOpt1, '\0', "string", nullptr, nullptr, nullptr, ruc::ArgParser::Required::Yes);
});
EXPECT_EQ(result, true);
EXPECT_EQ(stringOpt1, "my-required-argument");
@ -400,7 +400,7 @@ TEST_CASE(SingleRequiredStringOptions)
// Single required string long option, given directly after
stringOpt1 = "";
result = runParser({ "--string=my-required-argument" }, [&](auto& parser) {
parser.addOption(stringOpt1, '\0', "string", nullptr, nullptr, nullptr, Util::ArgParser::Required::Yes);
parser.addOption(stringOpt1, '\0', "string", nullptr, nullptr, nullptr, ruc::ArgParser::Required::Yes);
});
EXPECT_EQ(result, true);
EXPECT_EQ(stringOpt1, "my-required-argument");
@ -408,7 +408,7 @@ TEST_CASE(SingleRequiredStringOptions)
// Single required string long option, empty given
stringOpt1 = "";
result = runParser({ "--string" }, [&](auto& parser) {
parser.addOption(stringOpt1, '\0', "string", nullptr, nullptr, nullptr, Util::ArgParser::Required::Yes);
parser.addOption(stringOpt1, '\0', "string", nullptr, nullptr, nullptr, ruc::ArgParser::Required::Yes);
});
EXPECT_EQ(result, false);
EXPECT_EQ(stringOpt1, "");
@ -416,7 +416,7 @@ TEST_CASE(SingleRequiredStringOptions)
// Single required string long option, not given
stringOpt1 = "";
result = runParser({}, [&](auto& parser) {
parser.addOption(stringOpt1, '\0', "string", nullptr, nullptr, nullptr, Util::ArgParser::Required::Yes);
parser.addOption(stringOpt1, '\0', "string", nullptr, nullptr, nullptr, ruc::ArgParser::Required::Yes);
});
EXPECT_EQ(result, true);
EXPECT_EQ(stringOpt1, "");
@ -430,8 +430,8 @@ TEST_CASE(SingleOptionalStringOptions)
std::string stringOpt1 = "";
std::string stringArg1 = "";
auto result = runParser({ "-s", "my-optional-argument" }, [&](auto& parser) {
parser.addOption(stringOpt1, 's', nullptr, nullptr, nullptr, nullptr, Util::ArgParser::Required::Optional);
parser.addArgument(stringArg1, nullptr, nullptr, nullptr, Util::ArgParser::Required::No);
parser.addOption(stringOpt1, 's', nullptr, nullptr, nullptr, nullptr, ruc::ArgParser::Required::Optional);
parser.addArgument(stringArg1, nullptr, nullptr, nullptr, ruc::ArgParser::Required::No);
});
EXPECT_EQ(result, true);
EXPECT_EQ(stringOpt1, "");
@ -440,7 +440,7 @@ TEST_CASE(SingleOptionalStringOptions)
// Single optional string short option, given directly after
stringOpt1 = "";
result = runParser({ "-smy-optional-argument" }, [&](auto& parser) {
parser.addOption(stringOpt1, 's', nullptr, nullptr, nullptr, nullptr, Util::ArgParser::Required::Optional);
parser.addOption(stringOpt1, 's', nullptr, nullptr, nullptr, nullptr, ruc::ArgParser::Required::Optional);
});
EXPECT_EQ(result, true);
EXPECT_EQ(stringOpt1, "my-optional-argument");
@ -448,7 +448,7 @@ TEST_CASE(SingleOptionalStringOptions)
// Single optional string short option, empty given
stringOpt1 = "";
result = runParser({ "-s" }, [&](auto& parser) {
parser.addOption(stringOpt1, 's', nullptr, nullptr, nullptr, nullptr, Util::ArgParser::Required::Optional);
parser.addOption(stringOpt1, 's', nullptr, nullptr, nullptr, nullptr, ruc::ArgParser::Required::Optional);
});
EXPECT_EQ(result, true);
EXPECT_EQ(stringOpt1, "");
@ -456,7 +456,7 @@ TEST_CASE(SingleOptionalStringOptions)
// Single optional string short option, not given
stringOpt1 = "";
result = runParser({}, [&](auto& parser) {
parser.addOption(stringOpt1, 's', nullptr, nullptr, nullptr, nullptr, Util::ArgParser::Required::Optional);
parser.addOption(stringOpt1, 's', nullptr, nullptr, nullptr, nullptr, ruc::ArgParser::Required::Optional);
});
EXPECT_EQ(result, true);
EXPECT_EQ(stringOpt1, "");
@ -465,8 +465,8 @@ TEST_CASE(SingleOptionalStringOptions)
stringOpt1 = "";
stringArg1 = "";
result = runParser({ "--string", "my-optional-argument" }, [&](auto& parser) {
parser.addOption(stringOpt1, '\0', "string", nullptr, nullptr, nullptr, Util::ArgParser::Required::Optional);
parser.addArgument(stringArg1, nullptr, nullptr, nullptr, Util::ArgParser::Required::No);
parser.addOption(stringOpt1, '\0', "string", nullptr, nullptr, nullptr, ruc::ArgParser::Required::Optional);
parser.addArgument(stringArg1, nullptr, nullptr, nullptr, ruc::ArgParser::Required::No);
});
EXPECT_EQ(result, true);
EXPECT_EQ(stringOpt1, "");
@ -475,7 +475,7 @@ TEST_CASE(SingleOptionalStringOptions)
// Single optional string long option, given directly after
stringOpt1 = "";
result = runParser({ "--string=my-optional-argument" }, [&](auto& parser) {
parser.addOption(stringOpt1, '\0', "string", nullptr, nullptr, nullptr, Util::ArgParser::Required::Optional);
parser.addOption(stringOpt1, '\0', "string", nullptr, nullptr, nullptr, ruc::ArgParser::Required::Optional);
});
EXPECT_EQ(result, true);
EXPECT_EQ(stringOpt1, "my-optional-argument");
@ -483,7 +483,7 @@ TEST_CASE(SingleOptionalStringOptions)
// Single optional string long option, empty given
stringOpt1 = "";
result = runParser({ "--string" }, [&](auto& parser) {
parser.addOption(stringOpt1, '\0', "string", nullptr, nullptr, nullptr, Util::ArgParser::Required::Optional);
parser.addOption(stringOpt1, '\0', "string", nullptr, nullptr, nullptr, ruc::ArgParser::Required::Optional);
});
EXPECT_EQ(result, true);
EXPECT_EQ(stringOpt1, "");
@ -491,7 +491,7 @@ TEST_CASE(SingleOptionalStringOptions)
// Single optional string long option, not given
stringOpt1 = "";
result = runParser({}, [&](auto& parser) {
parser.addOption(stringOpt1, '\0', "string", nullptr, nullptr, nullptr, Util::ArgParser::Required::Optional);
parser.addOption(stringOpt1, '\0', "string", nullptr, nullptr, nullptr, ruc::ArgParser::Required::Optional);
});
EXPECT_EQ(result, true);
EXPECT_EQ(stringOpt1, "");
@ -505,8 +505,8 @@ TEST_CASE(SingleNonRequiredStringOptions)
std::string stringOpt1 = "";
std::string stringArg1 = "";
auto result = runParser({ "-s", "my-non-required-argument" }, [&](auto& parser) {
parser.addOption(stringOpt1, 's', nullptr, nullptr, nullptr, nullptr, Util::ArgParser::Required::No);
parser.addArgument(stringArg1, nullptr, nullptr, nullptr, Util::ArgParser::Required::No);
parser.addOption(stringOpt1, 's', nullptr, nullptr, nullptr, nullptr, ruc::ArgParser::Required::No);
parser.addArgument(stringArg1, nullptr, nullptr, nullptr, ruc::ArgParser::Required::No);
});
EXPECT_EQ(result, true);
EXPECT_EQ(stringOpt1, "");
@ -515,7 +515,7 @@ TEST_CASE(SingleNonRequiredStringOptions)
// Single non-required string short option, given directly after
stringOpt1 = "";
result = runParser({ "-smy-non-required-argument" }, [&](auto& parser) {
parser.addOption(stringOpt1, 's', nullptr, nullptr, nullptr, nullptr, Util::ArgParser::Required::No);
parser.addOption(stringOpt1, 's', nullptr, nullptr, nullptr, nullptr, ruc::ArgParser::Required::No);
});
EXPECT_EQ(result, false);
EXPECT_EQ(stringOpt1, "");
@ -523,7 +523,7 @@ TEST_CASE(SingleNonRequiredStringOptions)
// Single non-required string short option, empty given
stringOpt1 = "";
result = runParser({ "-s" }, [&](auto& parser) {
parser.addOption(stringOpt1, 's', nullptr, nullptr, nullptr, nullptr, Util::ArgParser::Required::No);
parser.addOption(stringOpt1, 's', nullptr, nullptr, nullptr, nullptr, ruc::ArgParser::Required::No);
});
EXPECT_EQ(result, true);
EXPECT_EQ(stringOpt1, "");
@ -531,7 +531,7 @@ TEST_CASE(SingleNonRequiredStringOptions)
// Single non-required string short option, not given
stringOpt1 = "";
result = runParser({}, [&](auto& parser) {
parser.addOption(stringOpt1, 's', nullptr, nullptr, nullptr, nullptr, Util::ArgParser::Required::No);
parser.addOption(stringOpt1, 's', nullptr, nullptr, nullptr, nullptr, ruc::ArgParser::Required::No);
});
EXPECT_EQ(result, true);
EXPECT_EQ(stringOpt1, "");
@ -540,8 +540,8 @@ TEST_CASE(SingleNonRequiredStringOptions)
stringOpt1 = "";
stringArg1 = "";
result = runParser({ "--string", "my-non-required-argument" }, [&](auto& parser) {
parser.addOption(stringOpt1, '\0', "string", nullptr, nullptr, nullptr, Util::ArgParser::Required::No);
parser.addArgument(stringArg1, nullptr, nullptr, nullptr, Util::ArgParser::Required::No);
parser.addOption(stringOpt1, '\0', "string", nullptr, nullptr, nullptr, ruc::ArgParser::Required::No);
parser.addArgument(stringArg1, nullptr, nullptr, nullptr, ruc::ArgParser::Required::No);
});
EXPECT_EQ(result, true);
EXPECT_EQ(stringOpt1, "");
@ -550,7 +550,7 @@ TEST_CASE(SingleNonRequiredStringOptions)
// Single non-required string long option, given directly after
stringOpt1 = "";
result = runParser({ "--string=my-non-required-argument" }, [&](auto& parser) {
parser.addOption(stringOpt1, '\0', "string", nullptr, nullptr, nullptr, Util::ArgParser::Required::No);
parser.addOption(stringOpt1, '\0', "string", nullptr, nullptr, nullptr, ruc::ArgParser::Required::No);
});
EXPECT_EQ(result, false);
EXPECT_EQ(stringOpt1, "");
@ -558,7 +558,7 @@ TEST_CASE(SingleNonRequiredStringOptions)
// Single non-required string long option, empty given
stringOpt1 = "";
result = runParser({ "--string" }, [&](auto& parser) {
parser.addOption(stringOpt1, '\0', "string", nullptr, nullptr, nullptr, Util::ArgParser::Required::No);
parser.addOption(stringOpt1, '\0', "string", nullptr, nullptr, nullptr, ruc::ArgParser::Required::No);
});
EXPECT_EQ(result, true);
EXPECT_EQ(stringOpt1, "");
@ -566,7 +566,7 @@ TEST_CASE(SingleNonRequiredStringOptions)
// Single non-required string long option, not given
stringOpt1 = "";
result = runParser({}, [&](auto& parser) {
parser.addOption(stringOpt1, '\0', "string", nullptr, nullptr, nullptr, Util::ArgParser::Required::No);
parser.addOption(stringOpt1, '\0', "string", nullptr, nullptr, nullptr, ruc::ArgParser::Required::No);
});
EXPECT_EQ(result, true);
EXPECT_EQ(stringOpt1, "");
@ -579,7 +579,7 @@ TEST_CASE(NumberOptions)
// Required int short option
int intOpt1 = 0;
auto result = runParser({ "-i", "2147483647" }, [&](auto& parser) {
parser.addOption(intOpt1, 'i', nullptr, nullptr, nullptr, nullptr, Util::ArgParser::Required::Yes);
parser.addOption(intOpt1, 'i', nullptr, nullptr, nullptr, nullptr, ruc::ArgParser::Required::Yes);
});
EXPECT_EQ(result, true);
EXPECT_EQ(intOpt1, 2147483647);
@ -587,7 +587,7 @@ TEST_CASE(NumberOptions)
// Required int short option, overflown value given
intOpt1 = 0;
result = runParser({ "-i", "2147483648" }, [&](auto& parser) {
parser.addOption(intOpt1, 'i', nullptr, nullptr, nullptr, nullptr, Util::ArgParser::Required::Yes);
parser.addOption(intOpt1, 'i', nullptr, nullptr, nullptr, nullptr, ruc::ArgParser::Required::Yes);
});
EXPECT_EQ(result, false);
EXPECT_EQ(intOpt1, 0);
@ -595,7 +595,7 @@ TEST_CASE(NumberOptions)
// Required int short option, empty given
intOpt1 = 0;
result = runParser({ "-i" }, [&](auto& parser) {
parser.addOption(intOpt1, 'i', nullptr, nullptr, nullptr, nullptr, Util::ArgParser::Required::Yes);
parser.addOption(intOpt1, 'i', nullptr, nullptr, nullptr, nullptr, ruc::ArgParser::Required::Yes);
});
EXPECT_EQ(result, false);
EXPECT_EQ(intOpt1, 0);
@ -603,7 +603,7 @@ TEST_CASE(NumberOptions)
// Required unsigned int short option
unsigned int unsignedIntOpt1 = 0;
result = runParser({ "-u", "4294967295" }, [&](auto& parser) {
parser.addOption(unsignedIntOpt1, 'u', nullptr, nullptr, nullptr, nullptr, Util::ArgParser::Required::Yes);
parser.addOption(unsignedIntOpt1, 'u', nullptr, nullptr, nullptr, nullptr, ruc::ArgParser::Required::Yes);
});
EXPECT_EQ(result, true);
EXPECT_EQ(unsignedIntOpt1, 4294967295);
@ -611,7 +611,7 @@ TEST_CASE(NumberOptions)
// Required unsigned int short option, overflown value given
unsignedIntOpt1 = 0;
result = runParser({ "-u", "4294967296" }, [&](auto& parser) {
parser.addOption(unsignedIntOpt1, 'u', nullptr, nullptr, nullptr, nullptr, Util::ArgParser::Required::Yes);
parser.addOption(unsignedIntOpt1, 'u', nullptr, nullptr, nullptr, nullptr, ruc::ArgParser::Required::Yes);
});
EXPECT_EQ(result, false);
EXPECT_EQ(unsignedIntOpt1, 0);
@ -619,7 +619,7 @@ TEST_CASE(NumberOptions)
// Required unsigned int short option, empty given
unsignedIntOpt1 = 0;
result = runParser({ "-u" }, [&](auto& parser) {
parser.addOption(unsignedIntOpt1, 'u', nullptr, nullptr, nullptr, nullptr, Util::ArgParser::Required::Yes);
parser.addOption(unsignedIntOpt1, 'u', nullptr, nullptr, nullptr, nullptr, ruc::ArgParser::Required::Yes);
});
EXPECT_EQ(result, false);
EXPECT_EQ(unsignedIntOpt1, 0);
@ -627,7 +627,7 @@ TEST_CASE(NumberOptions)
// Required double short option
double doubleOpt1 = 0;
result = runParser({ "-d", "999.999" }, [&](auto& parser) {
parser.addOption(doubleOpt1, 'd', nullptr, nullptr, nullptr, nullptr, Util::ArgParser::Required::Yes);
parser.addOption(doubleOpt1, 'd', nullptr, nullptr, nullptr, nullptr, ruc::ArgParser::Required::Yes);
});
EXPECT_EQ(result, true);
EXPECT_EQ(doubleOpt1, 999.999);
@ -635,7 +635,7 @@ TEST_CASE(NumberOptions)
// Required double short option, empty given
doubleOpt1 = 0;
result = runParser({ "-d" }, [&](auto& parser) {
parser.addOption(doubleOpt1, 'd', nullptr, nullptr, nullptr, nullptr, Util::ArgParser::Required::Yes);
parser.addOption(doubleOpt1, 'd', nullptr, nullptr, nullptr, nullptr, ruc::ArgParser::Required::Yes);
});
EXPECT_EQ(result, false);
EXPECT_EQ(doubleOpt1, 0);
@ -648,7 +648,7 @@ TEST_CASE(VectorStringOptions)
// Required vector string short option, not given
std::vector<std::string> vectorOpt1 = {};
auto result = runParser({}, [&](auto& parser) {
parser.addOption(vectorOpt1, 'v', nullptr, nullptr, nullptr, nullptr, Util::ArgParser::Required::Yes);
parser.addOption(vectorOpt1, 'v', nullptr, nullptr, nullptr, nullptr, ruc::ArgParser::Required::Yes);
});
EXPECT_EQ(result, true);
EXPECT_EQ(vectorOpt1.size(), 0);
@ -656,7 +656,7 @@ TEST_CASE(VectorStringOptions)
// Required vector string short option, empty given
vectorOpt1 = {};
result = runParser({ "-v" }, [&](auto& parser) {
parser.addOption(vectorOpt1, 'v', nullptr, nullptr, nullptr, nullptr, Util::ArgParser::Required::Yes);
parser.addOption(vectorOpt1, 'v', nullptr, nullptr, nullptr, nullptr, ruc::ArgParser::Required::Yes);
});
EXPECT_EQ(result, false);
EXPECT_EQ(vectorOpt1.size(), 0);
@ -664,7 +664,7 @@ TEST_CASE(VectorStringOptions)
// Required vector string short option, one given
vectorOpt1 = {};
result = runParser({ "-v", "a vector argument!" }, [&](auto& parser) {
parser.addOption(vectorOpt1, 'v', nullptr, nullptr, nullptr, nullptr, Util::ArgParser::Required::Yes);
parser.addOption(vectorOpt1, 'v', nullptr, nullptr, nullptr, nullptr, ruc::ArgParser::Required::Yes);
});
EXPECT_EQ(result, true);
EXPECT_EQ(vectorOpt1.size(), 1);
@ -675,7 +675,7 @@ TEST_CASE(VectorStringOptions)
// Required vector string short option, two given
vectorOpt1 = {};
result = runParser({ "-v", "hello", "-v", "world" }, [&](auto& parser) {
parser.addOption(vectorOpt1, 'v', nullptr, nullptr, nullptr, nullptr, Util::ArgParser::Required::Yes);
parser.addOption(vectorOpt1, 'v', nullptr, nullptr, nullptr, nullptr, ruc::ArgParser::Required::Yes);
});
EXPECT_EQ(result, true);
EXPECT_EQ(vectorOpt1.size(), 2);
@ -687,7 +687,7 @@ TEST_CASE(VectorStringOptions)
// Required vector string short option, two given directly after
vectorOpt1 = {};
result = runParser({ "-vhello", "-vworld" }, [&](auto& parser) {
parser.addOption(vectorOpt1, 'v', nullptr, nullptr, nullptr, nullptr, Util::ArgParser::Required::Yes);
parser.addOption(vectorOpt1, 'v', nullptr, nullptr, nullptr, nullptr, ruc::ArgParser::Required::Yes);
});
EXPECT_EQ(result, true);
EXPECT_EQ(vectorOpt1.size(), 2);
@ -699,7 +699,7 @@ TEST_CASE(VectorStringOptions)
// Required vector string long option, empty given
vectorOpt1 = {};
result = runParser({ "--vector" }, [&](auto& parser) {
parser.addOption(vectorOpt1, '\0', "vector", nullptr, nullptr, nullptr, Util::ArgParser::Required::Yes);
parser.addOption(vectorOpt1, '\0', "vector", nullptr, nullptr, nullptr, ruc::ArgParser::Required::Yes);
});
EXPECT_EQ(result, false);
EXPECT_EQ(vectorOpt1.size(), 0);
@ -707,7 +707,7 @@ TEST_CASE(VectorStringOptions)
// Required vector string long option, one given
vectorOpt1 = {};
result = runParser({ "--vector", "a vector argument!" }, [&](auto& parser) {
parser.addOption(vectorOpt1, '\0', "vector", nullptr, nullptr, nullptr, Util::ArgParser::Required::Yes);
parser.addOption(vectorOpt1, '\0', "vector", nullptr, nullptr, nullptr, ruc::ArgParser::Required::Yes);
});
EXPECT_EQ(result, true);
EXPECT_EQ(vectorOpt1.size(), 1);
@ -718,7 +718,7 @@ TEST_CASE(VectorStringOptions)
// Required vector string long option, two given
vectorOpt1 = {};
result = runParser({ "--vector", "hello", "--vector", "world" }, [&](auto& parser) {
parser.addOption(vectorOpt1, '\0', "vector", nullptr, nullptr, nullptr, Util::ArgParser::Required::Yes);
parser.addOption(vectorOpt1, '\0', "vector", nullptr, nullptr, nullptr, ruc::ArgParser::Required::Yes);
});
EXPECT_EQ(result, true);
EXPECT_EQ(vectorOpt1.size(), 2);
@ -730,7 +730,7 @@ TEST_CASE(VectorStringOptions)
// Required vector string long option, two given directly after
vectorOpt1 = {};
result = runParser({ "--vector=hello", "--vector=world" }, [&](auto& parser) {
parser.addOption(vectorOpt1, '\0', "vector", nullptr, nullptr, nullptr, Util::ArgParser::Required::Yes);
parser.addOption(vectorOpt1, '\0', "vector", nullptr, nullptr, nullptr, ruc::ArgParser::Required::Yes);
});
EXPECT_EQ(result, true);
EXPECT_EQ(vectorOpt1.size(), 2);
@ -750,7 +750,7 @@ TEST_CASE(MultipleOptions)
std::vector<std::string> vectorArg1 = {};
auto result = runParser({ "-b", "something", "-s", "a-string-value" }, [&](auto& parser) {
parser.addOption(boolOpt1, 'b', nullptr, nullptr, nullptr);
parser.addOption(stringOpt1, 's', nullptr, nullptr, nullptr, nullptr, Util::ArgParser::Required::Yes);
parser.addOption(stringOpt1, 's', nullptr, nullptr, nullptr, nullptr, ruc::ArgParser::Required::Yes);
parser.addArgument(vectorArg1, nullptr, nullptr, nullptr);
});
EXPECT_EQ(result, true);

232
test/unit/testutilformat.cpp

@ -13,9 +13,9 @@
#include <vector>
#include "macro.h"
#include "ruc/format/format.h"
#include "testcase.h"
#include "testsuite.h"
#include "util/format/format.h"
// -----------------------------------------
@ -26,37 +26,37 @@ TEST_CASE(FormatIntegral)
// Signed
int8_t i8 = 127; // char
result = Util::format("{}", i8);
result = format("{}", i8);
EXPECT_EQ(result, "127");
int16_t i16 = 32767;
result = Util::format("{}", i16);
result = format("{}", i16);
EXPECT_EQ(result, "32767");
int32_t i32 = 68766; // int
result = Util::format("{}", i32);
result = format("{}", i32);
EXPECT_EQ(result, "68766");
int64_t i64 = 237942768427; // long int
result = Util::format("{}", i64);
result = format("{}", i64);
EXPECT_EQ(result, "237942768427");
// Unsigned
uint8_t u8 = 255; // unsigned char
result = Util::format("{}", u8);
result = format("{}", u8);
EXPECT_EQ(result, "255");
uint16_t u16 = 65535;
result = Util::format("{}", u16);
result = format("{}", u16);
EXPECT_EQ(result, "65535");
uint32_t u32 = 4294967295; // unsigned int
result = Util::format("{}", u32);
result = format("{}", u32);
EXPECT_EQ(result, "4294967295");
size_t u64 = 18446744073709551615; // long unsigned int
result = Util::format("{}", u64);
result = format("{}", u64);
EXPECT_EQ(result, "18446744073709551615");
}
@ -65,19 +65,19 @@ TEST_CASE(FormatFloatingPoint)
std::string result;
float f32R = 245789.70000;
result = Util::format("{}", f32R);
result = format("{}", f32R);
EXPECT_EQ(result, "245789.703125");
float f32 = 45645.3233;
result = Util::format("{}", f32);
result = format("{}", f32);
EXPECT_EQ(result, "45645.324219");
double f64 = 87522.300000000;
result = Util::format("{}", f64);
result = format("{}", f64);
EXPECT_EQ(result, "87522.300000");
double pi = 3.14159265359;
result = Util::format("{}", pi);
result = format("{}", pi);
EXPECT_EQ(result, "3.141593");
}
@ -86,15 +86,15 @@ TEST_CASE(FormatChar)
std::string result;
char character = 'A';
result = Util::format("{}", character);
result = format("{}", character);
EXPECT_EQ(result, "A");
bool boolean = true;
result = Util::format("{}", boolean);
result = format("{}", boolean);
EXPECT_EQ(result, "true");
boolean = false;
result = Util::format("{}", boolean);
result = format("{}", boolean);
EXPECT_EQ(result, "false");
}
@ -102,28 +102,28 @@ TEST_CASE(FormatString)
{
std::string result;
result = Util::format("");
result = format("");
EXPECT_EQ(result, "");
const char* cString = "C string";
result = Util::format("{}", cString);
result = format("{}", cString);
EXPECT_EQ(result, "C string");
std::string string = "string";
result = Util::format("{}", string);
result = format("{}", string);
EXPECT_EQ(result, "string");
std::string_view stringView = "string_view";
result = Util::format("{}", stringView);
result = format("{}", stringView);
EXPECT_EQ(result, "string_view");
result = Util::format("{} {}", "Hello", "World");
result = format("{} {}", "Hello", "World");
EXPECT_EQ(result, "Hello World");
result = Util::format("{{escaped braces}}");
result = format("{{escaped braces}}");
EXPECT_EQ(result, "{escaped braces}");
result = Util::format("{{braces{}}}", "Something");
result = format("{{braces{}}}", "Something");
EXPECT_EQ(result, "{bracesSomething}");
}
@ -131,7 +131,7 @@ TEST_CASE(FormatPointer)
{
std::string result;
result = Util::format("{}", nullptr);
result = format("{}", nullptr);
EXPECT_EQ(result, "0x0");
int integer = 42;
@ -139,7 +139,7 @@ TEST_CASE(FormatPointer)
stream << &integer;
std::string pointer = stream.str();
result = Util::format("{}", &integer);
result = format("{}", &integer);
EXPECT_EQ(result, pointer);
}
@ -148,80 +148,80 @@ TEST_CASE(FormatSpecifierIntegral)
std::string result;
// Fill and Align
result = Util::format("{:+<}", 12345);
result = format("{:+<}", 12345);
EXPECT_EQ(result, "12345");
result = Util::format("{:+^}", 12345);
result = format("{:+^}", 12345);
EXPECT_EQ(result, "12345");
result = Util::format("{:+>}", 12345);
result = format("{:+>}", 12345);
EXPECT_EQ(result, "12345");
// Sign
result = Util::format("{:+}", 12345);
result = format("{:+}", 12345);
EXPECT_EQ(result, "+12345");
result = Util::format("{:+}", -12345);
result = format("{:+}", -12345);
EXPECT_EQ(result, "-12345");
result = Util::format("{:-}", 12345);
result = format("{:-}", 12345);
EXPECT_EQ(result, "12345");
result = Util::format("{:-}", -12345);
result = format("{:-}", -12345);
EXPECT_EQ(result, "-12345");
result = Util::format("{: }", 12345);
result = format("{: }", 12345);
EXPECT_EQ(result, " 12345");
result = Util::format("{: }", -12345);
result = format("{: }", -12345);
EXPECT_EQ(result, "-12345");
// AlternativeForm
result = Util::format("{:#}", 12345);
result = format("{:#}", 12345);
EXPECT_EQ(result, "12345");
// ZeroPadding
result = Util::format("{:0}", 12345);
result = format("{:0}", 12345);
EXPECT_EQ(result, "12345");
// Width
result = Util::format("{:10}", 12345);
result = format("{:10}", 12345);
EXPECT_EQ(result, " 12345");
// Width + Fill and Align
result = Util::format("{:+<10}", 12345);
result = format("{:+<10}", 12345);
EXPECT_EQ(result, "12345+++++");
result = Util::format("{:+^10}", 12345);
result = format("{:+^10}", 12345);
EXPECT_EQ(result, "++12345+++");
result = Util::format("{:+>10}", 12345);
result = format("{:+>10}", 12345);
EXPECT_EQ(result, "+++++12345");
// Width + ZeroPadding
result = Util::format("{:010}", 12345);
result = format("{:010}", 12345);
EXPECT_EQ(result, "0000012345");
// Precision
// Not possible on integral types
// Type
result = Util::format("{:b}", 12345);
result = format("{:b}", 12345);
EXPECT_EQ(result, "11000000111001");
result = Util::format("{:B}", 12345);
result = format("{:B}", 12345);
EXPECT_EQ(result, "11000000111001");
result = Util::format("{:c}", 65);
result = format("{:c}", 65);
EXPECT_EQ(result, "A");
result = Util::format("{:o}", 12345);
result = format("{:o}", 12345);
EXPECT_EQ(result, "30071");
result = Util::format("{:x}", 62432);
result = format("{:x}", 62432);
EXPECT_EQ(result, "f3e0");
result = Util::format("{:X}", 62432);
result = format("{:X}", 62432);
EXPECT_EQ(result, "F3E0");
// Type + AlternativeForm
result = Util::format("{:#b}", 12345);
result = format("{:#b}", 12345);
EXPECT_EQ(result, "0b11000000111001");
result = Util::format("{:#B}", 12345);
result = format("{:#B}", 12345);
EXPECT_EQ(result, "0B11000000111001");
result = Util::format("{:#c}", 65);
result = format("{:#c}", 65);
EXPECT_EQ(result, "A");
result = Util::format("{:#o}", 12345);
result = format("{:#o}", 12345);
EXPECT_EQ(result, "030071");
result = Util::format("{:#x}", 62432);
result = format("{:#x}", 62432);
EXPECT_EQ(result, "0xf3e0");
result = Util::format("{:#X}", 62432);
result = format("{:#X}", 62432);
EXPECT_EQ(result, "0XF3E0");
}
@ -232,78 +232,78 @@ TEST_CASE(FormatSpecifierIntegralCombination)
// AlternativeForm + ZeroPadding + Width + Type
// ------------------------------
result = Util::format("{:-#010d}", 402);
result = format("{:-#010d}", 402);
EXPECT_EQ(result, "0000000402");
// AlternativeForm + Width + Type
// ------------------------------
result = Util::format("{:#10x}", 402);
result = format("{:#10x}", 402);
EXPECT_EQ(result, " 0x192");
// + Fill and Align
result = Util::format("{:^<#10x}", 402);
result = format("{:^<#10x}", 402);
EXPECT_EQ(result, "0x192^^^^^");
result = Util::format("{:^^#10x}", 402);
result = format("{:^^#10x}", 402);
EXPECT_EQ(result, "^^0x192^^^");
result = Util::format("{:^>#10x}", 402);
result = format("{:^>#10x}", 402);
EXPECT_EQ(result, "^^^^^0x192");
// ------------------------------
// + Sign
result = Util::format("{:+#10x}", 402);
result = format("{:+#10x}", 402);
EXPECT_EQ(result, " +0x192");
// + Fill and Align + Sign
result = Util::format("{:^<+#10x}", 402);
result = format("{:^<+#10x}", 402);
EXPECT_EQ(result, "+0x192^^^^");
result = Util::format("{:^^+#10x}", 402);
result = format("{:^^+#10x}", 402);
EXPECT_EQ(result, "^^+0x192^^");
result = Util::format("{:^>+#10x}", 402);
result = format("{:^>+#10x}", 402);
EXPECT_EQ(result, "^^^^+0x192");
// ------------------------------
// + ZeroPadding
result = Util::format("{:#010x}", 402);
result = format("{:#010x}", 402);
EXPECT_EQ(result, "0x00000192");
// Fill and Align + ZeroPadding
result = Util::format("{:^<#010x}", 402);
result = format("{:^<#010x}", 402);
EXPECT_EQ(result, "0x19200000");
result = Util::format("{:^^#010x}", 402);
result = format("{:^^#010x}", 402);
EXPECT_EQ(result, "000x192000");
result = Util::format("{:^>#010x}", 402);
result = format("{:^>#010x}", 402);
EXPECT_EQ(result, "000000x192");
// ------------------------------
// + Sign + ZeroPadding
result = Util::format("{:+#010x}", 402);
result = format("{:+#010x}", 402);
EXPECT_EQ(result, "+0x0000192");
// + Fill and Align + Sign + ZeroPadding
result = Util::format("{:^<+#010x}", 402);
result = format("{:^<+#010x}", 402);
EXPECT_EQ(result, "+0x1920000");
result = Util::format("{:^^+#010x}", 402);
result = format("{:^^+#010x}", 402);
EXPECT_EQ(result, "00+0x19200");
result = Util::format("{:^>+#010x}", 402);
result = format("{:^>+#010x}", 402);
EXPECT_EQ(result, "0000+0x192");
}
@ -312,14 +312,14 @@ TEST_CASE(FormatSpecifierFloatingPoint)
std::string result;
double f64 = 87522.300000000;
result = Util::format("{:.1}", f64);
result = format("{:.1}", f64);
EXPECT_EQ(result, "87522.3");
double pi = 3.14159265359;
result = Util::format("{}", pi);
result = format("{}", pi);
EXPECT_EQ(result, "3.141593");
result = Util::format("{:.15}", pi);
result = format("{:.15}", pi);
EXPECT_EQ(result, "3.141592653590000");
}
@ -328,45 +328,45 @@ TEST_CASE(FormatSpecifierChar)
std::string result;
char character = 65;
result = Util::format("{:b}", character);
result = format("{:b}", character);
EXPECT_EQ(result, "1000001");
result = Util::format("{:B}", character);
result = format("{:B}", character);
EXPECT_EQ(result, "1000001");
result = Util::format("{:d}", character);
result = format("{:d}", character);
EXPECT_EQ(result, "65");
result = Util::format("{:o}", character);
result = format("{:o}", character);
EXPECT_EQ(result, "101");
result = Util::format("{:x}", character);
result = format("{:x}", character);
EXPECT_EQ(result, "41");
result = Util::format("{:X}", character);
result = format("{:X}", character);
EXPECT_EQ(result, "41");
bool boolean = true;
result = Util::format("{:b}", boolean);
result = format("{:b}", boolean);
EXPECT_EQ(result, "1");
result = Util::format("{:B}", boolean);
result = format("{:B}", boolean);
EXPECT_EQ(result, "1");
result = Util::format("{:d}", boolean);
result = format("{:d}", boolean);
EXPECT_EQ(result, "1");
result = Util::format("{:o}", boolean);
result = format("{:o}", boolean);
EXPECT_EQ(result, "1");
result = Util::format("{:x}", boolean);
result = format("{:x}", boolean);
EXPECT_EQ(result, "1");
result = Util::format("{:X}", boolean);
result = format("{:X}", boolean);
EXPECT_EQ(result, "1");
boolean = false;
result = Util::format("{:b}", boolean);
result = format("{:b}", boolean);
EXPECT_EQ(result, "0");
result = Util::format("{:B}", boolean);
result = format("{:B}", boolean);
EXPECT_EQ(result, "0");
result = Util::format("{:d}", boolean);
result = format("{:d}", boolean);
EXPECT_EQ(result, "0");
result = Util::format("{:o}", boolean);
result = format("{:o}", boolean);
EXPECT_EQ(result, "0");
result = Util::format("{:x}", boolean);
result = format("{:x}", boolean);
EXPECT_EQ(result, "0");
result = Util::format("{:X}", boolean);
result = format("{:X}", boolean);
EXPECT_EQ(result, "0");
}
@ -377,11 +377,11 @@ TEST_CASE(FormatSpecifierString)
std::string string = "my string";
// Fill and Align
result = Util::format("{:+<}", string);
result = format("{:+<}", string);
EXPECT_EQ(result, "my string");
result = Util::format("{:+^}", string);
result = format("{:+^}", string);
EXPECT_EQ(result, "my string");
result = Util::format("{:+>}", string);
result = format("{:+>}", string);
EXPECT_EQ(result, "my string");
// Sign
@ -394,22 +394,22 @@ TEST_CASE(FormatSpecifierString)
// Not possible on string types
// Width
result = Util::format("{:15}", string);
result = format("{:15}", string);
EXPECT_EQ(result, "my string ");
// Width + Fill and Align
result = Util::format("{:+<15}", string);
result = format("{:+<15}", string);
EXPECT_EQ(result, "my string++++++");
result = Util::format("{:+^15}", string);
result = format("{:+^15}", string);
EXPECT_EQ(result, "+++my string+++");
result = Util::format("{:+>15}", string);
result = format("{:+>15}", string);
EXPECT_EQ(result, "++++++my string");
// Precision
// Not possible on string types
// Type
result = Util::format("{:s}", string);
result = format("{:s}", string);
EXPECT_EQ(result, "my string");
}
@ -423,11 +423,11 @@ TEST_CASE(FormatSpecifierPointer)
std::string pointer = stream.str();
// Fill and Align
result = Util::format("{:+<}", &integer);
result = format("{:+<}", &integer);
EXPECT_EQ(result, pointer);
result = Util::format("{:+^}", &integer);
result = format("{:+^}", &integer);
EXPECT_EQ(result, pointer);
result = Util::format("{:+>}", &integer);
result = format("{:+>}", &integer);
EXPECT_EQ(result, pointer);
// Sign
@ -440,22 +440,22 @@ TEST_CASE(FormatSpecifierPointer)
// Not possible on string types
// Width
result = Util::format("{:24}", &integer);
result = format("{:24}", &integer);
EXPECT_EQ(result, std::string(24 - pointer.length(), ' ') + pointer);
// Width + Fill and Align
result = Util::format("{:+<24}", &integer);
result = format("{:+<24}", &integer);
EXPECT_EQ(result, pointer + std::string(24 - pointer.length(), '+'));
result = Util::format("{:+^24}", &integer);
result = format("{:+^24}", &integer);
EXPECT_EQ(result, std::string((24 - pointer.length()) / 2, '+') + pointer + std::string((24 - pointer.length()) / 2, '+'));
result = Util::format("{:+>24}", &integer);
result = format("{:+>24}", &integer);
EXPECT_EQ(result, std::string(24 - pointer.length(), '+') + pointer);
// Precision
// Not possible on string types
// Type
result = Util::format("{:p}", &integer);
result = format("{:p}", &integer);
EXPECT_EQ(result, pointer);
}
@ -464,17 +464,17 @@ TEST_CASE(FormatContainers)
std::string result;
std::vector<std::string> vector { "thing1", "thing2", "thing3" };
result = Util::format("{}", vector);
result = format("{}", vector);
EXPECT_EQ(result, "{thing1,thing2,thing3}");
result = Util::format("{:1}", vector);
result = format("{:1}", vector);
EXPECT_EQ(result, "{ thing1, thing2, thing3 }");
result = Util::format("{:#4}", vector);
result = format("{:#4}", vector);
EXPECT_EQ(result, R"({
thing1,
thing2,
thing3
})");
result = Util::format("{:\t<#1}", vector);
result = format("{:\t<#1}", vector);
EXPECT_EQ(result, R"({
thing1,
thing2,
@ -482,17 +482,17 @@ TEST_CASE(FormatContainers)
})");
std::map<std::string, int> map { { "thing3", 3 }, { "thing2", 2 }, { "thing1", 1 } };
result = Util::format("{}", map);
result = format("{}", map);
EXPECT_EQ(result, R"({"thing1":1,"thing2":2,"thing3":3})");
result = Util::format("{:1}", map);
result = format("{:1}", map);
EXPECT_EQ(result, R"({ "thing1": 1, "thing2": 2, "thing3": 3 })");
result = Util::format("{:#4}", map);
result = format("{:#4}", map);
EXPECT_EQ(result, R"({
"thing1": 1,
"thing2": 2,
"thing3": 3
})");
result = Util::format("{:\t<#1}", map);
result = format("{:\t<#1}", map);
EXPECT_EQ(result, R"({
"thing1": 1,
"thing2": 2,
@ -505,7 +505,7 @@ TEST_CASE(FormatContainers)
{ "thing1", "thing2", "thing3" },
{ "thing1", "thing2", "thing3" }
};
result = Util::format("{:#4}", twoDimensionalVector);
result = format("{:#4}", twoDimensionalVector);
EXPECT_EQ(result, R"({
{thing1,thing2,thing3},
{thing1,thing2,thing3}

166
test/unit/testutiljson.cpp

@ -13,40 +13,40 @@
#include <vector>
#include "macro.h"
#include "ruc/json/array.h"
#include "ruc/json/job.h"
#include "ruc/json/json.h"
#include "ruc/json/lexer.h"
#include "ruc/json/parser.h"
#include "ruc/json/serializer.h"
#include "testcase.h"
#include "testsuite.h"
#include "util/json/array.h"
#include "util/json/job.h"
#include "util/json/json.h"
#include "util/json/lexer.h"
#include "util/json/parser.h"
#include "util/json/serializer.h"
#define DONT_PRINT_PARSER_ERRORS
#ifndef DONT_PRINT_PARSER_ERRORS
#define EXEC(x) x
#define EXEC(x) x
#else
#define EXEC(x) \
stderr = Test::TestSuite::the().outputNull(); \
#define EXEC(x) \
stderr = test::TestSuite::the().outputNull(); \
x; \
stderr = Test::TestSuite::the().outputErr();
stderr = test::TestSuite::the().outputErr();
#endif
std::vector<Util::JSON::Token> lex(const std::string& input)
std::vector<ruc::json::Token> lex(const std::string& input)
{
EXEC(
Util::JSON::Job job(input);
Util::JSON::Lexer lexer(&job);
ruc::json::Job job(input);
ruc::json::Lexer lexer(&job);
lexer.analyze(););
return *job.tokens();
}
Util::Json parse(const std::string& input)
ruc::Json parse(const std::string& input)
{
EXEC(
Util::JSON::Job job(input);
Util::JSON::Lexer lexer(&job);
ruc::json::Job job(input);
ruc::json::Lexer lexer(&job);
lexer.analyze(););
if (!job.success()) {
@ -54,8 +54,8 @@ Util::Json parse(const std::string& input)
}
EXEC(
Util::JSON::Parser parser(&job);
Util::Json json = parser.parse(););
ruc::json::Parser parser(&job);
ruc::Json json = parser.parse(););
if (!job.success()) {
return nullptr;
@ -67,7 +67,7 @@ Util::Json parse(const std::string& input)
std::string serialize(const std::string& input, uint32_t indent = 0)
{
EXEC(
auto json = Util::Json::parse(input););
auto json = ruc::Json::parse(input););
return json.dump(indent);
}
@ -75,59 +75,59 @@ std::string serialize(const std::string& input, uint32_t indent = 0)
TEST_CASE(JsonLexer)
{
std::vector<Util::JSON::Token> tokens;
std::vector<ruc::json::Token> tokens;
// Literal
tokens = lex("true");
EXPECT_EQ(tokens.size(), 1);
EXPECT_EQ(tokens[0].symbol, "true");
EXPECT(tokens[0].type == Util::JSON::Token::Type::Literal);
EXPECT(tokens[0].type == ruc::json::Token::Type::Literal);
tokens = lex("false");
EXPECT_EQ(tokens.size(), 1);
EXPECT_EQ(tokens[0].symbol, "false");
EXPECT(tokens[0].type == Util::JSON::Token::Type::Literal);
EXPECT(tokens[0].type == ruc::json::Token::Type::Literal);
tokens = lex("null");
EXPECT_EQ(tokens.size(), 1);
EXPECT_EQ(tokens[0].symbol, "null");
EXPECT(tokens[0].type == Util::JSON::Token::Type::Literal);
EXPECT(tokens[0].type == ruc::json::Token::Type::Literal);
// Number
tokens = lex("3.14");
EXPECT_EQ(tokens.size(), 1);
EXPECT_EQ(tokens[0].symbol, "3.14");
EXPECT(tokens[0].type == Util::JSON::Token::Type::Number);
EXPECT(tokens[0].type == ruc::json::Token::Type::Number);
tokens = lex("-3.14e+2");
EXPECT_EQ(tokens.size(), 1);
EXPECT_EQ(tokens[0].symbol, "-3.14e+2");
EXPECT(tokens[0].type == Util::JSON::Token::Type::Number);
EXPECT(tokens[0].type == ruc::json::Token::Type::Number);
tokens = lex("+3.14");
EXPECT_EQ(tokens.size(), 1);
EXPECT_EQ(tokens[0].symbol, "+");
EXPECT(tokens[0].type == Util::JSON::Token::Type::None);
EXPECT(tokens[0].type == ruc::json::Token::Type::None);
// String
tokens = lex(R"("a string")");
EXPECT_EQ(tokens.size(), 1);
EXPECT_EQ(tokens[0].symbol, "a string");
EXPECT(tokens[0].type == Util::JSON::Token::Type::String);
EXPECT(tokens[0].type == ruc::json::Token::Type::String);
tokens = lex(R"("a string""another string")");
EXPECT_EQ(tokens.size(), 2);
EXPECT_EQ(tokens[0].symbol, "a string");
EXPECT_EQ(tokens[1].symbol, "another string");
EXPECT(tokens[0].type == Util::JSON::Token::Type::String);
EXPECT(tokens[0].type == ruc::json::Token::Type::String);
tokens = lex("\"a string\nwill break on the newline symbol\"");
EXPECT_EQ(tokens.size(), 1);
EXPECT_EQ(tokens[0].symbol, "a string");
EXPECT(tokens[0].type == Util::JSON::Token::Type::String);
EXPECT(tokens[0].type == ruc::json::Token::Type::String);
// Array
@ -156,186 +156,186 @@ TEST_CASE(JsonLexer)
TEST_CASE(JsonParser)
{
Util::Json json;
ruc::Json json;
json = parse("null");
EXPECT_EQ(json.size(), 0);
EXPECT_EQ(json.type(), Util::Json::Type::Null);
EXPECT_EQ(json.type(), ruc::Json::Type::Null);
json = parse("true");
EXPECT_EQ(json.size(), 1);
EXPECT_EQ(json.type(), Util::Json::Type::Bool);
EXPECT_EQ(json.type(), ruc::Json::Type::Bool);
json = parse("false");
EXPECT_EQ(json.size(), 1);
EXPECT_EQ(json.type(), Util::Json::Type::Bool);
EXPECT_EQ(json.type(), ruc::Json::Type::Bool);
json = parse("3.14");
EXPECT_EQ(json.size(), 1);
EXPECT_EQ(json.type(), Util::Json::Type::Number);
EXPECT_EQ(json.type(), ruc::Json::Type::Number);
json = parse(R"("a string")");
EXPECT_EQ(json.size(), 1);
EXPECT_EQ(json.type(), Util::Json::Type::String);
EXPECT_EQ(json.type(), ruc::Json::Type::String);
// Array
json = parse("[");
EXPECT_EQ(json.size(), 0);
EXPECT_EQ(json.type(), Util::Json::Type::Null);
EXPECT_EQ(json.type(), ruc::Json::Type::Null);
json = parse("[ 123");
EXPECT_EQ(json.size(), 0);
EXPECT_EQ(json.type(), Util::Json::Type::Null);
EXPECT_EQ(json.type(), ruc::Json::Type::Null);
json = parse("[ 123,");
EXPECT_EQ(json.size(), 0);
EXPECT_EQ(json.type(), Util::Json::Type::Null);
EXPECT_EQ(json.type(), ruc::Json::Type::Null);
json = parse("[ 123, ]");
EXPECT_EQ(json.size(), 0);
EXPECT_EQ(json.type(), Util::Json::Type::Null);
EXPECT_EQ(json.type(), ruc::Json::Type::Null);
json = parse("[ 123 456 ]");
EXPECT_EQ(json.size(), 0);
EXPECT_EQ(json.type(), Util::Json::Type::Null);
EXPECT_EQ(json.type(), ruc::Json::Type::Null);
json = parse("[]");
EXPECT_EQ(json.size(), 0);
EXPECT_EQ(json.type(), Util::Json::Type::Array);
EXPECT_EQ(json.type(), ruc::Json::Type::Array);
json = parse(R"([ "element", 3.14 ])");
EXPECT_EQ(json.size(), 2);
EXPECT_EQ(json.type(), Util::Json::Type::Array);
EXPECT_EQ(json.type(), ruc::Json::Type::Array);
// Object
json = parse("{");
EXPECT_EQ(json.size(), 0);
EXPECT_EQ(json.type(), Util::Json::Type::Null);
EXPECT_EQ(json.type(), ruc::Json::Type::Null);
json = parse(R"({ "name")");
EXPECT_EQ(json.size(), 0);
EXPECT_EQ(json.type(), Util::Json::Type::Null);
EXPECT_EQ(json.type(), ruc::Json::Type::Null);
json = parse(R"({ "name":)");
EXPECT_EQ(json.size(), 0);
EXPECT_EQ(json.type(), Util::Json::Type::Null);
EXPECT_EQ(json.type(), ruc::Json::Type::Null);
json = parse(R"({ "name":,)");
EXPECT_EQ(json.size(), 0);
EXPECT_EQ(json.type(), Util::Json::Type::Null);
EXPECT_EQ(json.type(), ruc::Json::Type::Null);
json = parse(R"({ "name":"value")");
EXPECT_EQ(json.size(), 0);
EXPECT_EQ(json.type(), Util::Json::Type::Null);
EXPECT_EQ(json.type(), ruc::Json::Type::Null);
json = parse(R"({ "name":"value",)");
EXPECT_EQ(json.size(), 0);
EXPECT_EQ(json.type(), Util::Json::Type::Null);
EXPECT_EQ(json.type(), ruc::Json::Type::Null);
json = parse(R"({ "name":"value", })");
EXPECT_EQ(json.size(), 0);
EXPECT_EQ(json.type(), Util::Json::Type::Null);
EXPECT_EQ(json.type(), ruc::Json::Type::Null);
json = parse(R"({ "name" "value" })");
EXPECT_EQ(json.size(), 0);
EXPECT_EQ(json.type(), Util::Json::Type::Null);
EXPECT_EQ(json.type(), ruc::Json::Type::Null);
json = parse(R"({ 123 })");
EXPECT_EQ(json.size(), 0);
EXPECT_EQ(json.type(), Util::Json::Type::Null);
EXPECT_EQ(json.type(), ruc::Json::Type::Null);
json = parse("{}");
EXPECT_EQ(json.size(), 0);
EXPECT_EQ(json.type(), Util::Json::Type::Object);
EXPECT_EQ(json.type(), ruc::Json::Type::Object);
json = parse(R"({ "name": "value", "name2": 3.14 })");
EXPECT_EQ(json.size(), 2);
EXPECT_EQ(json.type(), Util::Json::Type::Object);
EXPECT_EQ(json.type(), ruc::Json::Type::Object);
// Multiple root elements
json = parse("54 false");
EXPECT_EQ(json.type(), Util::Json::Type::Null);
EXPECT_EQ(json.type(), ruc::Json::Type::Null);
json = parse("3.14, 666");
EXPECT_EQ(json.type(), Util::Json::Type::Null);
EXPECT_EQ(json.type(), ruc::Json::Type::Null);
json = parse("true\nfalse");
EXPECT_EQ(json.type(), Util::Json::Type::Null);
EXPECT_EQ(json.type(), ruc::Json::Type::Null);
}
TEST_CASE(JsonToJsonValue)
{
Util::Json json;
ruc::Json json;
json = {};
EXPECT_EQ(json.size(), 0);
EXPECT_EQ(json.type(), Util::Json::Type::Null);
EXPECT_EQ(json.type(), ruc::Json::Type::Null);
json = nullptr;
EXPECT_EQ(json.size(), 0);
EXPECT_EQ(json.type(), Util::Json::Type::Null);
EXPECT_EQ(json.type(), ruc::Json::Type::Null);
json = true;
EXPECT_EQ(json.size(), 1);
EXPECT_EQ(json.type(), Util::Json::Type::Bool);
EXPECT_EQ(json.type(), ruc::Json::Type::Bool);
json = false;
EXPECT_EQ(json.size(), 1);
EXPECT_EQ(json.type(), Util::Json::Type::Bool);
EXPECT_EQ(json.type(), ruc::Json::Type::Bool);
json = 666;
EXPECT_EQ(json.size(), 1);
EXPECT_EQ(json.type(), Util::Json::Type::Number);
EXPECT_EQ(json.type(), ruc::Json::Type::Number);
json = 3.14;
EXPECT_EQ(json.size(), 1);
EXPECT_EQ(json.type(), Util::Json::Type::Number);
EXPECT_EQ(json.type(), ruc::Json::Type::Number);
const char* characters = "my string";
json = characters;
EXPECT_EQ(json.size(), 1);
EXPECT_EQ(json.type(), Util::Json::Type::String);
EXPECT_EQ(json.type(), ruc::Json::Type::String);
std::string string = "my string";
json = string;
EXPECT_EQ(json.size(), 1);
EXPECT_EQ(json.type(), Util::Json::Type::String);
EXPECT_EQ(json.type(), ruc::Json::Type::String);
// Nested Array with multiple types
json = { "element", 3.14, true, nullptr, { "nested element", { "more nesting", { 1, 2, 3, "yes" } } } };
EXPECT_EQ(json.size(), 5);
EXPECT_EQ(json.type(), Util::Json::Type::Array);
EXPECT_EQ(json.type(), ruc::Json::Type::Array);
// Nested Object with multiple types
json = { { "name", "value" }, { "name2", 3.14 }, { "name3", true }, { "name4", nullptr }, { "name5", { { "nested name", "value" } } } };
EXPECT_EQ(json.size(), 5);
EXPECT_EQ(json.type(), Util::Json::Type::Object);
EXPECT_EQ(json.type(), ruc::Json::Type::Object);
// Array with singular type
std::vector<std::string> vector = { "element", "element2", "element3" };
json = vector;
EXPECT_EQ(json.size(), 3);
EXPECT_EQ(json.type(), Util::Json::Type::Array);
EXPECT_EQ(json.type(), ruc::Json::Type::Array);
// Object with singular type
std::map<std::string, std::string> map = { { "name", "value" }, { "name2", "value2" } };
json = map;
EXPECT_EQ(json.size(), 2);
EXPECT_EQ(json.type(), Util::Json::Type::Object);
EXPECT_EQ(json.type(), ruc::Json::Type::Object);
// Object with singular type
std::unordered_map<std::string, std::string> unorderedMap = { { "name", "value" }, { "name2", "value2" } };
json = unorderedMap;
EXPECT_EQ(json.size(), 2);
EXPECT_EQ(json.type(), Util::Json::Type::Object);
EXPECT_EQ(json.type(), ruc::Json::Type::Object);
}
TEST_CASE(JsonFromJsonValue)
{
Util::Json json;
ruc::Json json;
json = nullptr;
EXPECT_EQ(json.get<std::nullptr_t>(), nullptr);
@ -373,7 +373,7 @@ TEST_CASE(JsonFromJsonValue)
EXPECT_EQ(json.at(1).get<double>(), 3.14);
EXPECT_EQ(json[2].get<bool>(), true);
EXPECT_EQ(json[3].get<std::nullptr_t>(), nullptr);
auto valueArray = json.get<std::vector<Util::Json>>();
auto valueArray = json.get<std::vector<ruc::Json>>();
EXPECT_EQ(valueArray.size(), 4);
EXPECT_EQ(valueArray[0].get<std::string>(), "string");
EXPECT_EQ(valueArray[1].get<double>(), 3.14);
@ -417,7 +417,7 @@ TEST_CASE(JsonFromJsonValue)
EXPECT_EQ(json.at("name2").get<double>(), 3.14);
EXPECT_EQ(json["name3"].get<bool>(), true);
EXPECT_EQ(json["name4"].get<std::nullptr_t>(), nullptr);
auto valueObject = json.get<std::map<std::string, Util::Json>>();
auto valueObject = json.get<std::map<std::string, ruc::Json>>();
EXPECT_EQ(valueObject.size(), 4);
EXPECT_EQ(valueObject["name"].get<std::string>(), "value");
EXPECT_EQ(valueObject["name2"].get<double>(), 3.14);
@ -455,25 +455,25 @@ TEST_CASE(JsonFromJsonValue)
TEST_CASE(JsonImplicitConversion)
{
Util::Json array;
ruc::Json array;
array[0];
EXPECT_EQ(array.type(), Util::Json::Type::Array);
EXPECT_EQ(array.type(), ruc::Json::Type::Array);
Util::Json arrayEmplace;
ruc::Json arrayEmplace;
arrayEmplace.emplace_back("element");
arrayEmplace.emplace_back({ "nested element" });
EXPECT_EQ(arrayEmplace.type(), Util::Json::Type::Array);
EXPECT_EQ(arrayEmplace[1].type(), Util::Json::Type::Array);
EXPECT_EQ(arrayEmplace.type(), ruc::Json::Type::Array);
EXPECT_EQ(arrayEmplace[1].type(), ruc::Json::Type::Array);
Util::Json object;
ruc::Json object;
object[""];
EXPECT_EQ(object.type(), Util::Json::Type::Object);
EXPECT_EQ(object.type(), ruc::Json::Type::Object);
Util::Json objectEmplace;
ruc::Json objectEmplace;
objectEmplace.emplace("name", "value");
objectEmplace.emplace("name2", { { "nested name", "value" } });
EXPECT_EQ(objectEmplace.type(), Util::Json::Type::Object);
EXPECT_EQ(objectEmplace["name2"].type(), Util::Json::Type::Object);
EXPECT_EQ(objectEmplace.type(), ruc::Json::Type::Object);
EXPECT_EQ(objectEmplace["name2"].type(), ruc::Json::Type::Object);
}
TEST_CASE(JsonSerializer)

8
test/unit/testutilshell.cpp

@ -1,21 +1,21 @@
#include <string>
#include "macro.h"
#include "ruc/shell.h"
#include "testcase.h"
#include "testsuite.h"
#include "util/shell.h"
bool runShell(const char* command, std::string* output = nullptr)
{
stdout = Test::TestSuite::the().outputNull();
stdout = test::TestSuite::the().outputNull();
Util::Shell $;
ruc::Shell $;
auto exec = $(command);
if (output) {
*output = exec.output();
}
stdout = Test::TestSuite::the().outputStd();
stdout = test::TestSuite::the().outputStd();
return !exec.status() ? true : false;
}

27
test/unit/testutilsystem.cpp

@ -3,13 +3,13 @@
#include <vector>
#include "macro.h"
#include "ruc/system.h"
#include "testcase.h"
#include "testsuite.h"
#include "util/system.h"
bool runSystem(std::function<Util::System(Util::System&)> commands, std::string* output = nullptr, std::string* error = nullptr)
bool runSystem(std::function<ruc::System(ruc::System&)> commands, std::string* output = nullptr, std::string* error = nullptr)
{
Util::System system;
ruc::System system;
auto exec = commands(system);
if (output) {
*output = exec.output();
@ -30,7 +30,8 @@ TEST_CASE(SystemCommand)
std::string error = "";
auto result = runSystem([&](auto& $) {
return $("echo Hello World!")();
}, &output, &error);
},
&output, &error);
EXPECT_EQ(result, true);
EXPECT_EQ(output, "Hello World!\n");
EXPECT_EQ(error, "");
@ -40,7 +41,8 @@ TEST_CASE(SystemCommand)
error = "";
result = runSystem([&](auto& $) {
return $("echo -n Hello ") + $("echo -n World!");
}, &output, &error);
},
&output, &error);
EXPECT_EQ(result, true);
EXPECT_EQ(output, "Hello World!");
EXPECT_EQ(error, "");
@ -50,7 +52,8 @@ TEST_CASE(SystemCommand)
error = "";
result = runSystem([&](auto& $) {
return $("echo Hello World!") | $("grep --only-matching Hello");
}, &output, &error);
},
&output, &error);
EXPECT_EQ(result, true);
EXPECT_EQ(output, "Hello\n");
EXPECT_EQ(error, "");
@ -60,7 +63,8 @@ TEST_CASE(SystemCommand)
error = "";
result = runSystem([&](auto& $) {
return $("echo Hello") && $("echo World!");
}, &output, &error);
},
&output, &error);
EXPECT_EQ(result, true);
EXPECT_EQ(output, "Hello\nWorld!\n");
EXPECT_EQ(error, "");
@ -70,7 +74,8 @@ TEST_CASE(SystemCommand)
error = "";
result = runSystem([&](auto& $) {
return $("echo Hello") || $("echo World!");
}, &output, &error);
},
&output, &error);
EXPECT_EQ(result, true);
EXPECT_EQ(output, "Hello\n");
EXPECT_EQ(error, "");
@ -80,7 +85,8 @@ TEST_CASE(SystemCommand)
error = "";
result = runSystem([&](auto& $) {
return ($("echo -n one ") && $("echo -n two ") && $("echo -n three")) | $("grep --only-matching two");
}, &output, &error);
},
&output, &error);
EXPECT_EQ(result, true);
EXPECT_EQ(output, "two\n");
EXPECT_EQ(error, "");
@ -91,7 +97,8 @@ TEST_CASE(SystemCommand)
error = "";
result = runSystem([&](auto& $) {
return $("exit 1")();
}, &output, &error);
},
&output, &error);
EXPECT_EQ(result, false);
EXPECT_EQ(output, "");
EXPECT_EQ(error, "");

Loading…
Cancel
Save