MCPcopy
hub / github.com/google/mangle / TestRectifyAtom

Function TestRectifyAtom

analysis/rectify_test.go:25–125  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

23)
24
25func TestRectifyAtom(t *testing.T) {
26 tests := []struct {
27 atom ast.Atom
28 used []ast.Variable
29 wantAtom ast.Atom
30 wantFml []ast.Term
31 wantBound []ast.Variable
32 fresh []ast.Variable
33 }{
34 {
35 atom: atom("foo(_)"),
36 wantAtom: atom("foo(_)"),
37 },
38 {
39 atom: atom("foo(X)"),
40 wantAtom: atom("foo(X)"),
41 wantBound: []ast.Variable{ast.Variable{"X"}},
42 },
43 {
44 atom: atom("foo(X)"),
45 used: []ast.Variable{ast.Variable{"X"}},
46 wantAtom: atom("foo(Y)"),
47 wantFml: []ast.Term{ast.Eq{ast.Variable{"Y"}, ast.Variable{"X"}}},
48 fresh: []ast.Variable{ast.Variable{"Y"}},
49 },
50 {
51 atom: atom("foo(X, Y)"),
52 used: []ast.Variable{ast.Variable{"X"}},
53 wantAtom: atom("foo(Z, Y)"),
54 wantFml: []ast.Term{ast.Eq{ast.Variable{"Z"}, ast.Variable{"X"}}},
55 wantBound: []ast.Variable{ast.Variable{"Y"}},
56 fresh: []ast.Variable{ast.Variable{"Z"}},
57 },
58 {
59 atom: atom("foo(X, 23001)"),
60 used: []ast.Variable{ast.Variable{"X"}},
61 wantAtom: atom("foo(Z, Y)"),
62 wantFml: []ast.Term{
63 ast.Eq{ast.Variable{"Z"}, ast.Variable{"X"}},
64 ast.Eq{ast.Variable{"Y"}, ast.Number(23001)}},
65 fresh: []ast.Variable{ast.Variable{"Z"}, ast.Variable{"Y"}},
66 },
67 {
68 atom: atom("foo(X, X)"),
69 wantAtom: atom("foo(X, Y)"),
70 wantFml: []ast.Term{ast.Eq{ast.Variable{"Y"}, ast.Variable{"X"}}},
71 wantBound: []ast.Variable{ast.Variable{"X"}},
72 fresh: []ast.Variable{ast.Variable{"Y"}},
73 },
74 {
75 atom: atom("foo(fn:plus(X, 1))"),
76 wantAtom: atom("foo(Y)"),
77 wantFml: []ast.Term{fml("Y = fn:plus(X, 1)")},
78 fresh: []ast.Variable{ast.Variable{"Y"}},
79 },
80 {
81 atom: atom("foo(fn:plus(A, fn:plus(B, 1)))"),
82 wantAtom: atom("foo(Y)"),

Callers

nothing calls this directly

Calls 6

NumberFunction · 0.92
InitVarsFunction · 0.92
fmlFunction · 0.85
RectifyAtomFunction · 0.85
atomFunction · 0.70
ApplySubstMethod · 0.65

Tested by

no test coverage detected