blob: 2966d3df2971c6af7e19ee5129b9b1a9b59e90ca [file] [log] [blame]
# Copyright 2022 The ChromiumOS Authors
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""Test the star module."""
import pytest
from chromite.format.formatters import star
@pytest.mark.parametrize(
# exp=None means input is already formatted to avoid having to repeat.
"data,exp",
(
("", None),
('workspace(name = "foo")\n', None),
('workspace(name="foo")\n', 'workspace(name = "foo")\n'),
),
)
def test_check_format(data, exp) -> None:
"""Verify inputs match expected outputs."""
if exp is None:
exp = data
assert exp == star.Data(data)
SPECIALIZATION_INPUT = """cc_library(deps=["z","x","y"],name="a123")"""
UNSPECIALIZED_OUTPUT = """cc_library(deps = ["z", "x", "y"], name = "a123")
"""
SPECIALIZED_OUTPUT = """cc_library(
name = "a123",
deps = [
"x",
"y",
"z",
],
)
"""
LOAD_PREFIX = """load("@rules_cc//cc:defs.bzl", "cc_library")
"""
@pytest.mark.parametrize(
"path,exp",
(
("config.star", UNSPECIALIZED_OUTPUT),
("BUILD", LOAD_PREFIX + SPECIALIZED_OUTPUT),
("BUILD.bazel", LOAD_PREFIX + SPECIALIZED_OUTPUT),
("WORKSPACE", SPECIALIZED_OUTPUT),
("WORKSPACE.bazel", SPECIALIZED_OUTPUT),
("defs.bzl", LOAD_PREFIX + UNSPECIALIZED_OUTPUT),
),
)
def test_path_specialization(path, exp) -> None:
assert star.Data(SPECIALIZATION_INPUT, path) == exp