OLD | NEW |
(Empty) | |
| 1 #!/usr/bin/env python |
| 2 # Copyright 2014 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. |
| 5 |
| 6 import unittest |
| 7 |
| 8 from checker import Checker, FileCache |
| 9 |
| 10 |
| 11 class CodingConventionTest(unittest.TestCase): |
| 12 def setUp(self): |
| 13 self._checker = Checker(verbose=False) |
| 14 |
| 15 def testGetInstance(self): |
| 16 file_content = """ |
| 17 var cr = { |
| 18 /** @param {!Function} ctor */ |
| 19 addSingletonGetter: function(ctor) { |
| 20 ctor.getInstance = function() { |
| 21 return ctor.instance_ || (ctor.instance_ = new ctor()); |
| 22 }; |
| 23 } |
| 24 }; |
| 25 |
| 26 /** @constructor */ |
| 27 function Class() { |
| 28 /** @param {number} num */ |
| 29 this.needsNumber = function(num) {}; |
| 30 } |
| 31 |
| 32 cr.addSingletonGetter(Class); |
| 33 Class.getInstance().needsNumber("wrong type"); |
| 34 """ |
| 35 expected_chunk = "ERROR - actual parameter 1 of Class.needsNumber does not m
atch formal parameter" |
| 36 |
| 37 file_path = "/script.js" |
| 38 FileCache._cache[file_path] = file_content |
| 39 _, output = self._checker.check(file_path) |
| 40 |
| 41 self.assertTrue(expected_chunk in output, |
| 42 msg="%s\n\nExpected chunk: \n%s\n\nOutput:\n%s\n" % ( |
| 43 "getInstance", expected_chunk, output)) |
| 44 |
| 45 |
| 46 if __name__ == "__main__": |
| 47 unittest.main() |
OLD | NEW |