|
| 1 | +"Unit tests for //internal/common:preserve_legacy_templated_args.bzl" |
| 2 | + |
| 3 | +load("@bazel_skylib//lib:unittest.bzl", "asserts", "unittest") |
| 4 | +load("//internal/common:preserve_legacy_templated_args.bzl", "preserve_legacy_templated_args") |
| 5 | + |
| 6 | +def _impl(ctx): |
| 7 | + env = unittest.begin(ctx) |
| 8 | + |
| 9 | + conversions = { |
| 10 | + "$": "$$", |
| 11 | + "$$": "$$", |
| 12 | + "$$$$(BAR)": "$$$$(BAR)", |
| 13 | + "$$(": "$$(", |
| 14 | + "$$(BAR)": "$$(BAR)", |
| 15 | + "$$(rlocation foobar)": "$$(rlocation foobar)", |
| 16 | + "$$(rlocation foobar)$$(rlocation foobar)": "$$(rlocation foobar)$$(rlocation foobar)", |
| 17 | + "$(": "$(", |
| 18 | + "$(BAR)": "$(BAR)", |
| 19 | + "$(rlocation foobar)": "$$(rlocation foobar)", |
| 20 | + "$(rlocation foobar)$(rlocation foobar)": "$$(rlocation foobar)$$(rlocation foobar)", |
| 21 | + "$(rlocation! foobar)": "$(rlocation! foobar)", |
| 22 | + "$(rlocation! foobar)$(rlocation! foobar)": "$(rlocation! foobar)$(rlocation! foobar)", |
| 23 | + } |
| 24 | + |
| 25 | + for key in conversions: |
| 26 | + asserts.equals(env, "%s" % conversions[key], preserve_legacy_templated_args("%s" % key)) |
| 27 | + asserts.equals(env, " %s " % conversions[key], preserve_legacy_templated_args(" %s " % key)) |
| 28 | + asserts.equals(env, "%s %s" % (conversions[key], conversions[key]), preserve_legacy_templated_args("%s %s" % (key, key))) |
| 29 | + asserts.equals(env, " %s %s " % (conversions[key], conversions[key]), preserve_legacy_templated_args(" %s %s " % (key, key))) |
| 30 | + asserts.equals(env, "a%sb%sc" % (conversions[key], conversions[key]), preserve_legacy_templated_args("a%sb%sc" % (key, key))) |
| 31 | + |
| 32 | + return unittest.end(env) |
| 33 | + |
| 34 | +preserve_legacy_templated_args_test = unittest.make( |
| 35 | + impl = _impl, |
| 36 | + attrs = {}, |
| 37 | +) |
| 38 | + |
| 39 | +def preserve_legacy_templated_args_test_suite(): |
| 40 | + unittest.suite("preserve_legacy_templated_args_tests", preserve_legacy_templated_args_test) |
0 commit comments