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

Closes #13096
This commit is contained in:
Nicolas Évrard
2024-03-11 16:35:39 +01:00
parent 3e06f5043a
commit 026ae5bff4
5 changed files with 35 additions and 3 deletions
+1 -1
View File
@@ -244,7 +244,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
@@ -128,6 +128,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
@@ -223,7 +223,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
@@ -223,7 +223,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
@@ -70,6 +70,20 @@ class PYSONTestCase(unittest.TestCase):
repr(pyson.Eval('foo') != 'bar'),
"(Eval('foo') != 'bar')")
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(), {