Skip to content

Commit

Permalink
[config-derive] fix bug where multiple merge(strategy) fail with un…
Browse files Browse the repository at this point in the history
…parseable tokens

It was me, I forgot to add a semicolon when expanding a single field assignment. :face_palm:
  • Loading branch information
auguwu committed Jan 16, 2024
1 parent 6311ac4 commit 2e69ad1
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 2 deletions.
4 changes: 2 additions & 2 deletions crates/config-derive/src/expand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ fn gen_struct_field_assignment(field: &Field) -> Option<TokenStream> {

let name = field.ident.as_ref().expect("expected identifier");
Some(match first.strategy {
Some(path) => quote_spanned!(path.span()=> #path(&mut self.#name, other.#name)),
None => quote_spanned!(field.span()=> ::noelware_config::merge::Merge::merge(&mut self.#name, other.#name)),
Some(path) => quote_spanned!(path.span()=> #path(&mut self.#name, other.#name);),
None => quote_spanned!(field.span()=> ::noelware_config::merge::Merge::merge(&mut self.#name, other.#name);),
})
}
1 change: 1 addition & 0 deletions crates/config-derive/tests/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ fn ui() {
cases.compile_fail("./tests/ui/union.rs");
cases.compile_fail("./tests/ui/enum.rs");

cases.pass("./tests/ui/strategy_multi.rs");
cases.pass("./tests/ui/custom_strategy.rs");
cases.pass("./tests/ui/skip_test.rs");
cases.pass("./tests/ui/struct.rs");
Expand Down
47 changes: 47 additions & 0 deletions crates/config-derive/tests/ui/strategy_multi.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// 🐻‍❄️🪚 core-rs: Collection of Rust crates that are used by and built for Noelware's projects
// Copyright (c) 2024 Noelware, LLC. <[email protected]>
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.

use noelware_config::merge::Merge;

#[derive(Debug, noelware_config_derive::Merge)]
struct Something {
#[merge(strategy = noelware_config::merge::strategy::strings::append)]
a: String,

#[merge(strategy = noelware_config::merge::strategy::strings::overwrite_empty)]
b: String,
}

fn main() {
let mut a = Something {
a: String::from("weow"),
b: String::new(),
};

let b = Something {
a: String::from("heck"),
b: String::from("weow"),
};

a.merge(b);
assert_eq!(a.a, "weowheck");
assert_eq!(a.b, "weow");
}

0 comments on commit 2e69ad1

Please sign in to comment.