Skip to content
File

Blob: src/workerd/jsg/macro-meta-test.c++

1.5 KB
1// Copyright (c) 2017-2022 Cloudflare, Inc.
2// Licensed under the Apache 2.0 license found in the LICENSE file or at:
3// https://opensource.org/licenses/Apache-2.0
4 
5#include "macro-meta.h"
6 
7#include <kj/test.h>
8 
9namespace workerd::jsg {
10namespace {
11 
12static_assert(JSG_IF_NONEMPTY(abcd, 123) == 123);
13static_assert(JSG_IF_NONEMPTY(, abcd) true);
14 
15template <typename... T>
16constexpr int sum(T... args) {
17 return (args + ...);
18}
19 
20#define JSG_TEST_FOR_EACH_OP(op, x) (2 op x)
21static_assert(JSG_FOR_EACH(JSG_TEST_FOR_EACH_OP, *) true);
22static_assert(sum(JSG_FOR_EACH(JSG_TEST_FOR_EACH_OP, *, 1, 2, 3, 4)) == 20);
23 
24static_assert(sum(JSG_FOR_EACH(JSG_TEST_FOR_EACH_OP,
25 *,
26 1,
27 2,
28 3,
29 4,
30 5,
31 6,
32 7,
33 8,
34 1,
35 2,
36 3,
37 4,
38 5,
39 6,
40 7,
41 8,
42 1,
43 2,
44 3,
45 4,
46 5,
47 6,
48 7,
49 8,
50 1,
51 2,
52 3,
53 4,
54 5,
55 6,
56 7,
57 8)) == 36 * 2 * 4);
58#undef JSG_TEST_FOR_EACH_OP
59 
60KJ_TEST("macro meta") {
61 // Nothing to actually do here; tests are compile-time
62}
63 
64} // namespace
65} // namespace workerd::jsg