Use PYSON's Bool evaluation for PYSON's Not evaluation
Closes #13096 (grafted from 009133813b11f264b5e038dc9c5912dc9e0101cb) --HG-- branch : 6.0
This commit is contained in:
1 parent
319527ea43
commit
1ffdad78ce
5 files changed
+35
-3
No files matched your search
+1
-1
@@ -220,7 +220,7 @@
|
||||
});
|
||||
|
||||
Sao.PYSON.Not.eval_ = function(value, context) {
|
||||
return !value.v;
|
||||
return !Sao.PYSON.Bool.eval_(value, context);
|
||||
};
|
||||
Sao.PYSON.Not.init_from_object = function(obj) {
|
||||
return new Sao.PYSON.Not(obj.v);
|
||||
|
||||
@@ -124,6 +124,24 @@
|
||||
'decode(Not(false))');
|
||||
QUnit.strictEqual(new Sao.PYSON.Not(true).toString(),
|
||||
"Not(true)");
|
||||
|
||||
eval_ = new Sao.PYSON.Encoder().encode(new Sao.PYSON.Not({}));
|
||||
QUnit.strictEqual(new Sao.PYSON.Decoder().decode(eval_), true,
|
||||
"decode(Not({}))");
|
||||
|
||||
eval_ = new Sao.PYSON.Encoder().encode(new Sao.PYSON.Not({
|
||||
'a': 1,
|
||||
}));
|
||||
QUnit.strictEqual(new Sao.PYSON.Decoder().decode(eval_), false,
|
||||
"decode(Not({'a': 1}))");
|
||||
|
||||
eval_ = new Sao.PYSON.Encoder().encode(new Sao.PYSON.Not([]));
|
||||
QUnit.strictEqual(new Sao.PYSON.Decoder().decode(eval_), true,
|
||||
"decode(Not([]))");
|
||||
|
||||
eval_ = new Sao.PYSON.Encoder().encode(new Sao.PYSON.Not(['a']));
|
||||
QUnit.strictEqual(new Sao.PYSON.Decoder().decode(eval_), false,
|
||||
"decode(Not(['a']))");
|
||||
});
|
||||
|
||||
QUnit.test('PYSON Bool', function() {
|
||||
|
||||
@@ -188,7 +188,7 @@ class Not(PYSON):
|
||||
|
||||
@staticmethod
|
||||
def eval(dct, context):
|
||||
return not dct['v']
|
||||
return not Bool(dct['v']).eval(dct, context)
|
||||
|
||||
|
||||
class Bool(PYSON):
|
||||
|
||||
@@ -186,7 +186,7 @@ class Not(PYSON):
|
||||
|
||||
@staticmethod
|
||||
def eval(dct, context):
|
||||
return not dct['v']
|
||||
return not Bool(dct['v']).eval(dct, context)
|
||||
|
||||
|
||||
class Bool(PYSON):
|
||||
|
||||
@@ -63,6 +63,20 @@ class PYSONTestCase(unittest.TestCase):
|
||||
|
||||
self.assertEqual(repr(pyson.Not(True)), 'Not(True)')
|
||||
|
||||
eval_ = pyson.PYSONEncoder().encode(pyson.Not({}))
|
||||
self.assertTrue(pyson.PYSONDecoder().decode(eval_))
|
||||
|
||||
eval_ = pyson.PYSONEncoder().encode(pyson.Not({
|
||||
'a': 1,
|
||||
}))
|
||||
self.assertFalse(pyson.PYSONDecoder().decode(eval_))
|
||||
|
||||
eval_ = pyson.PYSONEncoder().encode(pyson.Not([]))
|
||||
self.assertTrue(pyson.PYSONDecoder().decode(eval_))
|
||||
|
||||
eval_ = pyson.PYSONEncoder().encode(pyson.Not(['a']))
|
||||
self.assertFalse(pyson.PYSONDecoder().decode(eval_))
|
||||
|
||||
def test_Bool(self):
|
||||
'Test pyson.Bool'
|
||||
self.assertEqual(pyson.Bool('test').pyson(), {
|
||||
|
||||
Reference in new issue
Block a user