<reponame>zealoussnow/chromium<filename>third_party/polymer/v1_0/rgbify_hex_vars_test.py
#!/usr/bin/env python
# Copyright 2019 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

import rgbify_hex_vars
import unittest


class RgbifyHexVarsTest(unittest.TestCase):
  def checkProduces(self, content, expected, **kwargs):
    actual = rgbify_hex_vars.Rgbify(content, **kwargs)
    self.assertEquals(actual, expected)

  def checkSame(self, content):
    self.checkProduces(content, content)

  def testPrefixFiltering(self):
    self.checkProduces('--google-blue-500: #010203;\n' +
                       '--paper-green-300: #445566;',
                       '--google-blue-500-rgb: 1, 2, 3;\n' +
                       '--google-blue-500: #010203;\n' +
                       '--paper-green-300: #445566;',
                       prefix='google')

  def testReplace(self):
    self.checkProduces('--var-name: #01020f;',
                       '--var-name-rgb: 1, 2, 15;  /* #01020f */\n' +
                       '--var-name: rgb(var(--var-name-rgb));',
                       replace=True)

  def testStuffToBeIgnored(self):
    self.checkSame('#bada55 { color: red; }')
    self.checkSame('--var-name: rgb(1, 2, 3);')
    self.checkSame('--var-name: rgba(1, 2, 3, .5);')

  def testValidHexVars(self):
    self.checkProduces('--color-var: #010203;',
                       '--color-var-rgb: 1, 2, 3;\n' +
                       '--color-var: #010203;')
    self.checkProduces('--hi: #102030;',
                       '--hi-rgb: 16, 32, 48;\n' +
                       '--hi: #102030;')


if __name__ == '__main__':
  unittest.main()

#!/usr/bin/env python
# Copyright 2019 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

import rgbify_hex_vars
import unittest


class RgbifyHexVarsTest(unittest.TestCase):
  def checkProduces(self, content, expected, **kwargs):
    actual = rgbify_hex_vars.Rgbify(content, **kwargs)
    self.assertEquals(actual, expected)

  def checkSame(self, content):
    self.checkProduces(content, content)

  def testPrefixFiltering(self):
    self.checkProduces('--google-blue-500: #010203;\n' +
                       '--paper-green-300: #445566;',
                       '--google-blue-500-rgb: 1, 2, 3;\n' +
                       '--google-blue-500: #010203;\n' +
                       '--paper-green-300: #445566;',
                       prefix='google')

  def testReplace(self):
    self.checkProduces('--var-name: #01020f;',
                       '--var-name-rgb: 1, 2, 15;  /* #01020f */\n' +
                       '--var-name: rgb(var(--var-name-rgb));',
                       replace=True)

  def testStuffToBeIgnored(self):
    self.checkSame('#bada55 { color: red; }')
    self.checkSame('--var-name: rgb(1, 2, 3);')
    self.checkSame('--var-name: rgba(1, 2, 3, .5);')

  def testValidHexVars(self):
    self.checkProduces('--color-var: #010203;',
                       '--color-var-rgb: 1, 2, 3;\n' +
                       '--color-var: #010203;')
    self.checkProduces('--hi: #102030;',
                       '--hi-rgb: 16, 32, 48;\n' +
                       '--hi: #102030;')


if __name__ == '__main__':
  unittest.main()
#!/usr/bin/env python # Copyright 2019 The Chromium Authors. All rights reserved. # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. #010203;\n' + #445566;', #010203;\n' + #445566;', #01020f;', #01020f */\n' + #010203;', #010203;') #102030;', #102030;')