Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(228)

Unified Diff: third_party/closure_linter/closure_linter/runner_test.py

Issue 411243002: closure_linter: 2.3.4 => 2.3.14 (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: remove checker Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/closure_linter/closure_linter/runner_test.py
diff --git a/third_party/closure_linter/closure_linter/runner_test.py b/third_party/closure_linter/closure_linter/runner_test.py
new file mode 100644
index 0000000000000000000000000000000000000000..da5857d30950f6fa1f8dec8414f074fe94d2ec4d
--- /dev/null
+++ b/third_party/closure_linter/closure_linter/runner_test.py
@@ -0,0 +1,101 @@
+#!/usr/bin/env python
+#
+# Copyright 2008 The Closure Linter Authors. All Rights Reserved.
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS-IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+"""Unit tests for the runner module."""
+
+__author__ = ('nnaze@google.com (Nathan Naze)')
+
+import StringIO
+
+
+import mox
+
+
+import unittest as googletest
+
+from closure_linter import errors
+from closure_linter import runner
+from closure_linter.common import error
+from closure_linter.common import errorhandler
+from closure_linter.common import tokens
+
+
+class LimitedDocTest(googletest.TestCase):
+
+ def testIsLimitedDocCheck(self):
+ self.assertTrue(runner._IsLimitedDocCheck('foo_test.js', ['_test.js']))
+ self.assertFalse(runner._IsLimitedDocCheck('foo_bar.js', ['_test.js']))
+
+ self.assertTrue(runner._IsLimitedDocCheck(
+ 'foo_moo.js', ['moo.js', 'quack.js']))
+ self.assertFalse(runner._IsLimitedDocCheck(
+ 'foo_moo.js', ['woof.js', 'quack.js']))
+
+
+class RunnerTest(googletest.TestCase):
+
+ def setUp(self):
+ self.mox = mox.Mox()
+
+ def testRunOnMissingFile(self):
+ mock_error_handler = self.mox.CreateMock(errorhandler.ErrorHandler)
+
+ def ValidateError(err):
+ return (isinstance(err, error.Error) and
+ err.code is errors.FILE_NOT_FOUND and
+ err.token is None)
+
+ mock_error_handler.HandleFile('does_not_exist.js', None)
+ mock_error_handler.HandleError(mox.Func(ValidateError))
+ mock_error_handler.FinishFile()
+
+ self.mox.ReplayAll()
+
+ runner.Run('does_not_exist.js', mock_error_handler)
+
+ self.mox.VerifyAll()
+
+ def testBadTokenization(self):
+ mock_error_handler = self.mox.CreateMock(errorhandler.ErrorHandler)
+
+ def ValidateError(err):
+ return (isinstance(err, error.Error) and
+ err.code is errors.FILE_IN_BLOCK and
+ err.token.string == '}')
+
+ mock_error_handler.HandleFile('foo.js', mox.IsA(tokens.Token))
+ mock_error_handler.HandleError(mox.Func(ValidateError))
+ mock_error_handler.HandleError(mox.IsA(error.Error))
+ mock_error_handler.FinishFile()
+
+ self.mox.ReplayAll()
+
+ source = StringIO.StringIO(_BAD_TOKENIZATION_SCRIPT)
+ runner.Run('foo.js', mock_error_handler, source)
+
+ self.mox.VerifyAll()
+
+
+_BAD_TOKENIZATION_SCRIPT = """
+function foo () {
+ var a = 3;
+ var b = 2;
+ return b + a; /* Comment not closed
+}
+"""
+
+
+if __name__ == '__main__':
+ googletest.main()
« no previous file with comments | « third_party/closure_linter/closure_linter/runner.py ('k') | third_party/closure_linter/closure_linter/scopeutil.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698