123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122 |
- use btproto::protocol;
- struct End;
- struct Ping;
- #[test]
- fn minimal_syntax() {
- // This is the token stream that should be passed to the protocol macro:
- // Ident { ident: "let", span: #0 bytes(91..94) }
- // Ident { ident: "name", span: #0 bytes(95..99) }
- // Punct { ch: '=', spacing: Alone, span: #0 bytes(100..101) }
- // Ident { ident: "Minimal", span: #0 bytes(102..109) }
- // Punct { ch: ';', spacing: Alone, span: #0 bytes(109..110) }
- // Ident { ident: "let", span: #0 bytes(119..122) }
- // Ident { ident: "states", span: #0 bytes(123..129) }
- // Punct { ch: '=', spacing: Alone, span: #0 bytes(130..131) }
- // Group { delimiter: Bracket,
- // stream: TokenStream [Ident { ident: "Init", span: #0 bytes(133..137) }],
- // span: #0 bytes(132..138)
- // }
- // Punct { ch: ';', spacing: Alone, span: #0 bytes(138..139) }
- // Ident { ident: "Init", span: #0 bytes(148..152) }
- // Punct { ch: '?', spacing: Alone, span: #0 bytes(152..153) }
- // Ident { ident: "Activate", span: #0 bytes(153..161) }
- // Punct { ch: '-', spacing: Joint, span: #0 bytes(162..163) }
- // Punct { ch: '>', spacing: Alone, span: #0 bytes(163..164) }
- // Ident { ident: "End", span: #0 bytes(165..168) }
- // Punct { ch: ';', spacing: Alone, span: #0 bytes(168..169) }
- protocol! {
- let name = Minimal;
- let states = [Init];
- Init?Activate -> End;
- }
- }
- #[test]
- fn reply() {
- // Ident { ident: "let", span: #0 bytes(1529..1532) }
- // Ident { ident: "name", span: #0 bytes(1533..1537) }
- // Punct { ch: '=', spacing: Alone, span: #0 bytes(1538..1539) }
- // Ident { ident: "Reply", span: #0 bytes(1540..1545) }
- // Punct { ch: ';', spacing: Alone, span: #0 bytes(1545..1546) }
- // Ident { ident: "let", span: #0 bytes(1555..1558) }
- // Ident { ident: "states", span: #0 bytes(1559..1565) }
- // Punct { ch: '=', spacing: Alone, span: #0 bytes(1566..1567) }
- // Group {
- // delimiter: Bracket,
- // stream: TokenStream [
- // Ident { ident: "ServerInit", span: #0 bytes(1582..1592) },
- // Punct { ch: ',', spacing: Alone, span: #0 bytes(1592..1593) },
- // Ident { ident: "Listening", span: #0 bytes(1594..1603) },
- // Punct { ch: ',', spacing: Alone, span: #0 bytes(1603..1604) },
- // Ident { ident: "Client", span: #0 bytes(1617..1623) },
- // Punct { ch: ',', spacing: Alone, span: #0 bytes(1623..1624) },
- // Ident { ident: "Waiting", span: #0 bytes(1625..1632) },
- // Punct { ch: ',', spacing: Alone, span: #0 bytes(1632..1633) }
- // ],
- // span: #0 bytes(1568..1643)
- // }
- // Punct { ch: ';', spacing: Alone, span: #0 bytes(1643..1644) }
- // Ident { ident: "ServerInit", span: #0 bytes(1653..1663) }
- // Punct { ch: '?', spacing: Alone, span: #0 bytes(1663..1664) }
- // Ident { ident: "Activate", span: #0 bytes(1664..1672) }
- // Punct { ch: '-', spacing: Joint, span: #0 bytes(1673..1674) }
- // Punct { ch: '>', spacing: Alone, span: #0 bytes(1674..1675) }
- // Ident { ident: "Listening", span: #0 bytes(1676..1685) }
- // Punct { ch: ';', spacing: Alone, span: #0 bytes(1685..1686) }
- // Ident { ident: "Client", span: #0 bytes(1695..1701) }
- // Punct { ch: '-', spacing: Joint, span: #0 bytes(1702..1703) }
- // Punct { ch: '>', spacing: Alone, span: #0 bytes(1703..1704) }
- // Ident { ident: "Waiting", span: #0 bytes(1705..1712) }
- // Punct { ch: ',', spacing: Alone, span: #0 bytes(1712..1713) }
- // Punct { ch: '>', spacing: Alone, span: #0 bytes(1714..1715) }
- // Ident { ident: "service", span: #0 bytes(1715..1722) }
- // Group {
- // delimiter: Parenthesis,
- // stream: TokenStream [
- // Ident { ident: "Listening", span: #0 bytes(1723..1732) }
- // ],
- // span: #0 bytes(1722..1733)
- // }
- // Punct { ch: '!', spacing: Alone, span: #0 bytes(1733..1734) }
- // Ident { ident: "Ping", span: #0 bytes(1734..1738) }
- // Punct { ch: ';', spacing: Alone, span: #0 bytes(1738..1739) }
- // Ident { ident: "Listening", span: #0 bytes(1748..1757) }
- // Punct { ch: '?', spacing: Alone, span: #0 bytes(1757..1758) }
- // Ident { ident: "Ping", span: #0 bytes(1758..1762) }
- // Punct { ch: '-', spacing: Joint, span: #0 bytes(1763..1764) }
- // Punct { ch: '>', spacing: Alone, span: #0 bytes(1764..1765) }
- // Ident { ident: "Listening", span: #0 bytes(1766..1775) }
- // Punct { ch: ',', spacing: Alone, span: #0 bytes(1775..1776) }
- // Punct { ch: '>', spacing: Alone, span: #0 bytes(1777..1778) }
- // Ident { ident: "Waiting", span: #0 bytes(1778..1785) }
- // Punct { ch: '!', spacing: Alone, span: #0 bytes(1785..1786) }
- // Ident { ident: "Ping", span: #0 bytes(1786..1790) }
- // Punct { ch: ':', spacing: Joint, span: #0 bytes(1790..1791) }
- // Punct { ch: ':', spacing: Alone, span: #0 bytes(1791..1792) }
- // Ident { ident: "Reply", span: #0 bytes(1792..1797) }
- // Punct { ch: ';', spacing: Alone, span: #0 bytes(1797..1798) }
- // Ident { ident: "Waiting", span: #0 bytes(1807..1814) }
- // Punct { ch: '?', spacing: Alone, span: #0 bytes(1814..1815) }
- // Ident { ident: "Ping", span: #0 bytes(1815..1819) }
- // Punct { ch: ':', spacing: Joint, span: #0 bytes(1819..1820) }
- // Punct { ch: ':', spacing: Alone, span: #0 bytes(1820..1821) }
- // Ident { ident: "Reply", span: #0 bytes(1821..1826) }
- // Punct { ch: '-', spacing: Joint, span: #0 bytes(1827..1828) }
- // Punct { ch: '>', spacing: Alone, span: #0 bytes(1828..1829) }
- // Ident { ident: "End", span: #0 bytes(1830..1833) }
- // Punct { ch: ';', spacing: Alone, span: #0 bytes(1833..1834) }
- protocol! {
- let name = Reply;
- let states = [
- ServerInit, Listening,
- Client, Waiting,
- ];
- ServerInit?Activate -> Listening;
- Client -> Waiting, >service(Listening)!Ping;
- Listening?Ping -> Listening, >Waiting!Ping::Reply;
- Waiting?Ping::Reply -> End;
- }
- }
|