Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Avatar for KuCalc : devops.
Download
50655 views
1
###
2
Test completion API
3
###
4
5
expect = require('expect')
6
7
common = require('./common')
8
9
# global kernel being tested at any point.
10
kernel = undefined
11
12
# This checks that on input the given obj={code:?, cursor_pos:?}
13
# the resulting matches *contains* matches
14
check = (obj, matches) ->
15
it "checks that #{JSON.stringify(obj)} includes #{if matches then JSON.stringify(matches) else 'nothing'}", (done) ->
16
kernel.complete
17
code : obj.code
18
cursor_pos : obj.cursor_pos ? obj.code.length
19
cb : (err, resp) ->
20
if err
21
done(err)
22
else
23
if not matches?
24
expect(resp.matches.length).toBe(0)
25
else
26
for m in matches
27
expect(resp.matches).toContain(m)
28
done()
29
30
31
32
describe "complete some things using python2 kernel -- ", ->
33
@timeout(10000)
34
35
it 'creates a python2 kernel', ->
36
kernel = common.kernel('python2')
37
38
it "complete 'imp'", (done) ->
39
kernel.complete
40
code : 'imp'
41
cursor_pos : 2
42
cb : (err, resp) ->
43
if err
44
done(err)
45
else
46
expect(resp).toEqual({matches: [ 'import' ], status: 'ok', cursor_start: 0, cursor_end: 2 })
47
done()
48
49
check({code:'imp'}, ['import'])
50
check({code:'in'}, [ 'in', 'input', 'int', 'intern' ])
51
check({code:'in', cursor_pos:1}, [ 'id', 'if', 'import', 'in', 'input', 'int', 'intern', 'is', 'isinstance', 'issubclass', 'iter' ])
52
53
check({code:"alsdfl"})
54
55
it 'creates a new identifier', (done) ->
56
kernel.execute_code
57
code : 'alsdfl = {"foo":"bar"}'
58
all : true
59
cb : done
60
61
check({code:"alsdfl"}, ['alsdfl'])
62
63
check({code:"alsdfl._"}, ['alsdfl.__class__', 'alsdfl.__cmp__'])
64
65
it 'closes the kernel', ->
66
kernel.close()
67
68
69
describe "complete some things using sage kernel -- ", ->
70
@timeout(30000)
71
72
it 'creates a sage kernel', ->
73
kernel = common.kernel('sagemath')
74
75
check({code:'Ell'}, ['Ellipsis', 'EllipticCurve', 'EllipticCurve_from_c4c6', 'EllipticCurve_from_cubic', 'EllipticCurve_from_j', 'EllipticCurve_from_plane_curve', 'EllipticCurveIsogeny', 'EllipticCurves_with_good_reduction_outside_S' ])
76
77
check({code:'e.'}, ['e.abs', 'e.add', 'e.add_to_both_sides', 'e.additive_order', 'e.arccos'])
78
check({code:'e.fac'}, ['e.factor'])
79
80
it 'closes the kernel', ->
81
kernel.close()
82
83
84
85
86