Skip to content

Commit

Permalink
Unit test for issue #73 by @Rupsbant
Browse files Browse the repository at this point in the history
  • Loading branch information
solodon4 committed Mar 30, 2017
1 parent c540002 commit 384b2a0
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

# Fortran module files
*.mod
*.smod

# Compiled Static libraries
*.lai
Expand Down
50 changes: 50 additions & 0 deletions code/test/unit/xtl_bug_73.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// This unit test is based on Mach7 issue #73 by @Rupsbant
// See https://github.com/solodon4/Mach7/issues/73 for details

#include <stdio.h>
#include <mach7/adapters/boost/adapt_boost_variant.hpp>
#include <mach7/patterns/constructor.hpp>
#include <mach7/patterns/primitive.hpp>

template<int N> struct A {
int val;
A(int a) : val(a) {};
};
struct CC {
boost::variant<A<0>, A<1>, A<2>, A<3>, A<4>, A<5>, A<6>, A<7>, A<8>> variant;
template<typename T> CC(T t) : variant(t) {};
};
namespace mch {
template <int N> struct bindings<A<N>> {
Members(A<N>::val);
};
template <> struct bindings<CC> {
Members(CC::variant);
};
}
int do_some(CC c) {
using namespace mch;
var<int> x;
Match(c.variant) {
Case(C<A<0>>(x)) {
return 0+x;
}
Case(C<A<8>>(x)) {
return 8-x;
}
Otherwise() {
return -1;
break;
}
}
EndMatch;
}
template<int N> int test() {
return do_some(CC(A<N>(5)));
}
int main() {
int result = 0;
if (5 != test<0>()) { ++result; printf("Invalid result of test<0>()\n"); }
if (3 != test<8>()) { ++result; printf("Invalid result of test<8>()\n"); }
return result;
}

0 comments on commit 384b2a0

Please sign in to comment.