Bill Wendling | 7d62345 | 2015-03-18 13:36:07 -0700 | [diff] [blame] | 1 | # Copyright 2015 Google Inc. All Rights Reserved. |
| 2 | # |
| 3 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | # you may not use this file except in compliance with the License. |
| 5 | # You may obtain a copy of the License at |
| 6 | # |
| 7 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | # |
| 9 | # Unless required by applicable law or agreed to in writing, software |
| 10 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | # See the License for the specific language governing permissions and |
| 13 | # limitations under the License. |
| 14 | """Tests for yapf.format_token.""" |
| 15 | |
| 16 | import unittest |
| 17 | |
| 18 | from lib2to3 import pytree |
| 19 | from lib2to3.pgen2 import token |
| 20 | from yapf.yapflib import format_token |
| 21 | |
| 22 | |
| 23 | class FormatTokenTest(unittest.TestCase): |
| 24 | |
| 25 | def testSimple(self): |
| 26 | tok = format_token.FormatToken(pytree.Leaf(token.STRING, "'hello world'")) |
| 27 | self.assertEqual("FormatToken(name=STRING, value='hello world')", str(tok)) |
| 28 | self.assertTrue(tok.is_string) |
| 29 | |
| 30 | tok = format_token.FormatToken(pytree.Leaf(token.COMMENT, "# A comment")) |
| 31 | self.assertEqual("FormatToken(name=COMMENT, value=# A comment)", str(tok)) |
| 32 | self.assertTrue(tok.is_comment) |
| 33 | |
| 34 | |
Bill Wendling | 7d62345 | 2015-03-18 13:36:07 -0700 | [diff] [blame] | 35 | if __name__ == "__main__": |
| 36 | unittest.main() |