Support dot notation on PYSON Eval

issue8528
review287841003
This commit is contained in:
Sergi Almacellas Abellana
2019-09-19 14:11:30 +02:00
parent 3b2e1165e3
commit e0d7f0e933
3 changed files with 40 additions and 0 deletions
+1
View File
@@ -1,3 +1,4 @@
* Support dot notation on PYSON Eval
* Manage sequence
* Add drag and drop on tree views
* Support expand on column
+7
View File
@@ -149,6 +149,13 @@
});
Sao.PYSON.Eval.eval_ = function(value, context) {
var idx = value.v.indexOf('.');
if (idx >= 0) {
return Sao.PYSON.Eval.eval_({
'v': value.v.substring(idx + 1),
'd': value.d,
}, context[value.v.substring(0, idx)] || {});
}
if (value.v in context) {
return context[value.v];
} else {
+32
View File
@@ -989,6 +989,38 @@
'{"test": ["foo", "bar"], "pyson": Eval("test", "")}');
});
QUnit.test('PYSON.Eval dot notation', function() {
var eval_;
eval_ = new Sao.PYSON.Encoder().encode(
new Sao.PYSON.Eval('foo.bar', 0));
[[{'foo': {'bar': 1}}, 1],
[{'foo': {'foo': 1}}, 0],
[{'bar': {'bar': 1}}, 0],
].forEach(function(params){
var ctx = params[0];
var result = params[1];
QUnit.strictEqual(
new Sao.PYSON.Decoder(ctx).decode(eval_), result,
"decode(" + JSON.stringify(ctx) + ")");
});
});
QUnit.test('PYSON.Eval dot notation nested', function() {
var eval_;
eval_ = new Sao.PYSON.Encoder().encode(
new Sao.PYSON.Eval('foo.bar.test', 0));
[[{'foo': {'bar': {'test': 1}}}, 1],
[{'foo': {'foo': 1}}, 0],
[{'bar': {'bar': 1}}, 0],
].forEach(function(params){
var ctx = params[0];
var result = params[1];
QUnit.strictEqual(
new Sao.PYSON.Decoder(ctx).decode(eval_), result,
"decode(" + JSON.stringify(ctx) + ")");
});
});
QUnit.test('DomainParser.group_operator', function() {
var parser = new Sao.common.DomainParser();
QUnit.ok(Sao.common.compare(parser.group_operator(['a', '>', '=']),