• 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/vector.h>
23    #include <fruit/impl/meta/metaprogramming.h>
24
25    struct A1 {};
26    struct B1 {};
27    struct C1 {};
28
29    using A = A1;
30    using B = B1;
31    using C = C1;
32    '''
33
34def test_IsInVector():
35    source = '''
36        int main() {
37            AssertNot(IsInVector(A, Vector<>));
38            AssertNot(IsInVector(A, Vector<B>));
39            Assert(IsInVector(A, Vector<A>));
40        }
41        '''
42    expect_success(
43        COMMON_DEFINITIONS,
44        source,
45        locals())
46
47def test_IsSameVector():
48    source = '''
49        int main() {
50            AssertNotSameType(Vector<A, B>, Vector<B, A>);
51            AssertNotSameType(Vector<A>, Vector<>);
52            AssertNotSameType(Vector<>, Vector<A>);
53        }
54        '''
55    expect_success(
56        COMMON_DEFINITIONS,
57        source,
58        locals())
59
60def test_VectorSize():
61    source = '''
62        int main() {
63            AssertSameType(Id<VectorSize(Vector<>)>, Int<0>);
64            AssertSameType(Id<VectorSize(Vector<A>)>, Int<1>);
65            AssertSameType(Id<VectorSize(Vector<A, B>)>, Int<2>);
66        }
67        '''
68    expect_success(
69        COMMON_DEFINITIONS,
70        source,
71        locals())
72
73def test_ConcatVectors():
74    source = '''
75        int main() {
76            AssertSameType(Id<ConcatVectors(Vector<>, Vector<>)>, Vector<>);
77            AssertSameType(Id<ConcatVectors(Vector<>, Vector<A, B>)>, Vector<A, B>);
78            AssertSameType(Id<ConcatVectors(Vector<A, B>, Vector<>)>, Vector<A, B>);
79            AssertSameType(Id<ConcatVectors(Vector<A>, Vector<A, B>)>, Vector<A, A, B>);
80            AssertSameType(Id<ConcatVectors(Vector<A, B>, Vector<A, C>)>, Vector<A, B, A, C>);
81        }
82        '''
83    expect_success(
84        COMMON_DEFINITIONS,
85        source,
86        locals())
87
88def test_VectorEndsWith():
89    source = '''
90        int main() {
91            Assert(VectorEndsWith(Vector<A, B>, B));
92            AssertNot(VectorEndsWith(Vector<A, B>, A));
93            AssertNot(VectorEndsWith(Vector<>, A));
94        }
95        '''
96    expect_success(
97        COMMON_DEFINITIONS,
98        source,
99        locals())
100
101def test_VectorRemoveFirstN():
102    source = '''
103        int main() {
104            AssertSameType(Id<VectorRemoveFirstN(Vector<>, Int<0>)>, Vector<>);
105            AssertSameType(Id<VectorRemoveFirstN(Vector<A>, Int<0>)>, Vector<A>);
106            AssertSameType(Id<VectorRemoveFirstN(Vector<A>, Int<1>)>, Vector<>);
107            AssertSameType(Id<VectorRemoveFirstN(Vector<A, B, C>, Int<0>)>, Vector<A, B, C>);
108            AssertSameType(Id<VectorRemoveFirstN(Vector<A, B, C>, Int<1>)>, Vector<B, C>);
109            AssertSameType(Id<VectorRemoveFirstN(Vector<A, B, C>, Int<2>)>, Vector<C>);
110            AssertSameType(Id<VectorRemoveFirstN(Vector<A, B, C>, Int<3>)>, Vector<>);
111        }
112        '''
113    expect_success(
114        COMMON_DEFINITIONS,
115        source,
116        locals())
117
118if __name__== '__main__':
119    main(__file__)
120