1#!/usr/bin/env python3
2#  Copyright 2016 Google Inc. All Rights Reserved.
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8#      http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS-IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15
16from fruit_test_common import *
17
18COMMON_DEFINITIONS = '''
19    #define IN_FRUIT_CPP_FILE 1
20
21    #include "meta/common.h"
22    #include <fruit/impl/meta/list.h>
23    #include <fruit/impl/meta/metaprogramming.h>
24    '''
25
26def test_FoldList():
27    source = '''
28        struct Helper {
29            template <typename CurrentResult, typename N>
30            struct apply {
31                using type = Int<(CurrentResult::value + 1) * N::value>;
32            };
33        };
34
35        int main() {
36            AssertSameType(Id<FoldList(EmptyList, Helper, Int<4>)>, Int<4>);
37            AssertSameType(Id<FoldList(Cons<Int<2>, EmptyList>, Helper, Int<4>)>, Int<10>);
38            AssertSameType(Id<FoldList(Cons<Int<3>, Cons<Int<2>, EmptyList>>, Helper, Int<4>)>, Int<32>);
39        }
40        '''
41    expect_success(
42        COMMON_DEFINITIONS,
43        source,
44        locals())
45
46if __name__== '__main__':
47    main(__file__)
48