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 absl.testing import parameterized 17from fruit_test_common import * 18 19COMMON_DEFINITIONS = ''' 20 #define IN_FRUIT_CPP_FILE 1 21 22 #include "meta/common.h" 23 #include <fruit/impl/meta/list.h> 24 #include <fruit/impl/meta/metaprogramming.h> 25 ''' 26 27class TestList(parameterized.TestCase): 28 def test_FoldList(self): 29 source = ''' 30 struct Helper { 31 template <typename CurrentResult, typename N> 32 struct apply { 33 using type = Int<(CurrentResult::value + 1) * N::value>; 34 }; 35 }; 36 37 int main() { 38 AssertSameType(Id<FoldList(EmptyList, Helper, Int<4>)>, Int<4>); 39 AssertSameType(Id<FoldList(Cons<Int<2>, EmptyList>, Helper, Int<4>)>, Int<10>); 40 AssertSameType(Id<FoldList(Cons<Int<3>, Cons<Int<2>, EmptyList>>, Helper, Int<4>)>, Int<32>); 41 } 42 ''' 43 expect_success( 44 COMMON_DEFINITIONS, 45 source, 46 locals()) 47 48if __name__ == '__main__': 49 absltest.main() 50