Files
regorus/tests/azure_policy_builtins/cases/date_time_add.yaml
Anand Krishnamoorthi 4c92fb4d92 feat(azure_policy): test runner, compiler fixes, and example program (#700)
Adds the YAML test runner that exercises the companion test data PRs, plus
several compiler fixes surfaced during testing:

- Removed parameter register caching that produced wrong results inside
  short-circuiting allOf/anyOf blocks; added literal-index caching for
  parameter defaults to avoid repeated O(n) literal-table scans
- Simplified cross-resource effect details to only emit roleDefinitionIds
  and type (deployment templates are not evaluated for compliance)
- Replaced guid/uniqueString builtins with clear "unsupported" errors
- Normalized datetime output to ISO 8601 with Z suffix
- Added azure_policy parser MAX_COL constant (8192) for long template
  expressions, keeping the global DEFAULT_MAX_COL at 1024
- Added rvm to azure_policy feature dependencies since the compiler
  targets RVM bytecode

Also restructures the example binary into examples/regorus/ with new
azure-policy-eval and azure-policy-aliases subcommands, adds C# alias
normalization tests, and documents Azure Policy support in the README.

Signed-off-by: Anand Krishnamoorthi <anakrish@microsoft.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-04-30 13:02:37 -05:00

170 lines
5.3 KiB
YAML

# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
# Tests for azure.policy.fn.date_time_add
builtin: azure.policy.fn.date_time_add
cases:
- note: add_one_day
args: ["2024-01-15T12:00:00Z", "P1D"]
want: "2024-01-16T12:00:00Z"
- note: add_one_hour
args: ["2024-01-15T12:00:00Z", "PT1H"]
want: "2024-01-15T13:00:00Z"
- note: add_thirty_minutes
args: ["2024-01-15T12:00:00Z", "PT30M"]
want: "2024-01-15T12:30:00Z"
- note: add_negative_one_day
args: ["2024-01-15T12:00:00Z", "-P1D"]
want: "2024-01-14T12:00:00Z"
- note: add_complex_duration
args: ["2024-01-15T12:00:00Z", "P1DT2H30M"]
want: "2024-01-16T14:30:00Z"
- note: add_one_year_approx
args: ["2024-01-01T00:00:00Z", "P1Y"]
want: "2024-12-31T00:00:00Z"
- note: add_zero_duration
args: ["2024-06-15T10:30:00Z", "PT0S"]
want: "2024-06-15T10:30:00Z"
- note: invalid_base_datetime
args: ["not-a-date", "P1D"]
want_undefined: true
- note: invalid_duration
args: ["2024-01-15T12:00:00Z", "invalid"]
want_undefined: true
# Input without explicit timezone is treated as UTC; outputs are
# normalized to ISO 8601 with an explicit timezone (`Z` for UTC).
- note: datetime_without_timezone
args: ["2024-01-15T12:00:00", "P1D"]
want: "2024-01-16T12:00:00Z"
- note: add_one_week
args: ["2024-01-15T00:00:00Z", "P1W"]
want: "2024-01-22T00:00:00Z"
# Azure Policy normalizes all output to ISO 8601 T-separated format with
# explicit timezone, regardless of input format.
- note: space_separated_datetime
args: ["2020-04-07 14:55:59", "P3D"]
want: "2020-04-10T14:55:59Z"
- note: space_separated_datetime_with_z
args: ["2020-04-07 14:55:59Z", "P3D"]
want: "2020-04-10T14:55:59Z"
- note: space_separated_datetime_with_offset
args: ["2020-04-07 14:55:59+05:30", "P1D"]
want: "2020-04-08T14:55:59+05:30"
- note: output_format_date_only
args: ["2020-04-07T14:55:59Z", "P3Y2M", "yyyy-MM-dd"]
want: "2023-06-06"
- note: output_format_custom
args: ["2024-01-15T12:00:00Z", "PT1H", "yyyy-MM-dd HH:mm:ss"]
want: "2024-01-15 13:00:00"
- note: output_format_with_k_utc
args: ["2024-01-15T12:00:00Z", "P0D", "yyyy-MM-ddTHH:mm:ssK"]
want: "2024-01-15T12:00:00Z"
# Standard .NET format specifiers
- note: output_standard_format_d
args: ["2024-01-15T12:30:00Z", "P1D", "d"]
want: "01/16/2024"
- note: output_standard_format_G
args: ["2024-01-15T12:30:00Z", "PT1H", "G"]
want: "01/15/2024 13:30:00"
- note: output_standard_format_o
args: ["2024-01-15T12:00:00Z", "P0D", "o"]
want: "2024-01-15T12:00:00.0000000Z"
- note: output_standard_format_o_with_nanos
args: ["2024-01-15T12:00:00.123456700Z", "P0D", "o"]
want: "2024-01-15T12:00:00.1234567Z"
- note: output_standard_format_u
args: ["2024-01-15T12:00:00Z", "P0D", "u"]
want: "2024-01-15 12:00:00Z"
- note: output_standard_format_u_with_offset
args: ["2024-01-15T12:00:00+05:30", "P0D", "u"]
want: "2024-01-15 06:30:00Z"
# When no explicit output format is provided, datetime output is normalized
# to ISO 8601 T-separated form with timezone, regardless of input format.
# Explicit third-argument formats may intentionally produce other forms
# (for example, space-separated output). Fractional seconds are preserved
# when non-zero.
- note: roundtrip_iso_no_tz_with_frac
args: ["2024-01-15T12:00:00.123", "P0D"]
want: "2024-01-15T12:00:00.123Z"
- note: roundtrip_iso_no_tz_with_frac_add
args: ["2024-01-15T12:00:00.500", "P1D"]
want: "2024-01-16T12:00:00.500Z"
- note: roundtrip_space_no_tz_with_frac
args: ["2024-01-15 12:00:00.456", "P0D"]
want: "2024-01-15T12:00:00.456Z"
- note: roundtrip_space_z_with_frac
args: ["2024-01-15 12:00:00.789Z", "P0D"]
want: "2024-01-15T12:00:00.789Z"
- note: roundtrip_space_offset_with_frac
args: ["2024-01-15 12:00:00.123+05:30", "P0D"]
want: "2024-01-15T12:00:00.123+05:30"
- note: roundtrip_no_frac_stays_clean
args: ["2024-01-15T12:00:00", "P0D"]
want: "2024-01-15T12:00:00Z"
- note: roundtrip_rfc3339_utc_with_frac
args: ["2024-01-15T12:00:00.123Z", "P0D"]
want: "2024-01-15T12:00:00.123Z"
- note: roundtrip_rfc3339_offset_with_frac
args: ["2024-01-15T12:00:00.456+05:30", "P0D"]
want: "2024-01-15T12:00:00.456+05:30"
- note: roundtrip_rfc3339_utc_no_frac_stays_clean
args: ["2024-01-15T12:00:00Z", "P0D"]
want: "2024-01-15T12:00:00Z"
- note: roundtrip_rfc3339_explicit_zero_offset
args: ["2024-01-15T12:00:00+00:00", "P0D"]
want: "2024-01-15T12:00:00Z"
- note: roundtrip_rfc3339_explicit_zero_offset_with_frac
args: ["2024-01-15T12:00:00.500+00:00", "P0D"]
want: "2024-01-15T12:00:00.500Z"
# Unknown single-char format specifier is a real error
- note: unknown_format_specifier_q
args: ["2024-01-15T12:00:00Z", "P0D", "q"]
want_error: "unrecognised standard format specifier 'q'"
- note: output_standard_format_U
args: ["2024-01-15T12:00:00+05:30", "P0D", "U"]
want: "Monday, 15 January 2024 06:30:00"
- note: output_standard_format_s
args: ["2024-01-15T12:00:00Z", "P0D", "s"]
want: "2024-01-15T12:00:00"
- note: output_standard_format_R
args: ["2024-01-15T12:00:00+05:30", "P0D", "R"]
want: "Mon, 15 Jan 2024 06:30:00 GMT"