blob: 86f92a51cf8e6180a68bd73589f0c61a2469bae3 [file] [log] [blame]
/*=============================================================================#
# Copyright (c) 2017, 2020 Stephan Wahlbrink and others.
#
# This program and the accompanying materials are made available under the
# terms of the Eclipse Public License 2.0 which is available at
# https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
# which is available at https://www.apache.org/licenses/LICENSE-2.0.
#
# SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
#
# Contributors:
# Stephan Wahlbrink <sw@wahlbrink.eu> - initial API and implementation
#=============================================================================*/
package org.eclipse.statet.r.core.rsource.ast;
import org.junit.Assert;
import org.junit.Test;
import org.eclipse.statet.jcommons.text.core.input.StringParserInput;
import org.eclipse.statet.ltk.model.core.IModelManager;
import org.eclipse.statet.r.core.rsource.ast.FCall.Args;
public class RScannerFCallArgsTest {
private final RScanner scanner= new RScanner(IModelManager.MODEL_FILE);
private final StringParserInput input= new StringParserInput();
@Test
public void scanNoExpand() {
assertArgs("a, b= 123", 0, 9, false);
assertArgs(" a, b= 123 ", 2, 2 + 9, false);
assertArgs(" a, b= 123, ", 2, 2 + 10, false);
assertArgs(" a, b= 123, )", 2, 2 + 10, false);
assertArgs(" a, b= 123, \n ", 2, 2 + 10, false);
assertArgs(" a, b= 123,#comment\n )", 2, 2 + 10, false);
assertArgs(" a, b= 123,#comment\n#comment\n )", 2, 2 + 10, false);
}
@Test
public void scanExpand() {
assertArgs("a, b= 123", 0, 9, true);
assertArgs(" a, b= 123 ", 0, 2 + 9 + 3, true);
assertArgs(" a, b= 123, ", 0, 2 + 10 + 3, true);
assertArgs(" a, b= 123, )", 0, 2 + 10 + 3, true);
assertArgs(" a, b= 123, \n ", 0, 2 + 10 + 4 + 3, true);
assertArgs(" a, b= 123,#comment\n )", 0, 2 + 10 + 9 + 3, true);
assertArgs(" a, b= 123,#comment\n#comment\n )", 0, 2 + 10 + 2*9 + 3, true);
}
private void assertArgs(final String code, final int startOffset, final int endOffset,
final boolean expand) {
final Args callArgs= this.scanner.scanFCallArgs(this.input.reset(code).init(), expand);
Assert.assertEquals("args.startOffset", startOffset, callArgs.getStartOffset());
Assert.assertEquals("args.endOffset", endOffset, callArgs.getEndOffset());
}
}