| OLD | NEW |
| 1 # Copyright 2014 The Chromium Authors. All rights reserved. | 1 # Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 import imp | 5 import imp |
| 6 import os.path | 6 import os.path |
| 7 import sys | 7 import sys |
| 8 import unittest | 8 import unittest |
| 9 | 9 |
| 10 # Disable lint check for finding modules: | 10 # Disable lint check for finding modules: |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 54 source = """\ | 54 source = """\ |
| 55 // This is a comment. | 55 // This is a comment. |
| 56 | 56 |
| 57 module my_module { | 57 module my_module { |
| 58 """ | 58 """ |
| 59 with self.assertRaisesRegexp( | 59 with self.assertRaisesRegexp( |
| 60 parser.ParseError, | 60 parser.ParseError, |
| 61 r"^my_file\.mojom: Error: Unexpected end of file$"): | 61 r"^my_file\.mojom: Error: Unexpected end of file$"): |
| 62 parser.Parse(source, "my_file.mojom") | 62 parser.Parse(source, "my_file.mojom") |
| 63 | 63 |
| 64 def testCommentLineNumbers(self): |
| 65 """Tests that line numbers are correctly tracked when comments are |
| 66 present.""" |
| 67 source1 = """\ |
| 68 // Isolated C++-style comments. |
| 69 |
| 70 // Foo. |
| 71 asdf1 |
| 72 """ |
| 73 with self.assertRaisesRegexp( |
| 74 parser.ParseError, |
| 75 r"^my_file\.mojom:4: Error: Unexpected 'asdf1':\nasdf1$"): |
| 76 parser.Parse(source1, "my_file.mojom") |
| 77 |
| 78 source2 = """\ |
| 79 // Consecutive C++-style comments. |
| 80 // Foo. |
| 81 // Bar. |
| 82 |
| 83 struct Yada { // Baz. |
| 84 // Quux. |
| 85 int32 x; |
| 86 }; |
| 87 |
| 88 asdf2 |
| 89 """ |
| 90 with self.assertRaisesRegexp( |
| 91 parser.ParseError, |
| 92 r"^my_file\.mojom:10: Error: Unexpected 'asdf2':\nasdf2$"): |
| 93 parser.Parse(source2, "my_file.mojom") |
| 94 |
| 95 source3 = """\ |
| 96 /* Single-line C-style comments. */ |
| 97 /* Foobar. */ |
| 98 |
| 99 /* Baz. */ |
| 100 asdf3 |
| 101 """ |
| 102 with self.assertRaisesRegexp( |
| 103 parser.ParseError, |
| 104 r"^my_file\.mojom:5: Error: Unexpected 'asdf3':\nasdf3$"): |
| 105 parser.Parse(source3, "my_file.mojom") |
| 106 |
| 107 source4 = """\ |
| 108 /* Multi-line C-style comments. |
| 109 */ |
| 110 /* |
| 111 Foo. |
| 112 Bar. |
| 113 */ |
| 114 |
| 115 /* Baz |
| 116 Quux. */ |
| 117 asdf4 |
| 118 """ |
| 119 with self.assertRaisesRegexp( |
| 120 parser.ParseError, |
| 121 r"^my_file\.mojom:10: Error: Unexpected 'asdf4':\nasdf4$"): |
| 122 parser.Parse(source4, "my_file.mojom") |
| 123 |
| 124 |
| 64 def testSimpleStruct(self): | 125 def testSimpleStruct(self): |
| 65 """Tests a simple .mojom source that just defines a struct.""" | 126 """Tests a simple .mojom source that just defines a struct.""" |
| 66 source = """\ | 127 source = """\ |
| 67 module my_module { | 128 module my_module { |
| 68 | 129 |
| 69 struct MyStruct { | 130 struct MyStruct { |
| 70 int32 a; | 131 int32 a; |
| 71 double b; | 132 double b; |
| 72 }; | 133 }; |
| 73 | 134 |
| (...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 368 with self.assertRaisesRegexp( | 429 with self.assertRaisesRegexp( |
| 369 parser.ParseError, | 430 parser.ParseError, |
| 370 r"^my_file\.mojom:2: Error: " | 431 r"^my_file\.mojom:2: Error: " |
| 371 r"Invalid handle type 'wtf_is_this':\n" | 432 r"Invalid handle type 'wtf_is_this':\n" |
| 372 r" handle<wtf_is_this> foo;$"): | 433 r" handle<wtf_is_this> foo;$"): |
| 373 parser.Parse(source, "my_file.mojom") | 434 parser.Parse(source, "my_file.mojom") |
| 374 | 435 |
| 375 | 436 |
| 376 if __name__ == "__main__": | 437 if __name__ == "__main__": |
| 377 unittest.main() | 438 unittest.main() |
| OLD | NEW |