1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
#include <forstio/test/suite.hpp>
#include "../c++/args.hpp"
namespace {
namespace sch {
using namespace saw::schema;
using ArgsStruct = Struct<
Member<String, "file">,
Member<String, "oawinu">
>;
using ArgsTuple = Tuple<
Int32,
String
>;
}
SAW_TEST("Codec Args Decode Basic"){
using namespace saw;
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{
5,
&bar[0]
};
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_EOV_EXPECT(eov, "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(str.template get<"oawinu">() == "", "Wrong oawinu dummy value.");
SAW_EXPECT(tup.template get<0>() == data<sch::Int32>{5}, "Wrong number");
SAW_EXPECT(tup.template get<1>() == "ex", "Wrong String");
}
}
|