Skip to content

Commit 89f31ae

Browse files
miaobyteclaude
andcommitted
test: add builtin assignment syntax test cases
Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 1259796 commit 89f31ae

1 file changed

Lines changed: 32 additions & 0 deletions

File tree

internal/parser/parsertest/main_test.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,3 +206,35 @@ func TestScan_BreakContinue_Tokens(t *testing.T) {
206206
t.Errorf("expected [Break, Continue], got %v", kinds)
207207
}
208208
}
209+
210+
func TestAssign_Eq(t *testing.T) {
211+
// = ≡ <-:写槽在左;== 不受影响;String() 保留 = 形态
212+
src := `
213+
def f(A:int) -> (R:int) {
214+
x = A + 1
215+
ok = x == 2
216+
R = x
217+
}
218+
`
219+
f, diags, err := parser.ParseCode(strings.NewReader(src))
220+
if err != nil {
221+
t.Fatalf("parse error: %v", err)
222+
}
223+
if len(diags) > 0 {
224+
t.Fatalf("diags: %v", diags)
225+
}
226+
body := f.Funcs[0].Body
227+
i0 := body[0].(*ast.Instruction)
228+
if !i0.ArrowLeft || !i0.Eq || len(i0.Writes) != 1 || i0.Writes[0] != "x" {
229+
t.Errorf("i0: ArrowLeft=%v Eq=%v Writes=%v", i0.ArrowLeft, i0.Eq, i0.Writes)
230+
}
231+
if got := i0.String(); got != "x = A + 1" {
232+
t.Errorf("expected 'x = A + 1', got %q", got)
233+
}
234+
if i1 := body[1].(*ast.Instruction); i1.Expr.Op != "==" {
235+
t.Errorf("expected '==' op, got %q", i1.Expr.Op)
236+
}
237+
if i2 := body[2].(*ast.Instruction); i2.Expr == nil || !i2.Expr.IsLeaf() || !i2.Eq {
238+
t.Errorf("i2: expected leaf copy with Eq")
239+
}
240+
}

0 commit comments

Comments
 (0)