Fix #includes
[folly.git] / folly / wangle / test / thens.rb
1 #!/usr/bin/env ruby
2
3 # An exercise in combinatorics.
4 # (ordinary/static function, member function, std::function, lambda)
5 # X
6 # returns (Future<R>, R)
7 # X
8 # accepts (Try<T>&&, Try<T> const&, Try<T>, T&&, T const&, T, nothing)
9
10 def test(*args)
11   args = args.join(", ")
12   [
13   "{Future<B> f = someFuture<A>().then(#{args});}",
14   #"{Future<B> f = makeFuture(A()).then(#{args}, anExecutor);}",
15   ]
16 end
17
18 def retval(ret)
19   {
20     "Future<B>" => "someFuture<B>()",
21     "Try<B>" => "Try<B>(B())",
22     "B" => "B()"
23   }[ret]
24 end
25
26 return_types = [
27   "Future<B>",
28   "B",
29   #"Try<B>",
30 ]
31 param_types = [
32     "Try<A>&&",
33     #"Try<A> const&",
34     #"Try<A>",
35     #"Try<A>&",
36     #"A&&",
37     #"A const&",
38     #"A",
39     #"A&",
40     #"",
41   ]
42
43 tests = (
44   return_types.map { |ret|
45     param_types.map { |param|
46       both = "#{ret}, #{param}"
47       [
48         ["aFunction<#{both}>"],
49         ["&SomeClass::aStaticMethod<#{both}>"],
50         # TODO switch these around (std::bind-style)
51         ["&anObject", "&SomeClass::aMethod<#{both}>"],
52         ["aStdFunction<#{both}>()"],
53         ["[&](#{param}){return #{retval(ret)};}"],
54       ]
55     }
56   }.flatten(2) + [
57     #[""],
58   ]
59 ).map {|a| test(a)}.flatten
60
61 print <<EOF
62 // This file is #{"@"}generated by thens.rb
63
64 #include <folly/wangle/test/Thens.h>
65
66 TEST(Future, thenVariants) {
67   SomeClass anObject;
68   Executor* anExecutor;
69
70   #{tests.join("\n  ")}
71 }
72 EOF