예제 #1
0
    def test_raises_for_bad_feature(self):
        with self.assertRaises(ValueError):
            parser.Options('foobar')

        options = parser.Options()
        with self.assertRaises(ValueError):
            options.has_feature('foobar')
예제 #2
0
    def test_has_feature(self):
        options = parser.Options()
        self.assertFalse(options.has_feature('dictionary-required'))
        self.assertFalse(
            options.has_feature(parser.Features.DICTIONARY_REQUIRED))
        self.assertFalse(
            options.has_feature(parser.Features.DICTIONARY_DEFAULT))

        options = parser.Options(parser.Features.DICTIONARY_REQUIRED)
        self.assertTrue(options.has_feature('dictionary-required'))
        self.assertTrue(
            options.has_feature(parser.Features.DICTIONARY_REQUIRED))
        self.assertFalse(
            options.has_feature(parser.Features.DICTIONARY_DEFAULT))
예제 #3
0
 def test_assumed_feature(self):
     tests = [
         ('dictionary-required', 'dictionary', 'dictionary-default'),
     ]
     for feature, expected, not_added in tests:
         options = parser.Options(feature)
         self.assertTrue(options.has_feature(feature))
         self.assertTrue(options.has_feature(expected))
         self.assertFalse(options.has_feature(not_added))
예제 #4
0
 def test_enforces_options(self):
     tests = [
         (['dictionary'], 'dictionary Foo { long x; };'),
         (['dictionary-required'], 'dictionary Foo { required long x; };'),
         (['dictionary-default'], 'dictionary Foo { long x = 123; };'),
     ]
     parse = parser.IdlParser()
     for config, code in tests:
         # With all options it should work.
         parse.options = parser.Options.all()
         parse.parse('', code)
         # It should also work with just the setting given.
         parse.options = parser.Options(*config)
         parse.parse('', code)
         # Without setting given, should raise an error.
         with self.assertRaises(parser.IdlSyntaxError):
             parse.options = parser.Options()
             parse.parse('', code)