android_webview
apps
ash
base
build
build_overrides
buildtools
cc
chrome
chromecast
chromeos
clank
codelabs
components
content
crypto
dbus
device
docs
extensions
fuchsia_web
gin
google_apis
gpu
headless
infra
internal
ios
ios_internal
ipc
media
mojo
native_client
native_client_sdk
net
pdf
ppapi
printing
remoting
rlz
sandbox
services
signing_keys
skia
sql
storage
styleguide
testing
third_party
tools
accessibility
aggregation_service
android
binary_size
bisect
bisect_repackage
captured_sites
cast3p
cfi
check_ecs_deps
checkbins
checklicenses
checkperms
checkteamtags
chrome_extensions
chromeos
clang
code_cache_generator
code_coverage
codeql
compile_test
cr
crates
crbug
cros
cygprofile
determinism
disable_tests
dromaeo_benchmark_runner
dump_process_memory
emacs
find_runtime_symbols
flags
flakiness
fuchsia
gdb
generate_library_loader
generate_shim_headers
generate_stubs
get_asan_chrome
get_swarming_logs
git
gn
grd
grit
gritsettings
idl_parser
imagediff
infra
interactive_ui_tests
ipc_fuzzer
json_comment_eater
json_data_generator
json_schema_compiler
json_to_struct
PRESUBMIT.py
aggregation.py
aggregation_test.py
class_generator.py
element_generator.py
element_generator_test.py
java_element_generator.py
json_to_struct.gni
json_to_struct.py
struct_generator.py
struct_generator_test.py
l10n
licenses
linux
lldb
mac
mb
md_browser
media_engagement_preload
memory
metrics
msan
nix
nocompile
oobe
origin_trials
perf
perfbot-analysis
pgo
pixel_test
polymer
privacy_budget
profiling
protoc_wrapper
python
real_world_impact
resources
rust
search_engine_choice
site_compare
strict_enum_value_checker
style_variable_generator
sublime
symsrc
traceline
tracing
traffic_annotation
translation
typescript
ubsan
usb_gadget
utr
v8_context_snapshot
valgrind
variations
vim
visual_debugger
vscode
warning_analysis
web_bluetooth
web_dev_style
whats_new
win
.gitignore
.style.yapf
DEPS
DIR_METADATA
OWNERS
PRESUBMIT.py
README.md
add_header.py
add_header_test.py
apply_cpplint_header_guard.py
auto-nav.py
autotest.py
bash-completion
bisect-builds.py
bisect_test.py
boilerplate.py
buildstate.bat
buildstate.py
check_git_config.py
check_grd_for_unused_strings.py
clang-format-js
diagnose-me.py
download_optimization_profile.py
hresult_to_enum.py
include_tracer.py
ipc_messages_log.py
make_gtest_filter.py
make_gtest_filter_test.py
mojo_messages_log.py
multi_process_rss.py
omahaproxy.py
perry.py
remove_stale_files.py
remove_stale_pyc_files.py
roll_webgl_conformance.py
run-swarmed.py
sample_clang_tidy_results.py
sort_sources.py
uberblame.py
unused-symbols-report.py
update_pgo_profiles.py
yes_no.py
ui
url
v8
webkit
.clang-format
.clang-tidy
.clangd
.git-blame-ignore-revs
.gitallowed
.gitattributes
.gitignore
.gitmodules
.gn
.mailmap
.rustfmt.toml
.vpython3
.yapfignore
ATL_OWNERS
AUTHORS
BUILD.gn
CODE_OF_CONDUCT.md
CPPLINT.cfg
CRYPTO_OWNERS
DEPS
DIR_METADATA
LICENSE
LICENSE.chromium_os
OWNERS
PRESUBMIT.py
PRESUBMIT_test.py
PRESUBMIT_test_mocks.py
README.md
WATCHLISTS
codereview.settings

This change permits maps to include element aliases. Bug: b:404850650 Change-Id: I9d313426f4a194488adf00d12b6105f2ee75d079 See: https://crrev.com/c/637357 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6378804 Reviewed-by: Dirk Pranke <dpranke@google.com> Commit-Queue: Tomasz Wiszkowski <ender@google.com> Cr-Commit-Position: refs/heads/main@{#1436117}
190 lines
5.2 KiB
Python
Executable File
190 lines
5.2 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
# Copyright 2025 The Chromium Authors
|
|
# Use of this source code is governed by a BSD-style license that can be
|
|
# found in the LICENSE file.
|
|
|
|
from aggregation import AggregationKind, AggregationDetails, GetAggregationDetails
|
|
import unittest
|
|
|
|
|
|
class AggregationTest(unittest.TestCase):
|
|
|
|
def testDefaults(self):
|
|
self.assertEqual(GetAggregationDetails({}),
|
|
AggregationDetails(AggregationKind.NONE, None, True, {}))
|
|
|
|
def testGenerateOldStyleArray(self):
|
|
self.assertEqual(
|
|
GetAggregationDetails({
|
|
"elements": {},
|
|
"generate_array": {
|
|
"array_name": "TestArray"
|
|
}
|
|
}), AggregationDetails(AggregationKind.ARRAY, "TestArray", True, {}))
|
|
|
|
def testGenerateArray(self):
|
|
self.assertEqual(
|
|
GetAggregationDetails({
|
|
"elements": {},
|
|
"aggregation": {
|
|
"type": "array",
|
|
"name": "TestArray"
|
|
}
|
|
}), AggregationDetails(AggregationKind.ARRAY, "TestArray", True, {}))
|
|
|
|
def testGenerateArrayAndHideElements(self):
|
|
self.assertEqual(
|
|
GetAggregationDetails({
|
|
"elements": {},
|
|
"aggregation": {
|
|
"type": "array",
|
|
"name": "TestArray",
|
|
"export_items": False
|
|
}
|
|
}), AggregationDetails(AggregationKind.ARRAY, "TestArray", False, {}))
|
|
|
|
def testGenerateMap(self):
|
|
self.assertEqual(
|
|
GetAggregationDetails({
|
|
"elements": {},
|
|
"aggregation": {
|
|
"type": "map",
|
|
"name": "TestMap"
|
|
}
|
|
}), AggregationDetails(AggregationKind.MAP, "TestMap", True, {}))
|
|
|
|
def testGenerateMapAndHideElements(self):
|
|
self.assertEqual(
|
|
GetAggregationDetails({
|
|
"elements": {},
|
|
"aggregation": {
|
|
"type": "map",
|
|
"name": "TestMap",
|
|
"export_items": False
|
|
}
|
|
}), AggregationDetails(AggregationKind.MAP, "TestMap", False, {}))
|
|
|
|
def testGetSortedArrayElements(self):
|
|
aggregation = GetAggregationDetails({
|
|
"elements": {
|
|
"c": [],
|
|
"d": [],
|
|
"b": [],
|
|
"a": []
|
|
},
|
|
"aggregation": {
|
|
"type": "array",
|
|
"name": "TestMap"
|
|
}
|
|
})
|
|
|
|
self.assertEqual(["a", "b", "c", "d"], aggregation.GetSortedArrayElements())
|
|
|
|
def testGetSortedMapElementsNoAliases(self):
|
|
aggregation = GetAggregationDetails({
|
|
"elements": {
|
|
"c": [],
|
|
"d": [],
|
|
"b": [],
|
|
"a": []
|
|
},
|
|
"aggregation": {
|
|
"type": "map",
|
|
"name": "TestMap"
|
|
}
|
|
})
|
|
|
|
# Expect the result to be sorted as well.
|
|
self.assertEqual([["a", "a"], ["b", "b"], ["c", "c"], ["d", "d"]],
|
|
aggregation.GetSortedMapElements())
|
|
|
|
def testGetSortedMapElementsWithAliases(self):
|
|
aggregation = GetAggregationDetails({
|
|
"elements": {
|
|
"c": [],
|
|
"d": [],
|
|
},
|
|
"aggregation": {
|
|
"type": "map",
|
|
"name": "TestMap",
|
|
"map_aliases": {
|
|
"a": "d",
|
|
"b": "c",
|
|
"e": "c",
|
|
}
|
|
}
|
|
})
|
|
|
|
# Expect the result to be sorted as well.
|
|
self.assertEqual(
|
|
[["a", "d"], ["b", "c"], ["c", "c"], ["d", "d"], ["e", "c"]],
|
|
aggregation.GetSortedMapElements())
|
|
|
|
def testGenerateMapWithConflictingAliases(self):
|
|
self.assertRaisesRegex(
|
|
Exception, "Alias `b` already defined as element.",
|
|
lambda: GetAggregationDetails({
|
|
"elements": {
|
|
"a": [],
|
|
"b": [],
|
|
},
|
|
"aggregation": {
|
|
"type": "map",
|
|
"name": "TestMap",
|
|
"map_aliases": {
|
|
"b": "a"
|
|
}
|
|
}
|
|
}))
|
|
|
|
def testGenerateMapWithIncorrectAliases(self):
|
|
self.assertRaisesRegex(
|
|
Exception, "Aliased element `b` does not exist.",
|
|
lambda: GetAggregationDetails({
|
|
"elements": {
|
|
"a": [],
|
|
},
|
|
"aggregation": {
|
|
"type": "map",
|
|
"name": "TestMap",
|
|
"map_aliases": {
|
|
"b": "a",
|
|
"c": "b"
|
|
}
|
|
}
|
|
}))
|
|
|
|
def testUnrecognizedAggregationType(self):
|
|
self.assertRaisesRegex(
|
|
Exception, "'collection' is not a valid AggregationKind",
|
|
lambda: GetAggregationDetails({
|
|
"elements": {},
|
|
"aggregation": {
|
|
"type": "collection",
|
|
}
|
|
}))
|
|
|
|
def testArrayMustHaveAName(self):
|
|
self.assertRaisesRegex(
|
|
Exception, "Aggregation container needs a `name`.",
|
|
lambda: GetAggregationDetails({
|
|
"elements": {},
|
|
"aggregation": {
|
|
"type": "array",
|
|
}
|
|
}))
|
|
|
|
def testMapMustHaveAName(self):
|
|
self.assertRaisesRegex(
|
|
Exception, "Aggregation container needs a `name`.",
|
|
lambda: GetAggregationDetails({
|
|
"elements": {},
|
|
"aggregation": {
|
|
"type": "map",
|
|
}
|
|
}))
|
|
|
|
|
|
if __name__ == '__main__':
|
|
unittest.main()
|