summaryrefslogtreecommitdiff
path: root/modules/codec/tests/args.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'modules/codec/tests/args.cpp')
-rw-r--r--modules/codec/tests/args.cpp55
1 files changed, 55 insertions, 0 deletions
diff --git a/modules/codec/tests/args.cpp b/modules/codec/tests/args.cpp
new file mode 100644
index 0000000..ed6d918
--- /dev/null
+++ b/modules/codec/tests/args.cpp
@@ -0,0 +1,55 @@
+#include <forstio/test/suite.hpp>
+#include "../c++/args.hpp"
+
+namespace {
+namespace sch {
+using namespace saw::schema;
+
+using ArgsStruct = Struct<
+ Member<String, "file">
+>;
+
+using ArgsTuple = Tuple<
+ Int32,
+ String
+>;
+}
+
+SAW_TEST("Codec Args Decode"){
+ using namespace saw;
+
+ using Schema = sch::Args<sch::ArgsStruct, sch::ArgsTuple>;
+
+ std::array<std::string, 5> foo {
+ "example",
+ "5",
+ "--file",
+ "./foo.bar",
+ "ex"
+ };
+ std::array<char*,5> bar;
+ for(uint64_t i = 0; i < bar.size(); ++i){
+ bar[i] = &foo[i][0];
+ }
+
+ data<sch::Args<sch::ArgsStruct, sch::ArgsTuple>,encode::Args> dat_args{
+ &bar[0],5
+ };
+ data<sch::Args<sch::ArgsStruct, sch::ArgsTuple>> dat_nat;
+
+ codec<sch::Args<sch::ArgsStruct, sch::ArgsTuple>, encode::Args> args_codec;
+
+ auto eov = args_codec.decode(dat_args, dat_nat);
+ SAW_EXPECT(eov.is_value(), "Couldn't decode data");
+
+ auto& prog = dat_nat.template get<"program">();
+ auto& str = dat_nat.template get<"args">();
+ auto& tup = dat_nat.template get<"positionals">();
+
+ SAW_EXPECT(prog == "example", "Wrong program name");
+ SAW_EXPECT(str.template get<"file">() == "./foo.bar", "Wrong file path parsing");
+ SAW_EXPECT(tup.template get<0>() == data<sch::Int32>{5}, "Wrong number");
+ SAW_EXPECT(tup.template get<1>() == "ex", "Wrong String");
+}
+
+}