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

Function TestCheckTemporalRecursion

analysis/temporal_test.go:24–119  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

22)
23
24func TestCheckTemporalRecursion(t *testing.T) {
25 tests := []struct {
26 name string
27 program string
28 wantWarnings int
29 wantSeverity WarningSeverity
30 wantMsgContains string
31 }{
32 {
33 name: "no temporal predicates",
34 program: `
35 foo(X) :- bar(X).
36 bar(1).
37 `,
38 wantWarnings: 0,
39 },
40 {
41 name: "non-recursive temporal predicate",
42 program: `
43 Decl active(X) temporal bound [/name].
44 Decl base_active(X) bound [/name].
45 active(X) @[_, _] :- base_active(X).
46 base_active(/alice).
47 `,
48 wantWarnings: 0,
49 },
50 {
51 name: "self-recursive temporal predicate",
52 program: `
53 Decl derived(X) temporal bound [/name].
54 Decl some_condition(X) bound [/name].
55 derived(X) @[_, _] :- derived(X) @[_,_], some_condition(X).
56 some_condition(/alice).
57 `,
58 wantWarnings: 1,
59 wantSeverity: SeverityWarning,
60 wantMsgContains: "self-recursive",
61 },
62 {
63 name: "mutual recursion with temporal",
64 program: `
65 Decl foo(X) temporal bound [/name].
66 Decl bar(X) temporal bound [/name].
67 foo(X) @[_, _] :- bar(X) @[_,_].
68 bar(X) @[_, _] :- foo(X) @[_,_].
69 bar(/alice) @[_, _].
70 `,
71 wantWarnings: 1,
72 wantSeverity: SeverityCritical,
73 wantMsgContains: "mutual recursion",
74 },
75 }
76
77 for _, tt := range tests {
78 t.Run(tt.name, func(t *testing.T) {
79 unit, err := parse.Unit(strings.NewReader(tt.program))
80 if err != nil {
81 t.Fatalf("parse error: %v", err)

Callers

nothing calls this directly

Calls 5

UnitFunction · 0.92
AnalyzeOneUnitFunction · 0.85
CheckTemporalRecursionFunction · 0.85
ErrorMethod · 0.80
ContainsMethod · 0.65

Tested by

no test coverage detected