Skip to content

Commit 384b2a0

Browse files
committed
Unit test for issue #73 by @Rupsbant
1 parent c540002 commit 384b2a0

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
# Fortran module files
1717
*.mod
18+
*.smod
1819

1920
# Compiled Static libraries
2021
*.lai

code/test/unit/xtl_bug_73.cpp

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
// This unit test is based on Mach7 issue #73 by @Rupsbant
2+
// See https://github.com/solodon4/Mach7/issues/73 for details
3+
4+
#include <stdio.h>
5+
#include <mach7/adapters/boost/adapt_boost_variant.hpp>
6+
#include <mach7/patterns/constructor.hpp>
7+
#include <mach7/patterns/primitive.hpp>
8+
9+
template<int N> struct A {
10+
int val;
11+
A(int a) : val(a) {};
12+
};
13+
struct CC {
14+
boost::variant<A<0>, A<1>, A<2>, A<3>, A<4>, A<5>, A<6>, A<7>, A<8>> variant;
15+
template<typename T> CC(T t) : variant(t) {};
16+
};
17+
namespace mch {
18+
template <int N> struct bindings<A<N>> {
19+
Members(A<N>::val);
20+
};
21+
template <> struct bindings<CC> {
22+
Members(CC::variant);
23+
};
24+
}
25+
int do_some(CC c) {
26+
using namespace mch;
27+
var<int> x;
28+
Match(c.variant) {
29+
Case(C<A<0>>(x)) {
30+
return 0+x;
31+
}
32+
Case(C<A<8>>(x)) {
33+
return 8-x;
34+
}
35+
Otherwise() {
36+
return -1;
37+
break;
38+
}
39+
}
40+
EndMatch;
41+
}
42+
template<int N> int test() {
43+
return do_some(CC(A<N>(5)));
44+
}
45+
int main() {
46+
int result = 0;
47+
if (5 != test<0>()) { ++result; printf("Invalid result of test<0>()\n"); }
48+
if (3 != test<8>()) { ++result; printf("Invalid result of test<8>()\n"); }
49+
return result;
50+
}

0 commit comments

Comments
 (0)