feat(lint): add unused-label and invalid-textflag rules
Assisted-by: MiMo V2.5 Pro
This commit is contained in:
@@ -233,3 +233,52 @@ TEXT ·f(SB), NOSPLIT, $0
|
||||
t.Fatalf("label rules should be suppressed in macro files: %+v", diags)
|
||||
}
|
||||
}
|
||||
|
||||
func TestUnusedLabel(t *testing.T) {
|
||||
diags := lintSrc(t, `
|
||||
#include "textflag.h"
|
||||
TEXT ·f(SB), NOSPLIT, $0
|
||||
unused:
|
||||
ADDQ $1, AX
|
||||
RET
|
||||
`)
|
||||
if codes(diags)[CodeUnusedLabel] != 1 {
|
||||
t.Fatalf("want one unused-label, got %+v", diags)
|
||||
}
|
||||
}
|
||||
|
||||
func TestUsedLabelNotFlagged(t *testing.T) {
|
||||
diags := lintSrc(t, `
|
||||
#include "textflag.h"
|
||||
TEXT ·f(SB), NOSPLIT, $0
|
||||
loop:
|
||||
ADDQ $1, AX
|
||||
JMP loop
|
||||
RET
|
||||
`)
|
||||
if codes(diags)[CodeUnusedLabel] != 0 {
|
||||
t.Fatalf("used label must not be flagged: %+v", diags)
|
||||
}
|
||||
}
|
||||
|
||||
func TestInvalidTextflag(t *testing.T) {
|
||||
diags := lintSrc(t, `
|
||||
#include "textflag.h"
|
||||
TEXT ·f(SB), NOSPLIT|BOGUS, $0
|
||||
RET
|
||||
`)
|
||||
if codes(diags)[CodeInvalidFlag] != 1 {
|
||||
t.Fatalf("want one invalid-textflag, got %+v", diags)
|
||||
}
|
||||
}
|
||||
|
||||
func TestValidTextflags(t *testing.T) {
|
||||
diags := lintSrc(t, `
|
||||
#include "textflag.h"
|
||||
TEXT ·f(SB), NOSPLIT|NOFRAME|DUPOK, $0
|
||||
RET
|
||||
`)
|
||||
if codes(diags)[CodeInvalidFlag] != 0 {
|
||||
t.Fatalf("valid flags must not be flagged: %+v", diags)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user