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/vector.h> 24 25 #include <vector> 26 27 struct A {}; 28 struct B {}; 29 struct C {}; 30 31 struct Select1st { 32 template <typename T, typename U> 33 struct apply { 34 using type = T; 35 }; 36 }; 37 38 struct Select2nd { 39 template <typename T, typename U> 40 struct apply { 41 using type = U; 42 }; 43 }; 44 ''' 45 46class TestBasics(parameterized.TestCase): 47 def test_ImplicitCall(self): 48 source = ''' 49 int main() { 50 AssertSameType(Type<int>, Id<Select1st(Type<int>, Type<float>)>); 51 AssertSameType(Type<float>, Id<Select2nd(Type<int>, Type<float>)>); 52 AssertSameType(Type<int>, Id<Select1st(Type<int>, Type<float>)>); 53 AssertSameType(Type<float>, Id<Select2nd(Type<int>, Type<float>)>); 54 } 55 ''' 56 expect_success( 57 COMMON_DEFINITIONS, 58 source, 59 locals()) 60 61 def test_Call(self): 62 source = ''' 63 int main() { 64 AssertSameType(Type<int>, Id<Call(Select1st, Type<int>, Type<float>)>); 65 AssertSameType(Type<float>, Id<Call(Select2nd, Type<int>, Type<float>)>); 66 AssertSameType(Type<int>, Id<Call(Select1st, Type<int>, Type<float>)>); 67 AssertSameType(Type<float>, Id<Call(Select2nd, Type<int>, Type<float>)>); 68 } 69 ''' 70 expect_success( 71 COMMON_DEFINITIONS, 72 source, 73 locals()) 74 75 def test_DeferArgs(self): 76 source = ''' 77 int main() { 78 AssertSameType(Type<int>, Id<Call(Id<Call(Id<DeferArgs(Select1st)>, Type<int>)>, Type<float>)>); 79 AssertSameType(Type<float>, Id<Call(Id<Call(Id<DeferArgs(Select2nd)>, Type<int>)>, Type<float>)>); 80 AssertSameType(Type<int>, Id<Call(Id<Call(Id<DeferArgs(Select1st)>, Type<int>)>, Type<float>)>); 81 AssertSameType(Type<float>, Id<Call(Id<Call(Id<DeferArgs(Select2nd)>, Type<int>)>, Type<float>)>); 82 } 83 ''' 84 expect_success( 85 COMMON_DEFINITIONS, 86 source, 87 locals()) 88 89if __name__ == '__main__': 90 absltest.main() 91