Skip to content

Commit

Permalink
Add tests to on conflict query exprs
Browse files Browse the repository at this point in the history
  • Loading branch information
LakshanWeerasinghe committed Nov 20, 2023
1 parent 22351a6 commit 50d4318
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,16 @@ public void testKeyLessTableWithReturnTable() {
Assert.assertTrue((Boolean) returnValues);
}

@Test(description = "Test query expr with map construction variable references in on conflict clause")
public void testQueryConstructingMapWithOnConflictsWithVarRef() {
BRunUtil.invoke(result, "testQueryConstructingMapWithOnConflictsWithVarRef");
}

@Test(description = "Test query expr with table construction variable references in on conflict clause")
public void testQueryConstructingTableWithOnConflictsWithVarRef() {
BRunUtil.invoke(result, "testQueryConstructingTableWithOnConflictsWithVarRef");
}

@Test(description = "Test negative scenarios for query expr with query construct type")
public void testNegativeScenarios() {
int index = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -979,6 +979,30 @@ function testQueryConstructingTableWithOnConflictClauseHavingNonTableQueryInWher
}
}

function testQueryConstructingTableWithOnConflictsWithVarRef() {
TokenTable|error tbl1 = table key(idx) from int i in [1, 2, 3, 1, 2, 3]
let string value = "A" + i.toString()
select {
idx: i,
value
}
on conflict error(string `Duplicate Key: ${i} Value: ${value}`);

assertEqual(true, tbl1 is error);
assertEqual("Duplicate Key: 1 Value: A1", (<error>tbl1).message());

int duplicateKey = 1;
TokenTable|error tbl2 = table key(idx) from int i in [1, 2, 3, 1, 2, 3]
let string value = "A" + i.toString()
select {
idx: i,
value
}
on conflict error(string `Duplicate Key: ${duplicateKey} Value: ${value}`);
assertEqual(true, tbl2 is error);
assertEqual("Duplicate Key: 1 Value: A1", (<error>tbl2).message());
}

function testMapConstructingQueryExpr() {
Customer c1 = {id: 1, name: "Melina", noOfItems: 12};
Customer c2 = {id: 2, name: "James", noOfItems: 5};
Expand Down Expand Up @@ -1609,6 +1633,24 @@ function testQueryConstructingMapsAndTablesWithClausesMayCompleteSEarlyWithError
assertEqual(table6, error("Error"));
}

function testQueryConstructingMapWithOnConflictsWithVarRef() {
map<string>|error mp1 = map from int i in [1, 2, 3, 1, 2, 3]
let string value = "A" + i.toString()
select [i.toString(), value]
on conflict error(string `Duplicate Key: ${i} Value: ${value}`);

assertEqual(true, mp1 is error);
assertEqual("Duplicate Key: 1 Value: A1", (<error>mp1).message());

int duplicateKey = 1;
map<string>|error mp2 = map from int i in [1, 2, 3, 1, 2, 3]
let string value = "A" + i.toString()
select [i.toString(), value]
on conflict error(string `Duplicate Key: ${duplicateKey} Value: ${value}`);
assertEqual(true, mp2 is error);
assertEqual("Duplicate Key: 1 Value: A1", (<error>mp2).message());
}

function testQueryConstructingMapsAndTablesWithClausesMayCompleteSEarlyWithError2() {
EvenNumberGenerator evenGen = new();
stream<int, error> evenNumberStream = new(evenGen);
Expand Down

0 comments on commit 50d4318

Please sign in to comment.