Use PYSON's Bool evaluation for PYSON's Not evaluation

Closes #13096
(grafted from 009133813b11f264b5e038dc9c5912dc9e0101cb)

--HG--
branch : 6.0
This commit is contained in:
Nicolas Évrard committed 2024-03-11 16:35:39 +01:00
1 parent 319527ea43
commit 1ffdad78ce
5 files changed
+35 -3

No files matched your search

+1 -1
View File
@@ -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);
+18
View File
@@ -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() {
+1 -1
View File
@@ -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):
+1 -1
View File
@@ -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):
+14
View File
@@ -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(), {