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/graph.h> 24 25 struct A1 {}; 26 struct B1 {}; 27 struct C1 {}; 28 struct D1 {}; 29 struct E1 {}; 30 31 using A = Type<A1>; 32 using B = Type<B1>; 33 using C = Type<C1>; 34 using D = Type<D1>; 35 using E = Type<E1>; 36 ''' 37 38class TestGraph(parameterized.TestCase): 39 def test_GraphFindLoop(self): 40 source = ''' 41 int main() { 42 // A -> B, D 43 // C -> D 44 AssertSameType(Id<GraphFindLoop(Vector<Pair<A, Vector<B, D>>, Pair<C, Vector<D>>, Pair<B, Vector<>>>)>, None); 45 46 // A -> B 47 // B -> B 48 // C -> B 49 AssertSameType(Id<GraphFindLoop(Vector<Pair<A, Vector<B>>, Pair<B, Vector<B>>, Pair<C, Vector<B>>>)>, Vector<B>); 50 51 // A -> D, B 52 // B -> C 53 // C -> A 54 // The order in the result here *does* matter, but rotations of the correct (A,B,C) sequence are also ok. 55 // Fix this test as appropriate. 56 AssertSameType(Id<GraphFindLoop(Vector<Pair<A, Vector<D, B>>, Pair<B, Vector<C>>, Pair<C, Vector<A>>>)>, Vector<B, C, A>); 57 } 58 ''' 59 expect_success( 60 COMMON_DEFINITIONS, 61 source, 62 locals()) 63 64if __name__ == '__main__': 65 absltest.main() 66