1# Copyright (c) 2015 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.
4
5import unittest
6
7from tracing_build.update_gypi import GypiFile
8
9
10class UpdateGypiTests(unittest.TestCase):
11
12  def setUp(self):
13    self.file_groups = ['group1', 'group2']
14
15  def testGypiTokenizer(self):
16    content = ("useless data\n'group1': [\n    <file list goes here>\n"
17               "    ]\nNote the four spaces before the ] above")
18    gypi_files = GypiFile(content, self.file_groups)
19    self.assertEqual(3, len(gypi_files._tokens))
20    self.assertEqual('plain', gypi_files._tokens[0].token_id)
21    self.assertEqual(
22        "useless data\n'group1': [\n", gypi_files._tokens[0].data)
23    self.assertEqual('group1', gypi_files._tokens[1].token_id)
24    self.assertEqual("    <file list goes here>\n", gypi_files._tokens[1].data)
25    self.assertEqual('plain', gypi_files._tokens[2].token_id)
26    self.assertEqual(
27        "    ]\nNote the four spaces before the ] above",
28        gypi_files._tokens[2].data)
29
30  def testGypiFileListBuilder(self):
31    gypi_file = GypiFile('', self.file_groups)
32    existing_list = ("    '/four/spaces/indent',\n'"
33                     "    '/five/spaces/but/only/first/line/matters',\n")
34    new_list = ['item1', 'item2', 'item3']
35    self.assertEqual(
36        "    'item1',\n    'item2',\n    'item3',\n",
37        gypi_file._GetReplacementListAsString(existing_list, new_list))
38