File: test_templates.py

package info (click to toggle)
pygccxml 3.0.2-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 8,444 kB
  • sloc: xml: 29,841; python: 13,914; cpp: 2,671; makefile: 163; ansic: 59
file content (75 lines) | stat: -rw-r--r-- 2,382 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# Copyright 2014-2017 Insight Software Consortium.
# Copyright 2004-2009 Roman Yakovenko.
# Distributed under the Boost Software License, Version 1.0.
# See http://www.boost.org/LICENSE_1_0.txt

from pygccxml import declarations


def __test_split_impl(decl_string, name, args):
    assert (name, args) == \
        declarations.templates.split(decl_string)


def __test_split_recursive_impl(decl_string, control_seq):
    assert control_seq == \
        list(declarations.templates.split_recursive(decl_string))


def __test_is_template_impl(decl_string):
    assert declarations.templates.is_instantiation(decl_string)


def test_split_on_vector():
    __test_is_template_impl("vector<int, std::allocator<int>>")

    __test_split_impl(
        "vector<int, std::allocator<int>>",
        "vector",
        ["int", "std::allocator<int>"])

    __test_split_recursive_impl(
        "vector<int, std::allocator<int>>",
        [("vector", ["int", "std::allocator<int>"]),
            ("std::allocator", ["int"])])


def test_split_on_string():
    __test_is_template_impl(
        "basic_string<char, std::char_traits<char>, std::allocator<char>>")

    __test_split_impl(
        "basic_string<char, std::char_traits<char>, std::allocator<char>>",
        "basic_string",
        ["char",
            "std::char_traits<char>",
            "std::allocator<char>"])


def test_split_on_map():
    __test_is_template_impl(
        "map<long int,std::vector<int, std::allocator<int>>," +
        "std::less<long int>, std::allocator<std::pair<const long int, " +
        "std::vector<int, std::allocator<int>>>>>")

    __test_split_impl(
        "map<long int,std::vector<int, std::allocator<int>>," +
        "std::less<long int>, std::allocator<std::pair<const long int, " +
        "std::vector<int, std::allocator<int>>>>>",
        "map",
        ["long int",
            "std::vector<int, std::allocator<int>>",
            "std::less<long int>",
            "std::allocator<std::pair<const long int, " +
            "std::vector<int, std::allocator<int>>>>"])


def test_join_on_vector():
    assert "vector<int, std::allocator<int>>" == \
        declarations.templates.join(
            "vector", ("int", "std::allocator<int>"))


def test_bug_is_tmpl_inst():
    assert declarations.templates.is_instantiation(
        "::FX::QMemArray<unsigned char>::setRawData") is False