blob: 867065010c762d1ae6e59a2c9022da2ad36d5708 [file] [log] [blame]
Sapan Bhatia64c72512017-06-23 02:32:45 -07001import plyxproto.parser as plyproto
Dusan Klinecccaa0d92014-11-09 03:21:31 +01002
3test1 = """package tutorial;"""
4
5test2 = """package tutorial;
6
7message Person {
8 required string name = 1;
9 required int32 id = 2;
10 optional string email = 3;
11}
12
13"""
14
15test3 = """package tutorial;
16option java_outer_classname = "PushNotifications";
Dusan Klinecaa9ff472014-11-10 18:02:03 +010017option optimize_for = SPEED;
Dusan Klinecccaa0d92014-11-09 03:21:31 +010018
Sapan Bhatia64c72512017-06-23 02:32:45 -070019 policy slice_user <foobar>
20
21 message Person(core.Actor) {
Dusan Klinecccaa0d92014-11-09 03:21:31 +010022 required string name = 1;
23 required int32 id = 2;
24 optional string email = 3;
25
Sapan Bhatia2ddf83a2017-06-10 04:31:40 -070026 required manytoone work_location->Location/types.Company:employees = 4;
27
Dusan Klinecccaa0d92014-11-09 03:21:31 +010028 enum PhoneType {
29 MOBILE = 0;
30 HOME = 1;
31 WORK = 2;
32 }
33
34 message PhoneNumber {
35 required string number = 1;
36 optional PhoneType type = 2 [default = HOME];
37 }
38
39 repeated PhoneNumber phone = 4;
40 extensions 500 to 990;
41}
42
43message AddressBook {
44 repeated Person person = 1;
45
46 // Possible extension numbers.
47 extensions 500 to max;
48}"""
49
Sapan Bhatiaad79fee2017-06-26 23:35:57 -070050test4 = '''policy foo <exists foo: foo.x=foo.y>'''
Dusan Klinecccaa0d92014-11-09 03:21:31 +010051parser = plyproto.ProtobufAnalyzer()
Sapan Bhatiaad79fee2017-06-26 23:35:57 -070052
53tests = globals()
54
55for t in tests:
Sapan Bhatiaad79fee2017-06-26 23:35:57 -070056 if t.startswith('test'):
57 print 'parsin %s'%t
58 parser.parse_string(globals()[t])
59