-
Notifications
You must be signed in to change notification settings - Fork 788
/
translator-test.js
114 lines (100 loc) · 5.35 KB
/
translator-test.js
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
import assert from 'assert';
import { Graph } from '../../lib/structure/graph.js';
import { order, P, TextP } from '../../lib/process/traversal.js';
import Translator from '../../lib/process/translator.js';
import { statics } from '../../lib/process/graph-traversal.js';
const __ = statics;
describe('Translator', function () {
describe('#translate()', function () {
it('should produce valid script representation from bytecode glv steps', function () {
const g = new Graph().traversal();
const script = new Translator('g').translate(g.V().out('created').getBytecode());
assert.ok(script);
assert.strictEqual(script, 'g.V().out(\'created\')');
});
it('should produce valid script representation from bytecode glv steps translating number and text correctly', function () {
const g = new Graph().traversal();
const script = new Translator('g').translate(g.V(1).out('created').getBytecode());
assert.ok(script);
assert.strictEqual(script, 'g.V(1).out(\'created\')');
});
it('should produce valid script representation from bytecode glv steps containing parameter bindings', function () {
const g = new Graph().traversal();
const script = new Translator('g').translate(g.addV({'name': 'Lilac'}).getBytecode());
assert.ok(script);
assert.strictEqual(script, 'g.addV((\'name\', \'Lilac\'))');
});
it('should produce valid script representation from bytecode glv steps containing enum', function () {
const g = new Graph().traversal();
const script = new Translator('g').translate(g.V().order().by('age', order.shuffle).getBytecode());
assert.ok(script);
assert.strictEqual(script, 'g.V().order().by(\'age\', shuffle)');
});
it('should produce valid script representation from bytecode glv steps containing a predicate', function () {
const g = new Graph().traversal();
const script = new Translator('g').translate(g.V().hasLabel('person').has('age', P.gt(30)).getBytecode());
assert.ok(script);
assert.strictEqual(script, 'g.V().hasLabel(\'person\').has(\'age\', gt(30))');
});
it('should produce valid script representation from bytecode glv steps containing a string predicate', function () {
const g = new Graph().traversal();
const script = new Translator('g').translate(g.V().hasLabel('person').has('name', TextP.containing("foo")).getBytecode());
assert.ok(script);
assert.strictEqual(script, 'g.V().hasLabel(\'person\').has(\'name\', containing(\'foo\'))');
});
it('should produce valid script representation from bytecode glv steps with child', function () {
const g = new Graph().traversal();
const script = new Translator('g').translate(g.V().filter(__.outE('created')).getBytecode());
assert.ok(script);
assert.strictEqual(script, 'g.V().filter(__.outE(\'created\'))');
});
it('should produce valid script representation from bytecode glv steps with embedded child', function () {
const g = new Graph().traversal();
const script = new Translator('g').translate(g.V().filter(__.outE('created').filter(__.has('weight'))).getBytecode());
assert.ok(script);
assert.strictEqual(script, 'g.V().filter(__.outE(\'created\').filter(__.has(\'weight\')))');
});
it('should produce valid script representation from bytecode glv steps with embedded children', function () {
const g = new Graph().traversal();
const script = new Translator('g').translate(g.V().or(__.has('name', 'a'), __.has('name', 'b')).getBytecode());
assert.ok(script);
assert.strictEqual(script, 'g.V().or(__.has(\'name\', \'a\'), __.has(\'name\', \'b\'))');
});
it('should produce valid script representation from bytecode glv for boolean values', function () {
const g = new Graph().traversal();
const script = new Translator('g').translate(g.V().has('male', true).getBytecode());
assert.ok(script);
assert.strictEqual(script, 'g.V().has(\'male\', true)');
});
it('should produce valid script representation from a traversal object', function () {
const g = new Graph().traversal();
const script = new Translator('g').translate(g.V().has('male', true));
assert.ok(script);
assert.strictEqual(script, 'g.V().has(\'male\', true)');
});
it('should produce valid script representation of array as step arg', function () {
const g = new Graph().traversal();
const script = new Translator('g').translate(g.V([1, 2, 3]));
assert.ok(script);
assert.strictEqual(script, 'g.V([1, 2, 3])');
});
});
});