diff --git a/CHANGELOG b/CHANGELOG index 0c92a4fd3b..292be0c9f8 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,4 @@ +* Support dot notation on PYSON Eval * Manage sequence * Add drag and drop on tree views * Support expand on column diff --git a/src/pyson.js b/src/pyson.js index ed4a7c3393..ab716ffae1 100644 --- a/src/pyson.js +++ b/src/pyson.js @@ -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 { diff --git a/tests/sao.js b/tests/sao.js index 5d0e44f287..77c32fcd9f 100644 --- a/tests/sao.js +++ b/tests/sao.js @@ -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', '>', '=']),