Skip to content

Commit 8df4cef

Browse files
committed
Fix tests
1 parent 16e0d96 commit 8df4cef

File tree

4 files changed

+19
-20
lines changed

4 files changed

+19
-20
lines changed

vtl-engine/src/main/java/fr/insee/vtl/engine/VtlScriptEngine.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import java.util.stream.Stream;
2121
import javax.script.*;
2222
import org.antlr.v4.runtime.*;
23+
import org.antlr.v4.runtime.misc.Interval;
2324
import org.antlr.v4.runtime.tree.ParseTree;
2425
import org.antlr.v4.runtime.tree.TerminalNode;
2526

@@ -103,9 +104,11 @@ public static Positioned fromTokens(Token from, Token to) {
103104
if (to == null) {
104105
to = from;
105106
}
107+
var stream = from.getInputStream();
108+
var text = stream.getText(new Interval(from.getStartIndex(), to.getStopIndex()));
106109
var position =
107110
new Positioned.Position(
108-
"",
111+
text,
109112
from.getLine() - 1,
110113
to.getLine() - 1,
111114
from.getCharPositionInLine(),

vtl-engine/src/test/java/fr/insee/vtl/engine/utils/dag/DagTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ private static Positioned.Position getPositionOfStatementInScript(
148148
}
149149
}
150150

151-
return new Positioned.Position("", startLine, endLine, startColumn, endColumn);
151+
return new Positioned.Position(statement, startLine, endLine, startColumn, endColumn);
152152
}
153153

154154
@BeforeEach

vtl-engine/src/test/java/fr/insee/vtl/engine/visitors/ClauseVisitorTest.java

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,8 @@ public void testRenameClause_unknownVariable() {
140140

141141
assertThatThrownBy(() -> engine.eval("ds := ds1[rename missing to foo];"))
142142
.isInstanceOf(VtlScriptException.class)
143-
.is(atPosition(0, 47, 58))
144-
.hasMessageContaining("Error: source column to rename not found: 'missing'");
143+
.is(atPosition(0, 17, 24))
144+
.hasMessage("undefined variable 'missing' in 'ds1'");
145145
}
146146

147147
@Test
@@ -159,8 +159,7 @@ public void testRenameClause_duplicateToNamesShouldFail() {
159159

160160
assertThatThrownBy(() -> engine.eval("ds := ds1[rename age to dup, weight to dup];"))
161161
.isInstanceOf(VtlScriptException.class)
162-
.is(atPosition(0, 47, 58))
163-
.hasMessageContaining("Error: source column to rename not found: 'missing'");
162+
.hasMessage("'dup', is already defined in 'ds1'");
164163
}
165164

166165
@Test
@@ -178,8 +177,8 @@ public void testRenameClause_duplicateFromNamesShouldFail() {
178177

179178
assertThatThrownBy(() -> engine.eval("ds := ds1[rename age to foo, age to bar];"))
180179
.isInstanceOf(VtlScriptException.class)
181-
.hasMessageContaining("Error: duplicate source name in RENAME clause: 'age'")
182-
.is(atPosition(0, 47, 58));
180+
.hasMessageContaining("duplicate from name 'age'")
181+
.is(atPosition(0, 29, 32));
183182
}
184183

185184
@Test
@@ -198,9 +197,8 @@ public void testRenameClause_duplicateToNameShouldFail() {
198197
assertThatThrownBy(
199198
() -> engine.eval("ds := ds1[rename age to weight, weight to age, name to age];"))
200199
.isInstanceOf(VtlScriptException.class)
201-
.is(atPosition(0, 47, 58))
202-
.hasMessageContaining(
203-
"TODO: Improve: Error: duplicate output column name in RENAME clause: 'name'");
200+
.hasMessage(
201+
"'age', is already defined in 'ds1'");
204202
}
205203

206204
/** RENAME: duplicate "from" name inside the clause must raise a detailed script error. */
@@ -218,8 +216,8 @@ public void testRenameClause_duplicateFromNameShouldFail() {
218216

219217
assertThatThrownBy(() -> engine.eval("ds := ds1[rename age to weight, age to weight2];"))
220218
.isInstanceOf(VtlScriptException.class)
221-
.is(atPosition(0, 0, 0, 0))
222-
.hasMessage("TODO: Improve: duplicate source name in RENAME clause");
219+
.is(atPosition(0, 32, 35))
220+
.hasMessageContaining("duplicate from name 'age'");
223221
}
224222

225223
/** RENAME: "from" column must exist in dataset. */
@@ -235,8 +233,8 @@ public void testRenameClause_fromColumnNotFoundShouldFail() {
235233

236234
assertThatThrownBy(() -> engine.eval("ds := ds1[rename unknown to something];"))
237235
.isInstanceOf(VtlScriptException.class)
238-
.is(atPosition(0, 0, 0, 0))
239-
.hasMessageContaining("TODO: Improve: source column to rename not found: 'unknown'");
236+
.is(atPosition(0, 17, 24))
237+
.hasMessage("undefined variable 'unknown' in 'ds1'");
240238
}
241239

242240
/**
@@ -255,10 +253,8 @@ public void testRenameClause_targetCollidesWithUntouchedShouldFail() {
255253

256254
assertThatThrownBy(() -> engine.eval("ds := ds1[rename name to age];"))
257255
.isInstanceOf(VtlScriptException.class)
258-
.is(atPosition(0, 0, 0, 0))
259-
.hasMessageContaining("target name 'age'") // main message
260-
.hasMessageContaining("already exists in dataset and is not being renamed")
261-
.hasMessageContaining("(role=MEASURE, type=class java.lang.Long)");
256+
.is(atPosition(0, 25, 28))
257+
.hasMessage("'age', is already defined in 'ds1'");
262258
}
263259

264260
@Test

vtl-engine/src/test/java/fr/insee/vtl/engine/visitors/expression/functions/JoinFunctionsTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ public void testLeftJoinWithDifferentIdentifiers() throws ScriptException {
137137
result2 := left_join(ds_1_1, ds_2 using Id_2);\
138138
"""))
139139
.isInstanceOf(InvalidArgumentException.class)
140-
.hasMessage("using component Id_2 has to be an identifier");
140+
.hasMessageContaining("CALC cannot overwrite IDENTIFIER 'Id_2'");
141141
}
142142

143143
@Test

0 commit comments

Comments
 (0)