summaryrefslogtreecommitdiffstats
path: root/bindings/python/tests
diff options
context:
space:
mode:
authordim <dim@FreeBSD.org>2012-12-02 13:20:44 +0000
committerdim <dim@FreeBSD.org>2012-12-02 13:20:44 +0000
commit056abd2059c65a3e908193aeae16fad98017437c (patch)
tree2732d02d7d51218d6eed98ac7fcfc5b8794896b5 /bindings/python/tests
parentcc73504950eb7b5dff2dded9bedd67bc36d64641 (diff)
downloadFreeBSD-src-056abd2059c65a3e908193aeae16fad98017437c.zip
FreeBSD-src-056abd2059c65a3e908193aeae16fad98017437c.tar.gz
Vendor import of clang release_32 branch r168974 (effectively, 3.2 RC2):
http://llvm.org/svn/llvm-project/cfe/branches/release_32@168974
Diffstat (limited to 'bindings/python/tests')
-rw-r--r--bindings/python/tests/cindex/test_code_completion.py75
-rw-r--r--bindings/python/tests/cindex/test_cursor.py9
2 files changed, 84 insertions, 0 deletions
diff --git a/bindings/python/tests/cindex/test_code_completion.py b/bindings/python/tests/cindex/test_code_completion.py
new file mode 100644
index 0000000..357d50d
--- /dev/null
+++ b/bindings/python/tests/cindex/test_code_completion.py
@@ -0,0 +1,75 @@
+from clang.cindex import TranslationUnit
+
+def check_completion_results(cr, expected):
+ assert cr is not None
+ assert len(cr.diagnostics) == 0
+
+ completions = [str(c) for c in cr.results]
+
+ for c in expected:
+ assert c in completions
+
+def test_code_complete():
+ files = [('fake.c', """
+/// Aaa.
+int test1;
+
+/// Bbb.
+void test2(void);
+
+void f() {
+
+}
+""")]
+
+ tu = TranslationUnit.from_source('fake.c', ['-std=c99'], unsaved_files=files,
+ options=TranslationUnit.PARSE_INCLUDE_BRIEF_COMMENTS_IN_CODE_COMPLETION)
+
+ cr = tu.codeComplete('fake.c', 9, 1, unsaved_files=files, include_brief_comments=True)
+
+ expected = [
+ "{'int', ResultType} | {'test1', TypedText} || Priority: 50 || Availability: Available || Brief comment: Aaa.",
+ "{'void', ResultType} | {'test2', TypedText} | {'(', LeftParen} | {')', RightParen} || Priority: 50 || Availability: Available || Brief comment: Bbb.",
+ "{'return', TypedText} || Priority: 40 || Availability: Available || Brief comment: None"
+ ]
+ check_completion_results(cr, expected)
+
+def test_code_complete_availability():
+ files = [('fake.cpp', """
+class P {
+protected:
+ int member;
+};
+
+class Q : public P {
+public:
+ using P::member;
+};
+
+void f(P x, Q y) {
+ x.; // member is inaccessible
+ y.; // member is accessible
+}
+""")]
+
+ tu = TranslationUnit.from_source('fake.cpp', ['-std=c++98'], unsaved_files=files)
+
+ cr = tu.codeComplete('fake.cpp', 12, 5, unsaved_files=files)
+
+ expected = [
+ "{'const', TypedText} || Priority: 40 || Availability: Available || Brief comment: None",
+ "{'volatile', TypedText} || Priority: 40 || Availability: Available || Brief comment: None",
+ "{'operator', TypedText} || Priority: 40 || Availability: Available || Brief comment: None",
+ "{'P', TypedText} | {'::', Text} || Priority: 75 || Availability: Available || Brief comment: None",
+ "{'Q', TypedText} | {'::', Text} || Priority: 75 || Availability: Available || Brief comment: None"
+ ]
+ check_completion_results(cr, expected)
+
+ cr = tu.codeComplete('fake.cpp', 13, 5, unsaved_files=files)
+ expected = [
+ "{'P', TypedText} | {'::', Text} || Priority: 75 || Availability: Available || Brief comment: None",
+ "{'P &', ResultType} | {'operator=', TypedText} | {'(', LeftParen} | {'const P &', Placeholder} | {')', RightParen} || Priority: 34 || Availability: Available || Brief comment: None",
+ "{'int', ResultType} | {'member', TypedText} || Priority: 35 || Availability: NotAccessible || Brief comment: None",
+ "{'void', ResultType} | {'~P', TypedText} | {'(', LeftParen} | {')', RightParen} || Priority: 34 || Availability: Available || Brief comment: None"
+ ]
+ check_completion_results(cr, expected)
diff --git a/bindings/python/tests/cindex/test_cursor.py b/bindings/python/tests/cindex/test_cursor.py
index 51695e2..edb209b 100644
--- a/bindings/python/tests/cindex/test_cursor.py
+++ b/bindings/python/tests/cindex/test_cursor.py
@@ -241,3 +241,12 @@ def test_get_tokens():
assert len(tokens) == 7
assert tokens[0].spelling == 'int'
assert tokens[1].spelling == 'foo'
+
+def test_get_arguments():
+ tu = get_tu('void foo(int i, int j);')
+ foo = get_cursor(tu, 'foo')
+ arguments = list(foo.get_arguments())
+
+ assert len(arguments) == 2
+ assert arguments[0].spelling == "i"
+ assert arguments[1].spelling == "j"
OpenPOWER on IntegriCloud