Skip to content

Commit 231fa49

Browse files
committed
test(variant): 添加操作符功能测试用例
- 实现了算术操作符(+, -, *, /, %)的完整测试 - 添加了位操作符(<<, >>, &, |, ^)的功能验证 - 包含比较操作符(<=, <, >=, >, ==)的测试用例 - 添加混合类型操作的测试场景 - 覆盖边界条件和异常情况的测试 - 在variant.cc中添加异常处理确保操作安全 - 实现前置后置自增自减操作符的测试 - 验证赋值操作符(+=, -=, *=, /=, %=等)的正确性 - 测试一元操作符(~)的功能实现 - 添加操作符优先级和结合性的验证测试
1 parent 8f64429 commit 231fa49

File tree

3 files changed

+735
-0
lines changed

3 files changed

+735
-0
lines changed

src/core/variant.cc

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,12 +387,14 @@ void Variant::unsetProperty(const Variant &name) {
387387
static inline bool compare_op(const binary_op_type op, const zval *op1, const zval *op2) {
388388
zval result;
389389
op(&result, NO_CONST_UNWRAP_Z(op1), NO_CONST_UNWRAP_Z(op2));
390+
throwErrorIfOccurred();
390391
return Z_TYPE(result) == IS_TRUE;
391392
}
392393

393394
static inline Variant calc_op(const binary_op_type op, const zval *op1, const zval *op2) {
394395
Variant result;
395396
op(result.ptr(), NO_CONST_UNWRAP_Z(op1), NO_CONST_UNWRAP_Z(op2));
397+
throwErrorIfOccurred();
396398
return result;
397399
}
398400

@@ -425,73 +427,87 @@ Variant Variant::serialize() {
425427

426428
Variant &Variant::operator++() {
427429
increment_function(unwrap_ptr());
430+
throwErrorIfOccurred();
428431
return *this;
429432
}
430433

431434
Variant &Variant::operator--() {
432435
decrement_function(unwrap_ptr());
436+
throwErrorIfOccurred();
433437
return *this;
434438
}
435439

436440
Variant Variant::operator++(int) {
437441
auto original = *this;
438442
increment_function(unwrap_ptr());
443+
throwErrorIfOccurred();
439444
return original;
440445
}
441446

442447
Variant Variant::operator--(int) {
443448
auto original = *this;
444449
decrement_function(unwrap_ptr());
450+
throwErrorIfOccurred();
445451
return original;
446452
}
447453

448454
Variant &Variant::operator+=(const Variant &v) {
449455
add_function(unwrap_ptr(), unwrap_ptr(), NO_CONST_V(v));
456+
throwErrorIfOccurred();
450457
return *this;
451458
}
452459

453460
Variant &Variant::operator-=(const Variant &v) {
454461
sub_function(unwrap_ptr(), unwrap_ptr(), NO_CONST_V(v));
462+
throwErrorIfOccurred();
455463
return *this;
456464
}
457465

458466
Variant &Variant::operator/=(const Variant &v) {
459467
div_function(ptr(), unwrap_ptr(), NO_CONST_V(v));
468+
throwErrorIfOccurred();
460469
return *this;
461470
}
462471

463472
Variant &Variant::operator*=(const Variant &v) {
464473
mul_function(unwrap_ptr(), unwrap_ptr(), NO_CONST_V(v));
474+
throwErrorIfOccurred();
465475
return *this;
466476
}
467477

468478
Variant &Variant::operator%=(const Variant &v) {
469479
mod_function(unwrap_ptr(), unwrap_ptr(), NO_CONST_V(v));
480+
throwErrorIfOccurred();
470481
return *this;
471482
}
472483

473484
Variant &Variant::operator<<=(const Variant &v) {
474485
shift_left_function(unwrap_ptr(), unwrap_ptr(), NO_CONST_V(v));
486+
throwErrorIfOccurred();
475487
return *this;
476488
}
477489

478490
Variant &Variant::operator>>=(const Variant &v) {
479491
shift_right_function(unwrap_ptr(), unwrap_ptr(), NO_CONST_V(v));
492+
throwErrorIfOccurred();
480493
return *this;
481494
}
482495

483496
Variant &Variant::operator&=(const Variant &v) {
484497
bitwise_and_function(unwrap_ptr(), unwrap_ptr(), NO_CONST_V(v));
498+
throwErrorIfOccurred();
485499
return *this;
486500
}
487501

488502
Variant &Variant::operator|=(const Variant &v) {
489503
bitwise_or_function(unwrap_ptr(), unwrap_ptr(), NO_CONST_V(v));
504+
throwErrorIfOccurred();
490505
return *this;
491506
}
492507

493508
Variant &Variant::operator^=(const Variant &v) {
494509
bitwise_xor_function(unwrap_ptr(), unwrap_ptr(), NO_CONST_V(v));
510+
throwErrorIfOccurred();
495511
return *this;
496512
}
497513

@@ -538,6 +554,7 @@ Variant Variant::operator^(const Variant &v) const {
538554
Variant Variant::operator~() const {
539555
Variant result{};
540556
bitwise_not_function(result.ptr(), NO_CONST_Z(unwrap_ptr()));
557+
throwErrorIfOccurred();
541558
return result;
542559
}
543560

0 commit comments

Comments
 (0)