예제 #1
0
        public void AsyncAwaitClassification()
        {
            var code = @"
await f
await + f
async with f: pass
async for x in f: pass

async def f():
    await f
    async with f: pass
    async for x in f: pass

class F:
    async def f(self): pass

";

            using (var helper = new ClassifierHelper(code, PythonLanguageVersion.V35)) {
                helper.CheckAstClassifierSpans("ii i+i iki:k ikiki:k iki(): ii iki:k ikiki:k ki: iki(i): k");

                helper.Analyze();

                // "await f" does not highlight "f", but "await + f" does
                helper.CheckAnalysisClassifierSpans("fff k<async>f k<await>f k<async>f k<async>f c<F> k<async>fp");
            }
        }
예제 #2
0
        public void ParameterAnnotationClassification()
        {
            var code = @"class A: pass
class B: pass

def f(a = A, b : B):
    pass
";

            using (var helper = new ClassifierHelper(code, PythonLanguageVersion.V27)) {
                helper.CheckAstClassifierSpans("ki:k ki:k ki(i=i,i:i): k");

                helper.Analyze();

                helper.CheckAnalysisClassifierSpans("c<A>c<B>f<f>pc<A>pc<B>");
            }
        }
        public void ImportClassifications()
        {
            var code = @"import abc as x
from os import fdopen

abc
x
os
fdopen
";

            using (var helper = new ClassifierHelper(MockTextBuffer(code), PythonLanguageVersion.V27)) {
                helper.CheckAstClassifierSpans("kiki kiki i i i i");

                helper.Analyze();

                helper.CheckAnalysisClassifierSpans("m<abc>m<x>m<os>m<x>");
            }
        }
        public void ModuleClassification()
        {
            var code = @"import abc
import os
import ntpath

os.path = ntpath
abc = 123
abc = True
";

            using (var helper = new ClassifierHelper(MockTextBuffer(code), PythonLanguageVersion.V27)) {
                helper.CheckAstClassifierSpans("ki ki ki i.i=i i=n i=b");

                helper.Analyze();

                helper.CheckAnalysisClassifierSpans("m<abc>m<os>m<ntpath>m<os>m<ntpath>m<abc>m<abc>");
            }
        }
        public void ParameterClassification()
        {
            var code = @"def f(a, b, c):
    a = b
    b = c
    return a

f(a, b, c)
a = b
b = c
";

            using (var helper = new ClassifierHelper(MockTextBuffer(code), PythonLanguageVersion.V27)) {
                helper.CheckAstClassifierSpans("ki(i,i,i): i=i i=i ki i(i,i,i) i=i i=i");

                helper.Analyze();

                helper.CheckAnalysisClassifierSpans("f<f>ppppppppf<f>");
            }
        }
        public void TypeClassification()
        {
            var code = @"class MyClass(object):
    pass

mc = MyClass()
MyClassAlias = MyClass
mca = MyClassAlias()
MyClassType = type(mc)
";

            using (var helper = new ClassifierHelper(MockTextBuffer(code), PythonLanguageVersion.V27)) {
                helper.CheckAstClassifierSpans("ki(i): k i=i() i=i i=i() i=i(i)");
                helper.AnalysisClassifierSpans.ToArray();

                helper.Analyze();

                helper.CheckAnalysisClassifierSpans("c<MyClass>c<object>cc<MyClassAlias>ccc<type>");
            }
        }