Make Bool PYSON evaluate to false empty Time and TimeDelta
As Time and TimeDelta are moment Object, Bool should specially evaluate those instances. issue5993 review25781002
This commit is contained in:
1 parent
6b83651828
commit
24b522c7fc
2 files changed
+18
-1
No files matched your search
+6
-1
@@ -197,7 +197,12 @@
|
||||
});
|
||||
|
||||
Sao.PYSON.Bool.eval_ = function(value, context) {
|
||||
if (value.v instanceof Object) {
|
||||
if (moment.isMoment(value.v) && value.v.isTime) {
|
||||
return Boolean(value.v.hour() || value.v.minute() ||
|
||||
value.v.second() || value.v.millisecond());
|
||||
} else if (moment.isDuration(value.v)) {
|
||||
return Boolean(value.v.valueOf());
|
||||
} else if (value.v instanceof Object) {
|
||||
return !jQuery.isEmptyObject(value.v);
|
||||
} else {
|
||||
return Boolean(value.v);
|
||||
|
||||
@@ -149,6 +149,18 @@
|
||||
eval_ = new Sao.PYSON.Encoder().encode(new Sao.PYSON.Bool({}));
|
||||
QUnit.strictEqual(new Sao.PYSON.Decoder().decode(eval_), false,
|
||||
'decode(Bool({}))');
|
||||
|
||||
eval_ = new Sao.PYSON.Encoder().encode(
|
||||
new Sao.PYSON.Bool(new Sao.PYSON.Eval('value')));
|
||||
QUnit.strictEqual(new Sao.PYSON.Decoder({value: Sao.Time(0)})
|
||||
.decode(eval_), false, "decode(Bool(Sao.Time(0)))");
|
||||
QUnit.strictEqual(new Sao.PYSON.Decoder({value: Sao.Time(1)})
|
||||
.decode(eval_), true, "decode(Bool(Sao.Time(1)))");
|
||||
QUnit.strictEqual(new Sao.PYSON.Decoder({value: Sao.TimeDelta()})
|
||||
.decode(eval_), false, "decode(Bool(Sao.TimeDelta()))");
|
||||
QUnit.strictEqual(new Sao.PYSON.Decoder({value: Sao.TimeDelta(1)})
|
||||
.decode(eval_), true, "decode(Bool(Sao.TimeDelta(1)))");
|
||||
|
||||
QUnit.strictEqual(new Sao.PYSON.Bool('test').toString(),
|
||||
"Bool(\"test\")");
|
||||
});
|
||||
|
||||
Reference in new issue
Block a user