Castle: The best Real-Time/Embedded/HighTech language EVER. Attempt 2
修訂 | b42f9200ebf94cdb3fb73e1007e1942411261ded (tree) |
---|---|
時間 | 2024-05-27 01:44:26 |
作者 | Albert Mietus < albert AT mietus DOT nl > |
Commiter | Albert Mietus < albert AT mietus DOT nl > |
BUSY: TESTDOUBLES::sieveCastle::EV, test & then are dummy
@@ -65,8 +65,14 @@ | ||
65 | 65 | event=ID('input', context=aigr.Ref()), |
66 | 66 | port=ID('try', context=aigr.Ref()), |
67 | 67 | body=aigr.Body(statements=[ |
68 | - # XXXX | |
69 | - ])) | |
68 | + aigr.If( | |
69 | + test=aigr.Compare(ops=aigr.operators.NotEqual(), values=( | |
70 | + "try % .myPrime", | |
71 | + "0" | |
72 | + )), | |
73 | + body=aigr.Body(statements=[ | |
74 | + "XXX" | |
75 | + ]))])) | |
70 | 76 | |
71 | 77 | |
72 | 78 |
@@ -3,10 +3,8 @@ | ||
3 | 3 | See: http://docideas.mietus.nl/en/default/CCastle/4.Blog/b.TheSieve.html#the-design |
4 | 4 | """ |
5 | 5 | import logging; logger = logging.getLogger(__name__) |
6 | - | |
7 | 6 | import pytest |
8 | 7 | |
9 | - | |
10 | 8 | from castle import aigr |
11 | 9 | from castle.aigr_extra.blend import mangle_event_handler |
12 | 10 |
@@ -21,6 +19,17 @@ | ||
21 | 19 | def comp(): |
22 | 20 | return sieveCastle.Sieve |
23 | 21 | |
22 | +@pytest.fixture | |
23 | +def event_handler(comp): | |
24 | + # Notes | |
25 | + ## - event(`input`) -- this protocol has only one event, so its simple | |
26 | + ## - port('try') -- thats the 1ste one. But keep it in sync (CastleCode is leading) | |
27 | + (protocol, event, port) = protocols.SimpleSieve, protocols.SimpleSieve.events[0], components.SieveMoat.ports[0] | |
28 | + handler = find_name_in_body(mangle_event_handler(protocol=protocol.name, event=event.name, port=port.name), comp.body) | |
29 | + assert isinstance(handler, aigr.EventHandler), f"Expected EventHandler, got {handler} (type={type(handler)})" # Not a test, only to check. | |
30 | + logger.debug("Found <%s> as event_handler", handler) | |
31 | + return handler | |
32 | + | |
24 | 33 | |
25 | 34 | def test_0a_types(comp): |
26 | 35 | assert isinstance(comp, aigr.ComponentImplementation) |
@@ -35,7 +44,6 @@ | ||
35 | 44 | def test_0c_noParms(comp): |
36 | 45 | assert comp.parameters == () |
37 | 46 | |
38 | - | |
39 | 47 | def test_1_init_has_2lines(comp): |
40 | 48 | init = find_name_in_body('init', comp.body) |
41 | 49 | assert isinstance(init, aigr.Method), f"Expected an init method, got {init}" |
@@ -48,19 +56,45 @@ | ||
48 | 56 | assert isinstance(id.context, aigr.Ref), f"found ID '{id}' has not ref" |
49 | 57 | # XXX ToDo: check the ref -- for now empty is fine |
50 | 58 | |
59 | +def test_2_handler_on_try(event_handler): | |
60 | + verify_IDref(event_handler.protocol, "SimpleSieve") | |
61 | + verify_IDref(event_handler.event, "input") | |
62 | + verify_IDref(event_handler.port, "try") | |
51 | 63 | |
52 | -def test_2_handler_on_try(comp): | |
53 | - """The event-handler name and the name of protocol/event/port are all text, but ... | |
54 | - should match the names of the earlier/elsewere defined protocol/event/port structure. | |
55 | - """ | |
56 | - # Notes | |
57 | - #@ - event(`input`) -- this protocol has only one event, so its simple | |
58 | - ## - port('try') -- thats the 1ste one. But keep it in sync (CastleCode is leading) | |
59 | - (protocol, event, port) = protocols.SimpleSieve, protocols.SimpleSieve.events[0], components.SieveMoat.ports[0] | |
60 | 64 | |
61 | - handler = find_name_in_body(mangle_event_handler(protocol=protocol.name, event=event.name, port=port.name), comp.body) | |
62 | - assert handler, "No handler found" | |
65 | +def test_3a_EH_is_one_statement(event_handler): | |
66 | + "This eventhandler has basically one (multiline) statement: an if an 1 statement inside" | |
67 | + body = event_handler.body | |
68 | + assert isinstance(body, aigr.Body), f"any EH Should have a Body (instance), but found {body} (type={type(body)})" | |
69 | + assert len(body)==1, f"Expected a single (long) statement, but found {len(body)} statement(s)" | |
63 | 70 | |
64 | - verify_IDref(handler.protocol, protocol.name) | |
65 | - verify_IDref(handler.event, event.name) | |
66 | - verify_IDref(handler.port, port.name) | |
71 | + | |
72 | +def test_3b_EH_is_one_if(event_handler): | |
73 | + if_statement=event_handler.body[0] | |
74 | + assert isinstance(if_statement, aigr.If) # Not a test, only to check. | |
75 | + | |
76 | + test = if_statement.test | |
77 | + then = if_statement.body | |
78 | + orelse = if_statement.orelse | |
79 | + logger.debug("if_statement: test=%s, then=%s, orelse=%s", test,then,orelse) | |
80 | + | |
81 | + assert isinstance(test, aigr.expressions._expression) # The expressions itself is below | |
82 | + assert isinstance(then, aigr.Body) and len(then)==1 # The statement is tested below | |
83 | + assert orelse is None | |
84 | + | |
85 | + | |
86 | +def test_3c_EH_test_exps(event_handler): | |
87 | + if_statement = event_handler.body[0] | |
88 | + test = if_statement.test | |
89 | + | |
90 | + assert False, "ToDo if-expr" | |
91 | + | |
92 | + | |
93 | +def test_3d_EH_then_send(event_handler): | |
94 | + if_statement=event_handler.body[0] | |
95 | + then = if_statement.body | |
96 | + assert len(then) == 1 # Not a test, only to check. | |
97 | + send = then[0] | |
98 | + | |
99 | + assert False, "ToDo if-then" | |
100 | + |