Support dot notation on PYSON Eval
issue8528 review287841003
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
* Support dot notation on PYSON Eval
|
||||
* Manage sequence
|
||||
* Add drag and drop on tree views
|
||||
* Support expand on column
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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', '>', '=']),
|
||||
|
||||
Reference in New Issue
Block a user