|
| 1 | +import java as J |
| 2 | + |
| 3 | +private signature module InlineMadTestLangSig { |
| 4 | + /** |
| 5 | + * A base class of callables for modeling. |
| 6 | + */ |
| 7 | + class Callable; |
| 8 | + |
| 9 | + /** |
| 10 | + * Gets a relevant code comment for `c`, if any. |
| 11 | + */ |
| 12 | + string getComment(Callable c); |
| 13 | +} |
| 14 | + |
| 15 | +private module InlineMadTestImpl<InlineMadTestLangSig Lang> { |
| 16 | + private class Callable = Lang::Callable; |
| 17 | + |
| 18 | + signature module InlineMadTestConfigSig { |
| 19 | + /** |
| 20 | + * Gets the kind of a captured model. |
| 21 | + */ |
| 22 | + string getKind(); |
| 23 | + |
| 24 | + /** |
| 25 | + * Gets a captured model for `c`, if any. |
| 26 | + */ |
| 27 | + string getCapturedModel(Callable c); |
| 28 | + } |
| 29 | + |
| 30 | + module InlineMadTest<InlineMadTestConfigSig Input> { |
| 31 | + private string expects(Callable c) { |
| 32 | + Lang::getComment(c).regexpCapture(" *(SPURIOUS-)?" + Input::getKind() + "=(.*)", 2) = result |
| 33 | + } |
| 34 | + |
| 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 | + } |
| 50 | + } |
| 51 | +} |
| 52 | + |
| 53 | +private module InlineMadTestLang implements InlineMadTestLangSig { |
| 54 | + class Callable = J::Callable; |
| 55 | + |
| 56 | + string getComment(Callable c) { |
| 57 | + exists(J::Javadoc doc | |
| 58 | + hasJavadoc(c, doc) and |
| 59 | + isNormalComment(doc) and |
| 60 | + result = doc.getChild(0).toString() |
| 61 | + ) |
| 62 | + } |
| 63 | +} |
| 64 | + |
| 65 | +import InlineMadTestImpl<InlineMadTestLang> |
0 commit comments