/*
* This file is part of the Intuitive DSL project.
* Copyright (c) 2026 DBA Labs - Switzerland. All rights reserved.
*
* This program is dual-licensed under a commercial license and the AGPLv3.
* For commercial licensing, contact us at [email protected] or visit https://www.dbalabs.ch.
*
* AGPLv3 licensing:
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, version 3 (19 November 2007).
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/agpl-3.0.html>.
*/
package ch.dbalabs.intuitivedsl.binding;
import ch.dbalabs.intuitivedsl.annotation.Bind;
import ch.dbalabs.intuitivedsl.annotation.DslCommand;
import ch.dbalabs.intuitivedsl.core.ExecutionContext;
import ch.dbalabs.intuitivedsl.core.IntuitiveDslEngine;
import org.junit.jupiter.api.Test;
import java.util.ArrayList;
import java.util.List;
import static org.assertj.core.api.Assertions.assertThat;
class RepeatableBindingTest {
@DslCommand(name = "GRANT ACCESS", syntax = "GRANT ACCESS TO target_user ... ;")
public static class GrantAccessCommand implements Runnable {
private final List<String> grantedUsers = new ArrayList<>();
@Bind("target_user")
public void addUser(String user) {
this.grantedUsers.add(user);
}
@Override public void run() {}
public List<String> getGrantedUsers() { return grantedUsers; }
}
@Test
void shouldBindAllRepeatableParametersWithoutDataLoss() {
IntuitiveDslEngine engine = new IntuitiveDslEngine();
engine.register(GrantAccessCommand.class);
GrantAccessCommand cmd = engine.execute("GRANT ACCESS TO joe bob charlie ;", ExecutionContext.createDefault());
assertThat(cmd.getGrantedUsers())
.as("The DslBinder must inject ALL occurrences of the repeatable parameter.")
.containsExactly("joe", "bob", "charlie");
}
}