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): [x async for x in y] @F async def f(): pass "; using (var helper = new ClassifierHelper(code, PythonLanguageVersion.V36)) { helper.CheckAstClassifierSpans("ii i+i iki:k ikiki:k iki(): ii iki:k ikiki:k ki: " + "iki(i): (iikiki) @iiki():k"); // "await f" does not highlight "f", but "await + f" does // also note that only async and await are keywords here - not 'for' helper.CheckAnalysisClassifierSpans("fff k<async>f k<await>f k<async>f k<async>f c<F> " + "k<async>fp<self>p<x>k<async>p c<F>k<async>f"); } }
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 @F async def f(): 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 @iiki():k"); // "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 c<F>k<async>f"); } }
public void DocStringClassifications() { var code = @"def f(): '''doc string''' '''not a doc string''' "; using (var helper = new ClassifierHelper(code, PythonLanguageVersion.V35)) { helper.CheckAstClassifierSpans("ki():ss"); helper.CheckAnalysisClassifierSpans("f<f>d<'''doc string'''>"); } }
public void MultilineStringClassification() { var code = @"t = '''a b ''' + c + 'x' + '''d e'''"; using (var helper = new ClassifierHelper(code, PythonLanguageVersion.V27)) { helper.CheckAstClassifierSpans("i=sss+i+s+sss"); } }
public void TrueFalseClassification() { var code = "True False"; using (var helper = new ClassifierHelper(code, PythonLanguageVersion.V27)) { helper.CheckAstClassifierSpans("b<True> b<False>"); } using (var helper = new ClassifierHelper(code, PythonLanguageVersion.V33)) { helper.CheckAstClassifierSpans("k<True> k<False>"); } }
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.CheckAnalysisClassifierSpans("c<A>c<B>f<f>pc<A>pc<B>"); } }
public void ModuleClassification() { var code = @"import abc import os import ntpath os.path = ntpath abc = 123 abc = True "; using (var helper = new ClassifierHelper(code, PythonLanguageVersion.V27)) { helper.CheckAstClassifierSpans("ki ki ki i.i=i i=n i=b"); helper.CheckAnalysisClassifierSpans("m<abc>m<os>m<ntpath>m<os>m<ntpath>m<abc>m<abc>"); } }
public void ImportClassifications() { var code = @"import abc as x from os import fdopen abc x os fdopen "; using (var helper = new ClassifierHelper(code, PythonLanguageVersion.V27)) { helper.CheckAstClassifierSpans("kiki kiki i i i i"); helper.CheckAnalysisClassifierSpans("m<abc>m<x>m<os>m<x>"); } }
public void TypeClassification() { var code = @"class MyClass(object): pass mc = MyClass() MyClassAlias = MyClass mca = MyClassAlias() MyClassType = type(mc) "; using (var helper = new ClassifierHelper(code, PythonLanguageVersion.V27)) { helper.CheckAstClassifierSpans("ki(i): k i=i() i=i i=i() i=i(i)"); helper.CheckAnalysisClassifierSpans("c<MyClass>c<object>cc<MyClassAlias>ccc<type>"); } }
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(code, PythonLanguageVersion.V27)) { helper.CheckAstClassifierSpans("ki(i,i,i): i=i i=i ki i(i,i,i) i=i i=i"); helper.CheckAnalysisClassifierSpans("f<f>ppppppppf<f>"); } }
public void ImportClassifications() { // We import a name that is not in os, because otherwise // its classification may depend on the current DB for the // module. var code = @"import abc as x from os import name_not_in_os abc x os name_not_in_os "; using (var helper = new ClassifierHelper(code, PythonLanguageVersion.V27)) { helper.CheckAstClassifierSpans("kiki kiki i i i i"); helper.CheckAnalysisClassifierSpans("m<abc>m<x>m<os>m<x>"); } }
public void RegexClassifications() { var code = @"import re as R R.compile('pattern', 'str') R.escape('pattern', 'str') R.findall('pattern', 'str') R.finditer('pattern', 'str') R.fullmatch('pattern', 'str') R.match('pattern', 'str') R.search('pattern', 'str') R.split('pattern', 'str') R.sub('pattern', 'str') R.subn('pattern', 'str') "; using (var helper = new ClassifierHelper(code, PythonLanguageVersion.V35)) { helper.CheckAstClassifierSpans("kiki " + string.Join(" ", Enumerable.Repeat("i.i(s,s)", 10))); helper.CheckAnalysisClassifierSpans("m<re>m<R> " + string.Join(" ", Enumerable.Repeat("m<R>fr", 10))); } }
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(code, PythonLanguageVersion.V27)) { helper.CheckAstClassifierSpans("ki(i,i,i): i=i i=i ki i(i,i,i) i=i i=i"); helper.CheckAnalysisClassifierSpans("f<f>ppppppppf<f>"); } }
public void ImportClassifications() { var code = @"import abc as x from os import fdopen abc x os fdopen "; using (var helper = new ClassifierHelper(code, PythonLanguageVersion.V27)) { helper.CheckAstClassifierSpans("kiki kiki i i i i"); helper.CheckAnalysisClassifierSpans("m<abc>m<x>m<os>m<x>"); } }
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.CheckAnalysisClassifierSpans("c<A>c<B>f<f>pc<A>pc<B>"); } }
public void TrueFalseClassification() { var code = "True False"; using (var helper = new ClassifierHelper(code, PythonLanguageVersion.V27)) { helper.CheckAstClassifierSpans("b<True> b<False>"); } using (var helper = new ClassifierHelper(code, PythonLanguageVersion.V33)) { helper.CheckAstClassifierSpans("k<True> k<False>"); } }
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"); // "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"); } }
public void ModuleClassification() { var code = @"import abc import os import ntpath os.path = ntpath abc = 123 abc = True "; using (var helper = new ClassifierHelper(code, PythonLanguageVersion.V27)) { helper.CheckAstClassifierSpans("ki ki ki i.i=i i=n i=b"); helper.CheckAnalysisClassifierSpans("m<abc>m<os>m<ntpath>m<os>m<ntpath>m<abc>m<abc>"); } }
public void TypeClassification() { var code = @"class MyClass(object): pass mc = MyClass() MyClassAlias = MyClass mca = MyClassAlias() MyClassType = type(mc) "; using (var helper = new ClassifierHelper(code, PythonLanguageVersion.V27)) { helper.CheckAstClassifierSpans("ki(i): k i=i() i=i i=i() i=i(i)"); helper.CheckAnalysisClassifierSpans("c<MyClass>c<object>cc<MyClassAlias>ccc<type>"); } }