mirror of
https://codeberg.org/DawnMagnet/reflect-cpp
synced 2026-12-06 02:36:18 +08:00
Add tests for writing c arrays.
This commit is contained in:
@@ -60,7 +60,7 @@ struct Parser<R, W, std::array<T, _size>> {
|
||||
AlreadyExtracted&&... _already_extracted) noexcept {
|
||||
constexpr size_t i = sizeof...(AlreadyExtracted);
|
||||
if constexpr (i == _size) {
|
||||
return std::array<T, _size>({std::move(_already_extracted)...});
|
||||
return std::array<T, _size>{std::move(_already_extracted)...};
|
||||
} else {
|
||||
const auto extract_next = [&](auto&& new_entry) {
|
||||
return extract_field_by_field(_r, std::move(_vec),
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
#include "test_c_array_class1.hpp"
|
||||
|
||||
#include <iostream>
|
||||
#include <source_location>
|
||||
#include <string>
|
||||
|
||||
#include "rfl.hpp"
|
||||
#include "rfl/json.hpp"
|
||||
#include "write_and_read.hpp"
|
||||
|
||||
namespace test_c_array_class1 {
|
||||
|
||||
struct Test1 {
|
||||
std::vector<std::string> classes[3];
|
||||
};
|
||||
|
||||
void test() {
|
||||
std::cout << std::source_location::current().function_name() << std::endl;
|
||||
|
||||
Test1 test1 = {.classes = {{"Little A", "Little B", "Little C"},
|
||||
{"BIG A", "BIG B", "BIG C"},
|
||||
{"??", "$%", "#@"}}};
|
||||
write_and_read(
|
||||
test1,
|
||||
R"({"classes":[["Little A","Little B","Little C"],["BIG A","BIG B","BIG C"],["??","$%","#@"]]})");
|
||||
}
|
||||
|
||||
} // namespace test_c_array_class1
|
||||
@@ -0,0 +1,5 @@
|
||||
namespace test_c_array_class1 {
|
||||
|
||||
void test();
|
||||
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
#include "test_c_array_class2.hpp"
|
||||
|
||||
#include <iostream>
|
||||
#include <source_location>
|
||||
#include <string>
|
||||
|
||||
#include "rfl.hpp"
|
||||
#include "rfl/json.hpp"
|
||||
#include "write_and_read.hpp"
|
||||
|
||||
namespace test_c_array_class2 {
|
||||
|
||||
struct Test2 {
|
||||
int multi_dimension_arr[2][2][2][2];
|
||||
std::string s;
|
||||
};
|
||||
|
||||
void test() {
|
||||
std::cout << std::source_location::current().function_name() << std::endl;
|
||||
|
||||
Test2 test2;
|
||||
for (int i = 0; i < 1 << 4; i++) {
|
||||
test2.multi_dimension_arr[i >> 3 & 1][i >> 2 & 1][i >> 1 & 1][i >> 0 & 1] = i;
|
||||
}
|
||||
test2.s = "Hello, world!";
|
||||
|
||||
write_and_read(
|
||||
test2,
|
||||
R"({"multi_dimension_arr":[[[[0,1],[2,3]],[[4,5],[6,7]]],[[[8,9],[10,11]],[[12,13],[14,15]]]],"s":"Hello, world!"})");
|
||||
}
|
||||
|
||||
} // namespace test_c_array
|
||||
@@ -0,0 +1,5 @@
|
||||
namespace test_c_array_class2 {
|
||||
|
||||
void test();
|
||||
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
#include "test_c_array_class3.hpp"
|
||||
|
||||
#include <source_location>
|
||||
#include <array>
|
||||
|
||||
#include "rfl.hpp"
|
||||
#include "rfl/json.hpp"
|
||||
#include "write_and_read.hpp"
|
||||
|
||||
namespace test_c_array_class3 {
|
||||
|
||||
using Test3 = std::array<int, 3>[3];
|
||||
|
||||
void test() {
|
||||
std::cout << std::source_location::current().function_name() << std::endl;
|
||||
|
||||
Test3 test3 = {1, 2, 3, 4, 5, 6, 7, 8, 9};
|
||||
write_and_read(test3, "[[1,2,3],[4,5,6],[7,8,9]]");
|
||||
}
|
||||
|
||||
} // namespace test_c_array
|
||||
@@ -0,0 +1,5 @@
|
||||
namespace test_c_array_class3 {
|
||||
|
||||
void test();
|
||||
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
#include "test_c_array_class4.hpp"
|
||||
|
||||
#include <array>
|
||||
#include <source_location>
|
||||
|
||||
#include "rfl.hpp"
|
||||
#include "rfl/json.hpp"
|
||||
#include "write_and_read.hpp"
|
||||
|
||||
namespace test_c_array_class4 {
|
||||
|
||||
struct Test4 {
|
||||
int a[3];
|
||||
int b[3];
|
||||
int c[2][2];
|
||||
};
|
||||
|
||||
void test() {
|
||||
std::cout << std::source_location::current().function_name() << std::endl;
|
||||
|
||||
Test4 test4 = {.a = {1, 2, 3}, .b = {4, 5, 6}, .c = {{7, 8}, {9, 10}}};
|
||||
|
||||
write_and_read(test4, R"({"a":[1,2,3],"b":[4,5,6],"c":[[7,8],[9,10]]})");
|
||||
}
|
||||
|
||||
} // namespace test_c_array_class4
|
||||
@@ -0,0 +1,5 @@
|
||||
namespace test_c_array_class4 {
|
||||
|
||||
void test();
|
||||
|
||||
}
|
||||
@@ -8,6 +8,10 @@
|
||||
#include "test_as2.hpp"
|
||||
#include "test_as_flatten.hpp"
|
||||
#include "test_box.hpp"
|
||||
#include "test_c_array_class1.hpp"
|
||||
#include "test_c_array_class2.hpp"
|
||||
#include "test_c_array_class3.hpp"
|
||||
#include "test_c_array_class4.hpp"
|
||||
#include "test_custom_class1.hpp"
|
||||
#include "test_custom_class2.hpp"
|
||||
#include "test_custom_class3.hpp"
|
||||
@@ -135,5 +139,9 @@ int main() {
|
||||
|
||||
test_meta_fields::test();
|
||||
|
||||
test_c_array_class1::test();
|
||||
test_c_array_class2::test();
|
||||
test_c_array_class3::test();
|
||||
test_c_array_class4::test();
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user