Skip to content

Commit 5fe3ab7

Browse files
committed
Java: Prepare for inline test sharing with C#.
1 parent b53fa0f commit 5fe3ab7

File tree

1 file changed

+40
-31
lines changed

1 file changed

+40
-31
lines changed
Lines changed: 40 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,65 @@
1-
import java
1+
import java as J
22

33
private signature module InlineMadTestLangSig {
4+
/**
5+
* A base class of callables for modeling.
6+
*/
7+
class Callable;
8+
49
/**
510
* Gets a relevant code comment for `c`, if any.
611
*/
712
string getComment(Callable c);
813
}
914

10-
signature module InlineMadTestConfigSig {
11-
/**
12-
* Gets the kind of a captured model.
13-
*/
14-
string getKind();
15+
private module InlineMadTestImpl<InlineMadTestLangSig Lang> {
16+
private class Callable = Lang::Callable;
1517

16-
/**
17-
* Gets a captured model for `c`, if any.
18-
*/
19-
string getCapturedModel(Callable c);
20-
}
18+
signature module InlineMadTestConfigSig {
19+
/**
20+
* Gets the kind of a captured model.
21+
*/
22+
string getKind();
2123

22-
private module InlineMadTestImpl<InlineMadTestLangSig Lang, InlineMadTestConfigSig Input> {
23-
private string expects(Callable c) {
24-
Lang::getComment(c).regexpCapture(" *(SPURIOUS-)?" + Input::getKind() + "=(.*)", 2) = result
24+
/**
25+
* Gets a captured model for `c`, if any.
26+
*/
27+
string getCapturedModel(Callable c);
2528
}
2629

27-
query predicate unexpectedModel(string msg) {
28-
exists(Callable c, string flow |
29-
flow = Input::getCapturedModel(c) and
30-
not flow = expects(c) and
31-
msg = "Unexpected " + Input::getKind() + " found: " + flow
32-
)
33-
}
30+
module InlineMadTest<InlineMadTestConfigSig Input> {
31+
private string expects(Callable c) {
32+
Lang::getComment(c).regexpCapture(" *(SPURIOUS-)?" + Input::getKind() + "=(.*)", 2) = result
33+
}
3434

35-
query predicate expectedModel(string msg) {
36-
exists(Callable c, string e |
37-
e = expects(c) and
38-
not e = Input::getCapturedModel(c) and
39-
msg = "Expected " + Input::getKind() + " missing: " + e
40-
)
35+
query predicate unexpectedModel(string msg) {
36+
exists(Callable c, string flow |
37+
flow = Input::getCapturedModel(c) and
38+
not flow = expects(c) and
39+
msg = "Unexpected " + Input::getKind() + " found: " + flow
40+
)
41+
}
42+
43+
query predicate expectedModel(string msg) {
44+
exists(Callable c, string e |
45+
e = expects(c) and
46+
not e = Input::getCapturedModel(c) and
47+
msg = "Expected " + Input::getKind() + " missing: " + e
48+
)
49+
}
4150
}
4251
}
4352

4453
private module InlineMadTestLang implements InlineMadTestLangSig {
54+
class Callable = J::Callable;
55+
4556
string getComment(Callable c) {
46-
exists(Javadoc doc |
57+
exists(J::Javadoc doc |
4758
hasJavadoc(c, doc) and
4859
isNormalComment(doc) and
4960
result = doc.getChild(0).toString()
5061
)
5162
}
5263
}
5364

54-
module InlineMadTest<InlineMadTestConfigSig Input> {
55-
import InlineMadTestImpl<InlineMadTestLang, Input>
56-
}
65+
import InlineMadTestImpl<InlineMadTestLang>

0 commit comments

Comments
 (0)