OLD | NEW |
1 # Copyright 2014 The Chromium Authors. All rights reserved. | 1 # Copyright 2014 The Chromium Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 import StringIO | 5 import StringIO |
6 import unittest | 6 import unittest |
7 | 7 |
8 from webkitpy.common.system.systemhost_mock import MockSystemHost | 8 from webkitpy.common.system.systemhost_mock import MockSystemHost |
9 from webkitpy.formatter.main import main | 9 from webkitpy.formatter.main import main |
10 | 10 |
(...skipping 22 matching lines...) Expand all Loading... |
33 "because it's important to test quoting"] | 33 "because it's important to test quoting"] |
34 except Exception as e: | 34 except Exception as e: |
35 pass | 35 pass |
36 ''' | 36 ''' |
37 | 37 |
38 | 38 |
39 EXPECTED_CHROMIUM_OUTPUT = ''' | 39 EXPECTED_CHROMIUM_OUTPUT = ''' |
40 def foo(): | 40 def foo(): |
41 """triple-quoted docstring""" | 41 """triple-quoted docstring""" |
42 try: | 42 try: |
43 bar = "bar" | 43 bar = 'bar' |
44 long_list = [ | 44 long_list = [ |
45 "this is a list of strings that should be wrapped", | 45 'this is a list of strings that should be wrapped', |
46 "and consistently quoted"] | 46 'and consistently quoted'] |
47 longer_list = [ | 47 longer_list = [ |
48 "this is a list of strings that should be wrapped", | 48 'this is a list of strings that should be wrapped', |
49 "and consistently quoted", | 49 'and consistently quoted', |
50 "because it's important to test quoting"] | 50 "because it's important to test quoting"] |
51 except Exception as e: | 51 except Exception as e: |
52 pass | 52 pass |
53 ''' | 53 ''' |
54 | 54 |
| 55 EXPECTED_ONLY_DOUBLE_QUOTED_OUTPUT = ''' |
| 56 def foo(): |
| 57 """triple-quoted docstring""" |
| 58 try: |
| 59 bar = "bar" |
| 60 long_list = ["this is a list of strings that should be wrapped", "and co
nsistently quoted"] |
| 61 longer_list = ["this is a list of strings that should be wrapped", "and
consistently quoted", "because it's important to test quoting"] |
| 62 except Exception, e: |
| 63 pass |
| 64 ''' |
| 65 |
55 | 66 |
56 class TestMain(unittest.TestCase): | 67 class TestMain(unittest.TestCase): |
57 maxDiff = 4096 | 68 maxDiff = 4096 |
58 | 69 |
59 def test_stdin_blink(self): | |
60 host = MockSystemHost() | |
61 host.stdin = StringIO.StringIO(ACTUAL_INPUT) | |
62 main(host, ['-']) | |
63 self.assertMultiLineEqual(host.stdout.getvalue(), EXPECTED_BLINK_OUTPUT) | |
64 | |
65 def test_stdin_chromium(self): | |
66 host = MockSystemHost() | |
67 host.stdin = StringIO.StringIO(ACTUAL_INPUT) | |
68 main(host, ['--chromium', '-']) | |
69 self.assertMultiLineEqual(host.stdout.getvalue(), EXPECTED_CHROMIUM_OUTP
UT) | |
70 | |
71 def test_files_blink(self): | 70 def test_files_blink(self): |
72 host = MockSystemHost() | 71 host = MockSystemHost() |
73 host.filesystem.files = { | 72 host.filesystem.files = { |
74 'test.py': ACTUAL_INPUT} | 73 'test.py': ACTUAL_INPUT} |
75 main(host, ['test.py']) | 74 main(host, ['test.py']) |
76 self.assertEqual(host.filesystem.files, { | 75 self.assertEqual(host.filesystem.files, { |
77 'test.py': EXPECTED_BLINK_OUTPUT, | 76 'test.py': EXPECTED_BLINK_OUTPUT, |
78 'test.py.bak': ACTUAL_INPUT}) | 77 'test.py.bak': ACTUAL_INPUT}) |
79 | 78 |
80 def test_files_blink_no_backup(self): | 79 def test_files_blink_no_backup(self): |
81 host = MockSystemHost() | 80 host = MockSystemHost() |
82 host.filesystem.files = { | 81 host.filesystem.files = { |
83 'test.py': ACTUAL_INPUT} | 82 'test.py': ACTUAL_INPUT} |
84 main(host, ['--no-backups', 'test.py']) | 83 main(host, ['--no-backups', 'test.py']) |
85 self.assertEqual(host.filesystem.files, { | 84 self.assertEqual(host.filesystem.files, { |
86 'test.py': EXPECTED_BLINK_OUTPUT}) | 85 'test.py': EXPECTED_BLINK_OUTPUT}) |
| 86 |
| 87 def test_stdin_blink(self): |
| 88 host = MockSystemHost() |
| 89 host.stdin = StringIO.StringIO(ACTUAL_INPUT) |
| 90 main(host, ['-']) |
| 91 self.assertMultiLineEqual(host.stdout.getvalue(), EXPECTED_BLINK_OUTPUT) |
| 92 |
| 93 def test_stdin_chromium(self): |
| 94 host = MockSystemHost() |
| 95 host.stdin = StringIO.StringIO(ACTUAL_INPUT) |
| 96 main(host, ['--chromium', '-']) |
| 97 self.assertMultiLineEqual(host.stdout.getvalue(), EXPECTED_CHROMIUM_OUTP
UT) |
| 98 |
| 99 def test_stdin_no_changes(self): |
| 100 host = MockSystemHost() |
| 101 host.stdin = StringIO.StringIO(ACTUAL_INPUT) |
| 102 main(host, ['--no-autopep8', '--leave-strings-alone', '-']) |
| 103 self.assertMultiLineEqual(host.stdout.getvalue(), ACTUAL_INPUT) |
| 104 |
| 105 def test_stdin_only_double_quoting(self): |
| 106 host = MockSystemHost() |
| 107 host.stdin = StringIO.StringIO(ACTUAL_INPUT) |
| 108 main(host, ['--no-autopep8', '--double-quote-strings', '-']) |
| 109 self.assertMultiLineEqual(host.stdout.getvalue(), EXPECTED_ONLY_DOUBLE_Q
UOTED_OUTPUT) |
OLD | NEW |