项目文件夹

文件
wehub-resource-sync c4536f7e05
CI / test (push) Failing after 1s
CI / macOS amd64 (push) Has been cancelled
CI / macOS arm64 (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 12:30:31 +08:00

67 行
1.9 KiB
Go

package main
import (
"strings"
"testing"
)
func TestParseARMDir(t *testing.T) {
b := NewBuilder()
if err := ParseARMDir(b, "testdata/arm"); err != nil {
t.Fatal(err)
}
table := b.Table()
// sysreg_ and AArch64- files must be skipped entirely.
if _, ok := table["SHOULDNOTAPPEAR"]; ok {
t.Fatal("skipped file leaked into the table")
}
add, ok := table["ADD"]
if !ok {
t.Fatal("ADD missing")
}
// Brief comes from <desc><brief>, not the noisy "-- A64" title attr.
if add.Brief != "Add (immediate)" {
t.Errorf("ADD brief = %q", add.Brief)
}
// Description is the first <authored> paragraph only; the second must be dropped.
if !strings.HasPrefix(add.Description, "Add (immediate) adds a register value") {
t.Errorf("ADD description = %q", add.Description)
}
if strings.Contains(add.Description, "second paragraph") {
t.Errorf("ADD description leaked a later paragraph: %q", add.Description)
}
if len(add.Syntax) != 1 || add.Syntax[0] != "ADD <Wd>, <Wn>, #<imm>" {
t.Errorf("ADD syntax = %#v", add.Syntax)
}
if got := add.Operands["<Wd>"]; !strings.Contains(got, "destination register") {
t.Errorf("ADD operand <Wd> = %q", got)
}
if _, ok := add.Operands["<imm>"]; !ok {
t.Errorf("ADD operand <imm> missing: %#v", add.Operands)
}
// Two LDR encodings in one file must merge into distinct syntaxes.
ldr := table["LDR"]
if len(ldr.Syntax) != 2 {
t.Errorf("LDR should have 2 syntaxes, got %#v", ldr.Syntax)
}
// Alias files must be keyed by the alias mnemonic (UBFIZ), not the base
// (UBFM) from the mnemonic docvar.
ubfiz, ok := table["UBFIZ"]
if !ok {
t.Fatal("UBFIZ alias missing")
}
if ubfiz.Brief != "Unsigned Bitfield Insert in Zero" {
t.Errorf("UBFIZ brief = %q", ubfiz.Brief)
}
if len(ubfiz.Syntax) != 1 || !strings.HasPrefix(ubfiz.Syntax[0], "UBFIZ ") {
t.Errorf("UBFIZ syntax = %#v", ubfiz.Syntax)
}
if _, leaked := table["UBFM"]; leaked {
t.Error("alias content leaked into base UBFM key")
}
}