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