Skip to content

Commit

Permalink
Update/expand tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Time0o committed Dec 27, 2021
1 parent f8991a0 commit eb42d99
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 25 deletions.
22 changes: 13 additions & 9 deletions tests/run_test
Original file line number Diff line number Diff line change
Expand Up @@ -13,28 +13,32 @@ TEST_CASES = {
(['-a=1', '-b=2'], '3')
],
'flag': [
([], 'flag_a = 0, flag_b = 0'),
(['--flag_a'], 'flag_a = 1, flag_b = 0'),
(['--flag_b'], 'flag_a = 0, flag_b = 1'),
(['--flag_a', '--flag_b'], 'flag_a = 1, flag_b = 1')
([], '0'),
(['-f'], '1')
],
'default': [
'default_arg': [
([], '0'),
(['--def=1'], '1')
(['-d=1'], '1')
],
'optional': [
([], 'opt = nothing'),
(['--opt=1'], 'opt = 1')
],
'variadic': [
([], 'variadic = {}'),
(['1'], 'variadic = {1}'),
(['1', '2'], 'variadic = {1, 2}'),
(['1', '2', '3'], 'variadic = {1, 2, 3}')
],
'class': [
(['hello', '--msg', 'hello world'], 'hello world'),
(['add', '-a=1', '-b=2'], '3'),
(['sub', '-a=1', '-b=2'], '-1')
(['flag'], '0'),
(['flag', '-f'], '1'),
(['default_arg'], '0'),
(['default_arg', '-d=1'], '1'),
(['optional'], 'opt = nothing'),
(['optional', '--opt=1'], 'opt = 1'),
(['variadic'], 'variadic = {}'),
(['variadic', '1', '2', '3'], 'variadic = {1, 2, 3}')
]
}

Expand Down
6 changes: 2 additions & 4 deletions tests/test_add.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
#include <fire-llvm/fire.hpp>

#include <iostream>

namespace {

int fire_main_add(int a, int b)
int add(int a, int b)
{
return a + b;
}
Expand All @@ -13,5 +11,5 @@ int fire_main_add(int a, int b)

int main()
{
fire::fire_llvm(fire_main_add);
fire::fire_llvm(add);
}
57 changes: 57 additions & 0 deletions tests/test_class.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#include <fire-llvm/fire.hpp>

#include <iostream>
#include <optional>
#include <string>
#include <vector>

struct S
{
std::string hello(std::string const &msg)
{
return msg;
}

int add(int a, int b)
{
return a + b;
}

bool flag(bool f)
{
return f;
}

int default_arg(int d = 0)
{
return d;
}

void optional(std::optional<int> opt)
{
if (opt)
std::cout << "opt = " << opt.value() << std::endl;
else
std::cout << "opt = nothing" << std::endl;
}

void variadic(std::vector<int> const &variadic)
{
std::cout << "variadic = {";

if (!variadic.empty()) {
std::cout << variadic[0];
for (std::size_t i = 1; i < variadic.size(); ++i)
std::cout << ", " << variadic[i];
}

std::cout << "}";
}
};

S s;

int main()
{
fire::fire_llvm(s);
}
8 changes: 3 additions & 5 deletions tests/test_default_arg.cpp
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
#include <fire-llvm/fire.hpp>

#include <iostream>

namespace {

int fire_main_default(int def = 0)
int default_arg(int d = 0)
{
return def;
return d;
}

}

int main()
{
fire::fire_llvm(fire_main_default);
fire::fire_llvm(default_arg);
}
8 changes: 3 additions & 5 deletions tests/test_flag.cpp
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
#include <fire-llvm/fire.hpp>

#include <iostream>

namespace {

void fire_main_flag(bool flag_a, bool flag_b)
bool flag(bool f)
{
std::cout << "flag_a = " << flag_a << ", flag_b = " << flag_b << std::endl;
return f;
}

}

int main()
{
fire::fire_llvm(fire_main_flag);
fire::fire_llvm(flag);
}
4 changes: 2 additions & 2 deletions tests/test_hello.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

namespace {

void fire_main_hello(std::string const &msg)
std::string fire_main_hello(std::string const &msg)
{
std::cout << msg << std::endl;
return msg;
}

}
Expand Down

0 comments on commit eb42d99

Please sign in to comment.