OLD | NEW |
| (Empty) |
1 #!/usr/bin/python | |
2 # Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | |
3 # for details. All rights reserved. Use of this source code is governed by a | |
4 # BSD-style license that can be found in the LICENSE file. | |
5 | |
6 import idlnode | |
7 import idlparser | |
8 import idlrenderer | |
9 import logging.config | |
10 import unittest | |
11 | |
12 | |
13 class IDLRendererTestCase(unittest.TestCase): | |
14 | |
15 def _run_test(self, input_text, expected_text): | |
16 """Parses input, renders it and compares the results""" | |
17 parser = idlparser.IDLParser(idlparser.FREMONTCUT_SYNTAX) | |
18 idl_file = idlnode.IDLFile(parser.parse(input_text)) | |
19 output_text = idlrenderer.render(idl_file) | |
20 | |
21 if output_text != expected_text: | |
22 msg = ''' | |
23 EXPECTED: | |
24 %s | |
25 ACTUAL : | |
26 %s | |
27 ''' % (expected_text, output_text) | |
28 self.fail(msg) | |
29 | |
30 def test_rendering(self): | |
31 input_text = \ | |
32 '''module M { | |
33 [Constructor(long x)] interface I : @A J, K { | |
34 attribute int attr; | |
35 readonly attribute long attr2; | |
36 getter attribute int get_attr; | |
37 setter attribute int set_attr; | |
38 | |
39 [A,B=123] void function(in long x, in optional boolean y); | |
40 | |
41 const boolean CONST = 1; | |
42 | |
43 @A @B() @C(x) @D(x=1) @E(x,y=2) | |
44 void something(); | |
45 }; | |
46 }; | |
47 @X module M2 { | |
48 @Y interface I {}; | |
49 };''' | |
50 | |
51 expected_text = \ | |
52 '''module M { | |
53 [Constructor(in long x)] | |
54 interface I : | |
55 @A J, | |
56 K { | |
57 | |
58 /* Constants */ | |
59 const boolean CONST = 1; | |
60 | |
61 /* Attributes */ | |
62 attribute int attr; | |
63 attribute long attr2; | |
64 getter attribute int get_attr; | |
65 setter attribute int set_attr; | |
66 | |
67 /* Operations */ | |
68 [A, B=123] void function(in long x, in optional boolean y); | |
69 @A @B @C(x) @D(x=1) @E(x, y=2) void something(); | |
70 }; | |
71 }; | |
72 @X module M2 { | |
73 @Y | |
74 interface I { | |
75 }; | |
76 }; | |
77 ''' | |
78 self._run_test(input_text, expected_text) | |
79 | |
80 if __name__ == "__main__": | |
81 logging.config.fileConfig("logging.conf") | |
82 if __name__ == '__main__': | |
83 unittest.main() | |
OLD | NEW |