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
3 # found in the LICENSE file.
8 from webkitpy.common.system.systemhost_mock import MockSystemHost
9 from webkitpy.formatter.main import main
14 """triple-quoted docstring"""
17 long_list = ['this is a list of strings that should be wrapped', "and consistently quoted"]
18 longer_list = ['this is a list of strings that should be wrapped', "and consistently quoted", "because it's important to test quoting"]
24 EXPECTED_BLINK_OUTPUT = '''
26 """triple-quoted docstring"""
29 long_list = ['this is a list of strings that should be wrapped', 'and consistently quoted']
31 'this is a list of strings that should be wrapped',
32 'and consistently quoted',
33 "because it's important to test quoting"]
34 except Exception as e:
39 EXPECTED_CHROMIUM_OUTPUT = '''
41 """triple-quoted docstring"""
45 'this is a list of strings that should be wrapped',
46 'and consistently quoted']
48 'this is a list of strings that should be wrapped',
49 'and consistently quoted',
50 "because it's important to test quoting"]
51 except Exception as e:
55 EXPECTED_ONLY_DOUBLE_QUOTED_OUTPUT = '''
57 """triple-quoted docstring"""
60 long_list = ["this is a list of strings that should be wrapped", "and consistently quoted"]
61 longer_list = ["this is a list of strings that should be wrapped", "and consistently quoted", "because it's important to test quoting"]
67 class TestMain(unittest.TestCase):
70 def test_files_blink(self):
71 host = MockSystemHost()
72 host.filesystem.files = {
73 'test.py': ACTUAL_INPUT}
74 main(host, ['test.py'])
75 self.assertEqual(host.filesystem.files, {
76 'test.py': EXPECTED_BLINK_OUTPUT,
77 'test.py.bak': ACTUAL_INPUT})
79 def test_files_blink_no_backup(self):
80 host = MockSystemHost()
81 host.filesystem.files = {
82 'test.py': ACTUAL_INPUT}
83 main(host, ['--no-backups', 'test.py'])
84 self.assertEqual(host.filesystem.files, {
85 'test.py': EXPECTED_BLINK_OUTPUT})
87 def test_stdin_blink(self):
88 host = MockSystemHost()
89 host.stdin = StringIO.StringIO(ACTUAL_INPUT)
91 self.assertMultiLineEqual(host.stdout.getvalue(), EXPECTED_BLINK_OUTPUT)
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_OUTPUT)
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)
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_QUOTED_OUTPUT)