Roll ICU to r205936
[chromium-blink-merge.git] / tools / json_schema_compiler / dart_generator_test.py
blob65ec7f1e63863ebd53fbe760dab926929aa1b99e
1 #!/usr/bin/env python
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file.
6 import os
7 import sys
8 import unittest
9 import glob
11 from dart_generator import DartGenerator
12 from compiler import GenerateSchema
14 # If --rebase is passed to this test, this is set to True, indicating the test
15 # output should be re-generated for each test (rather than running the tests
16 # themselves).
17 REBASE_MODE = False
19 # The directory containing the input and expected output files corresponding
20 # to each test name.
21 TESTS_DIR = 'dart_test'
23 class DartTest(unittest.TestCase):
25 def _RunTest(self, test_filename):
26 '''Given the name of a test, runs compiler.py on the file:
27 TESTS_DIR/test_filename.idl
28 and compares it to the output in the file:
29 TESTS_DIR/test_filename.dart
30 '''
31 file_rel = os.path.join(TESTS_DIR, test_filename)
33 output_dir = None
34 if REBASE_MODE:
35 output_dir = TESTS_DIR
36 output_code = GenerateSchema('dart', ['%s.idl' % file_rel], TESTS_DIR,
37 output_dir, None, None)
39 if not REBASE_MODE:
40 with open('%s.dart' % file_rel) as f:
41 expected_output = f.read()
42 # Remove the first line of the output code (as it contains the filename).
43 # Also remove all blank lines, ignoring them from the comparison.
44 # Compare with lists instead of strings for clearer diffs (especially with
45 # whitespace) when a test fails.
46 self.assertEqual([l for l in expected_output.split('\n') if l],
47 [l for l in output_code.split('\n')[1:] if l])
49 def setUp(self):
50 # Increase the maximum diff amount to see the full diff on a failed test.
51 self.maxDiff = 2000
53 def testComments(self):
54 self._RunTest('comments')
56 def testDictionaries(self):
57 self._RunTest('dictionaries')
59 def testEmptyNamespace(self):
60 self._RunTest('empty_namespace')
62 def testEmptyType(self):
63 self._RunTest('empty_type')
65 def testEvents(self):
66 self._RunTest('enums')
68 def testEvents(self):
69 self._RunTest('events')
71 def testBasicFunction(self):
72 self._RunTest('functions')
74 def testOpratableType(self):
75 self._RunTest('operatable_type')
77 def testTags(self):
78 self._RunTest('tags')
80 if __name__ == '__main__':
81 if '--rebase' in sys.argv:
82 print "Running in rebase mode."
83 REBASE_MODE = True
84 sys.argv.remove('--rebase')
85 unittest.main()