mojo/public/tools/mojom/mojom/parse/parser_unittest.py
def testInvalidInterfaceDefinitions(self):
    """Tests that definitions that aren't allowed in an interface are correctly
    detected."""

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

    source2 = """\
        interface MyInterface {
          interface MyInnerInterface {
            MyMethod(int32 x);
          };
        };
        """
    with self.assertRaisesRegexp(
        parser.ParseError,
        r"^my_file\.mojom:2: Error: Unexpected 'interface':\n"
        r" *interface MyInnerInterface {$"):
      parser.Parse(source2, "my_file.mojom")

    source3 = """\
        interface MyInterface {
          int32 my_field;
        };
        """
    # The parser thinks that "int32" is a plausible name for a method, so it's
    # "my_field" that gives it away.
    with self.assertRaisesRegexp(
        parser.ParseError, r"^my_file\.mojom:2: Error: Unexpected 'my_field':\n"
        r" *int32 my_field;$"):
      parser.Parse(source3, "my_file.mojom")
Tests that definitions that aren't allowed in an interface are correctly
    detected.
Tests that definitions that aren't allowed in an interface are correctly
detected.
Tests that definitions that aren ' t allowed in an interface are correctly detected .
def testInvalidInterfaceDefinitions(self):
    source1 = """\
        interface MyInterface {
          struct MyStruct {
            int32 a;
          };
        };
        """
    with self.assertRaisesRegexp(
        parser.ParseError, r"^my_file\.mojom:2: Error: Unexpected 'struct':\n"
        r" *struct MyStruct {$"):
      parser.Parse(source1, "my_file.mojom")
    source2 = """\
        interface MyInterface {
          interface MyInnerInterface {
            MyMethod(int32 x);
          };
        };
        """
    with self.assertRaisesRegexp(
        parser.ParseError,
        r"^my_file\.mojom:2: Error: Unexpected 'interface':\n"
        r" *interface MyInnerInterface {$"):
      parser.Parse(source2, "my_file.mojom")
    source3 = """\
        interface MyInterface {
          int32 my_field;
        };
        """
    with self.assertRaisesRegexp(
        parser.ParseError, r"^my_file\.mojom:2: Error: Unexpected 'my_field':\n"
        r" *int32 my_field;$"):
      parser.Parse(source3, "my_file.mojom")
def testInvalidInterfaceDefinitions ( self ) : source1 = """\
        interface MyInterface {
          struct MyStruct {
            int32 a;
          };
        };
        """ with self . assertRaisesRegexp ( parser . ParseError , r"^my_file\.mojom:2: Error: Unexpected 'struct':\n" r" *struct MyStruct {$" ) : parser . Parse ( source1 , "my_file.mojom" ) source2 = """\
        interface MyInterface {
          interface MyInnerInterface {
            MyMethod(int32 x);
          };
        };
        """ with self . assertRaisesRegexp ( parser . ParseError , r"^my_file\.mojom:2: Error: Unexpected 'interface':\n" r" *interface MyInnerInterface {$" ) : parser . Parse ( source2 , "my_file.mojom" ) source3 = """\
        interface MyInterface {
          int32 my_field;
        };
        """ with self . assertRaisesRegexp ( parser . ParseError , r"^my_file\.mojom:2: Error: Unexpected 'my_field':\n" r" *int32 my_field;$" ) : parser . Parse ( source3 , "my_file.mojom" )
Tests that definitions that aren't allowed in an interface are correctly
detected.
Tests that definitions that aren ' t allowed in an interface are correctly detected .
"""Tests that definitions that aren't allowed in an interface are correctly
    detected.""" # The parser thinks that "int32" is a plausible name for a method, so it's # "my_field" that gives it away.
self