stage1 重构代码

This commit is contained in:
zzy
2026-08-01 21:15:47 +08:00
parent a77eade06f
commit b43042c88d
30 changed files with 1211 additions and 6502 deletions

View File

@@ -79,7 +79,7 @@ fn test_optional_match() i32 {
var o: Optional = Optional { .Some = 42 };
match o {
.Some(val) => {
.Some[val] => {
if val != 42 { ret 1; }
},
.None => {
@@ -90,7 +90,7 @@ fn test_optional_match() i32 {
o = Optional { .None };
var is_none: i32 = 0;
match o {
.Some(val) => {},
.Some[val] => {},
.None => { is_none = 1; }
}
if is_none != 1 { ret 3; }
@@ -98,7 +98,7 @@ fn test_optional_match() i32 {
/* 多次提取不同值 */
o = Optional { .Some = 99 };
match o {
.Some(val) => {
.Some[val] => {
if val != 99 { ret 4; }
},
.None => { ret 5; }
@@ -115,10 +115,10 @@ fn test_shape_match() i32 {
/* Circle: 单数据 */
var s: Shape = Shape { .Circle = 10 };
match s {
.Circle(r) => {
.Circle[r] => {
if r != 10 { ret 1; }
},
.Rect(w, h) => {
.Rect[.x = w, .y = h] => {
ret 2;
}
}
@@ -126,8 +126,8 @@ fn test_shape_match() i32 {
/* Rect: 结构体数据,绑定为 (x, y) 对应 Point 的字段 */
s = Shape { .Rect = Point { .x = 3, .y = 4 } };
match s {
.Circle(r) => { ret 3; },
.Rect(w, h) => {
.Circle[r] => { ret 3; },
.Rect[.x = w, .y = h] => {
if w != 3 { ret 4; }
if h != 4 { ret 5; }
}
@@ -143,16 +143,16 @@ fn test_shape_match() i32 {
fn test_action_result_match() i32 {
var r: ActionResult = ActionResult { .Success = 200 };
match r {
.Success(code) => {
.Success[code] => {
if code != 200 { ret 1; }
},
.NotFound => {
ret 2;
},
.Timeout(ms) => {
.Timeout[ms] => {
ret 3;
},
.Error(msg) => {
.Error[msg] => {
ret 4;
}
}
@@ -160,21 +160,21 @@ fn test_action_result_match() i32 {
r = ActionResult { .NotFound };
var found: i32 = 1;
match r {
.Success(code) => { found = 0; },
.Success[code] => { found = 0; },
.NotFound => { },
.Timeout(ms) => { found = 0; },
.Error(msg) => { found = 0; }
.Timeout[ms] => { found = 0; },
.Error[msg] => { found = 0; }
}
if found != 1 { ret 5; }
r = ActionResult { .Timeout = 5000 };
match r {
.Success(code) => { ret 6; },
.Success[code] => { ret 6; },
.NotFound => { ret 7; },
.Timeout(ms) => {
.Timeout[ms] => {
if ms != 5000 { ret 8; }
},
.Error(msg) => { ret 9; }
.Error[msg] => { ret 9; }
}
ret 0;
@@ -252,7 +252,7 @@ fn test_match_in_loop() i32 {
}
match o {
.Some(val) => {
.Some[val] => {
sum = sum + val;
},
.None => { }