mojo/public/tools/mojom/mojom/parse/parser_unittest.py
def testInvalidImports(self):
    """Tests that invalid import statements are correctly detected."""

    source1 = """\
        // Make the error occur on line 2.
        import invalid
        """
    with self.assertRaisesRegexp(
        parser.ParseError, r"^my_file\.mojom:2: Error: Unexpected 'invalid':\n"
        r" *import invalid$"):
      parser.Parse(source1, "my_file.mojom")

    source2 = """\
        import  // Missing string.
        struct MyStruct {
          int32 a;
        };
        """
    with self.assertRaisesRegexp(
        parser.ParseError, r"^my_file\.mojom:2: Error: Unexpected 'struct':\n"
        r" *struct MyStruct {$"):
      parser.Parse(source2, "my_file.mojom")

    source3 = """\
        import "foo.mojom"  // Missing semicolon.
        struct MyStruct {
          int32 a;
        };
        """
    with self.assertRaisesRegexp(
        parser.ParseError, r"^my_file\.mojom:2: Error: Unexpected 'struct':\n"
        r" *struct MyStruct {$"):
      parser.Parse(source3, "my_file.mojom")
Tests that invalid import statements are correctly detected.
Tests that invalid import statements are correctly detected.
Tests that invalid import statements are correctly detected .
def testInvalidImports(self):
    source1 = """\
        // Make the error occur on line 2.
        import invalid
        """
    with self.assertRaisesRegexp(
        parser.ParseError, r"^my_file\.mojom:2: Error: Unexpected 'invalid':\n"
        r" *import invalid$"):
      parser.Parse(source1, "my_file.mojom")
    source2 = """\
        import  // Missing string.
        struct MyStruct {
          int32 a;
        };
        """
    with self.assertRaisesRegexp(
        parser.ParseError, r"^my_file\.mojom:2: Error: Unexpected 'struct':\n"
        r" *struct MyStruct {$"):
      parser.Parse(source2, "my_file.mojom")
    source3 = """\
        import "foo.mojom"  // Missing semicolon.
        struct MyStruct {
          int32 a;
        };
        """
    with self.assertRaisesRegexp(
        parser.ParseError, r"^my_file\.mojom:2: Error: Unexpected 'struct':\n"
        r" *struct MyStruct {$"):
      parser.Parse(source3, "my_file.mojom")
def testInvalidImports ( self ) : source1 = """\
        // Make the error occur on line 2.
        import invalid
        """ with self . assertRaisesRegexp ( parser . ParseError , r"^my_file\.mojom:2: Error: Unexpected 'invalid':\n" r" *import invalid$" ) : parser . Parse ( source1 , "my_file.mojom" ) source2 = """\
        import  // Missing string.
        struct MyStruct {
          int32 a;
        };
        """ with self . assertRaisesRegexp ( parser . ParseError , r"^my_file\.mojom:2: Error: Unexpected 'struct':\n" r" *struct MyStruct {$" ) : parser . Parse ( source2 , "my_file.mojom" ) source3 = """\
        import "foo.mojom"  // Missing semicolon.
        struct MyStruct {
          int32 a;
        };
        """ with self . assertRaisesRegexp ( parser . ParseError , r"^my_file\.mojom:2: Error: Unexpected 'struct':\n" r" *struct MyStruct {$" ) : parser . Parse ( source3 , "my_file.mojom" )
Tests that invalid import statements are correctly detected.
Tests that invalid import statements are correctly detected .
"""Tests that invalid import statements are correctly detected."""
self