Skip to content

Commit

Permalink
[C++] 0.1.0
Browse files Browse the repository at this point in the history
Adequate rework
  • Loading branch information
uselessgoddess committed Jul 2, 2021
1 parent 1c7263b commit b371825
Show file tree
Hide file tree
Showing 15 changed files with 148 additions and 497 deletions.
12 changes: 12 additions & 0 deletions cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
cmake_minimum_required(VERSION 3.15)
project(Platform.Converters)
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup(TARGETS)

add_library(${PROJECT_NAME}.Library INTERFACE)
target_include_directories(${PROJECT_NAME}.Library INTERFACE ${PROJECT_NAME})

add_executable(${PROJECT_NAME}.Tests ${PROJECT_NAME}.Tests/${PROJECT_NAME}.Tests.cpp)
target_link_libraries(${PROJECT_NAME}.Tests PRIVATE ${PROJECT_NAME}.Library)
target_link_libraries(${PROJECT_NAME}.Tests PRIVATE CONAN_PKG::gtest)
set_target_properties(${PROJECT_NAME}.Tests PROPERTIES CXX_STANDARD 20)

This file was deleted.

This file was deleted.

This file was deleted.

59 changes: 59 additions & 0 deletions cpp/Platform.Converters.Tests/Platform.Converters.Tests.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#include <Platform.Converters.h>
#include <gtest/gtest.h>

class A
{
public:
explicit operator std::string() const
{
return "A";
}
};

class B
{
friend std::ostream& operator<<(std::ostream& out, const B& obj)
{
return out << "B";
}
};

struct X {};

namespace Platform::Converters::Tests
{
TEST(ConvertersTests, All)
{
A a;
A &aReference = a;
A *aPointer = &a;
X x;
X *xPointer = &x;

ASSERT_EQ(std::string("1"), (Convert<int, std::string>(1)));
// TODO: really, you have a magic compiler?
// ASSERT_EQ(std::string("1.49"), To<std::string>(1.49));
ASSERT_EQ(std::string("A"), To<std::string>(A()));
ASSERT_EQ(std::string("B"), To<std::string>(B()));
ASSERT_EQ(std::string(""), To<std::string>(std::string("")));
// TODO: really, you have a magic way of storing types without compression?
// ASSERT_EQ(std::string("instance of class X"), To<std::string>(x));

auto pointerToAString = To<std::string>(aPointer); // pointer <6826744964> to <A>
ASSERT_TRUE(pointerToAString.starts_with("pointer <"));
ASSERT_TRUE(pointerToAString.ends_with("> to <A>"));

auto pointerToXString = To<std::string>(xPointer); // pointer <6826744964> to <instanse of class X>
ASSERT_TRUE(pointerToXString.starts_with("pointer <"));
// TODO: really, you have a magic way of storing types without compression?
// ASSERT_TRUE(pointerToXString.ends_with("> to <instance of class X>"));

ASSERT_EQ(std::string("null pointer"), (Convert<X*, std::string>(nullptr)));
ASSERT_EQ(std::string("null pointer"), To<std::string>(nullptr));

ASSERT_EQ(std::string("A"), (Convert<A&, std::string>(a)));

ASSERT_EQ(std::string("A"), To<std::string>(aReference));
ASSERT_EQ(std::string("void pointer <0xa>"), To<std::string>((void *)10));
};
}
5 changes: 0 additions & 5 deletions cpp/Platform.Converters.Tests/pch.cpp

This file was deleted.

Loading

0 comments on commit b371825

Please sign in to comment.