Skip to content

Commit

Permalink
fix(config_compiler): support creating list in-place by __patch and _…
Browse files Browse the repository at this point in the history
…_merge
  • Loading branch information
lotem committed Apr 24, 2018
1 parent 253d8d1 commit 0784eb0
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
8 changes: 8 additions & 0 deletions data/test/config_merge_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,11 @@ merge_tree:
zerg:
# overwrite existing list
ground_units: []

create_list_with_inplace_patch:
# map node without data key-value (exclude compiler directives) can be converted to list
all_ground_units:
__patch:
- __append: [scv, marine, firebat, vulture, tank]
- __append: {__include: starcraft/protoss/ground_units}
- __append: {__include: starcraft/zerg/ground_units}
9 changes: 7 additions & 2 deletions src/rime/config/config_compiler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,13 @@ static bool AppendToList(an<ConfigItemRef> target, an<ConfigList> list) {
return false;
auto existing_list = As<ConfigList>(**target);
if (!existing_list) {
LOG(ERROR) << "trying to append list to other value";
return false;
if (!(**target)->empty()) {
LOG(ERROR) << "trying to append list to incompatible node type";
return false;
}
// convert empty node (usually map with only compiler directives) to list;
// refer to test case RimeConfigMergeTest.CreateListWithInplacePatch
existing_list = target->AsList();
}
if (list->empty())
return true;
Expand Down
6 changes: 6 additions & 0 deletions test/config_compiler_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,12 @@ class RimeConfigCircularDependencyTest : public RimeConfigCompilerTestBase {
}
};

TEST_F(RimeConfigMergeTest, CreateListWithInplacePatch) {
const string& prefix = "create_list_with_inplace_patch/";
EXPECT_TRUE(config_->IsList(prefix + "all_ground_units"));
EXPECT_EQ(16, config_->GetListSize(prefix + "all_ground_units"));
}

TEST_F(RimeConfigCircularDependencyTest, BestEffortResolution) {
const string& prefix = "test/";
EXPECT_TRUE(config_->IsNull(prefix + "__patch"));
Expand Down

0 comments on commit 0784eb0

Please sign in to comment.