Skip to content

Commit

Permalink
Address review suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
NipunaRanasinghe committed Nov 20, 2024
1 parent e006755 commit 25415e4
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,14 @@ public class VariableVisibilityTest extends BaseTestCase {
@Override
@BeforeClass
public void setup() {
String testProjectName = "variable-tests";
String testModuleFileName = "main.bal";
debugTestRunner = new DebugTestRunner(testProjectName, testModuleFileName, true);
}

@Test(description = "Variable visibility test at the beginning(first line) of the main() method")
public void initialVariableVisibilityTest() throws BallerinaTestException {
String testProjectName = "variable-tests";
String testModuleFileName = "main.bal";
debugTestRunner = new DebugTestRunner(testProjectName, testModuleFileName, true);

debugTestRunner.addBreakPoint(new BallerinaTestDebugPoint(debugTestRunner.testEntryFilePath, 123));
debugTestRunner.initDebugSession(DebugUtils.DebuggeeExecutionKind.RUN);
debugHitInfo = debugTestRunner.waitForDebugHit(25000);
Expand All @@ -71,6 +72,10 @@ public void initialVariableVisibilityTest() throws BallerinaTestException {

@Test(description = "Variable visibility test in the middle of the main() method for a new variable")
public void newVariableVisibilityTest() throws BallerinaTestException {
String testProjectName = "variable-tests";
String testModuleFileName = "main.bal";
debugTestRunner = new DebugTestRunner(testProjectName, testModuleFileName, true);

debugTestRunner.addBreakPoint(new BallerinaTestDebugPoint(debugTestRunner.testEntryFilePath, 245));
debugTestRunner.addBreakPoint(new BallerinaTestDebugPoint(debugTestRunner.testEntryFilePath, 316));
debugTestRunner.initDebugSession(DebugUtils.DebuggeeExecutionKind.RUN);
Expand Down Expand Up @@ -106,6 +111,10 @@ public void newVariableVisibilityTest() throws BallerinaTestException {

@Test(description = "Variable visibility test in control flows")
public void controlFlowVariableVisibilityTest() throws BallerinaTestException {
String testProjectName = "variable-tests";
String testModuleFileName = "main.bal";
debugTestRunner = new DebugTestRunner(testProjectName, testModuleFileName, true);

debugTestRunner.addBreakPoint(new BallerinaTestDebugPoint(debugTestRunner.testEntryFilePath, 266));
debugTestRunner.addBreakPoint(new BallerinaTestDebugPoint(debugTestRunner.testEntryFilePath, 270));
debugTestRunner.addBreakPoint(new BallerinaTestDebugPoint(debugTestRunner.testEntryFilePath, 277));
Expand Down Expand Up @@ -178,6 +187,10 @@ public void controlFlowVariableVisibilityTest() throws BallerinaTestException {

@Test(description = "Variable visibility test for global variables")
public void globalVariableVisibilityTest() throws BallerinaTestException {
String testProjectName = "variable-tests";
String testModuleFileName = "main.bal";
debugTestRunner = new DebugTestRunner(testProjectName, testModuleFileName, true);

debugTestRunner.addBreakPoint(new BallerinaTestDebugPoint(debugTestRunner.testEntryFilePath, 352));
debugTestRunner.addBreakPoint(new BallerinaTestDebugPoint(debugTestRunner.testEntryFilePath, 327));
debugTestRunner.initDebugSession(DebugUtils.DebuggeeExecutionKind.RUN);
Expand Down Expand Up @@ -216,6 +229,10 @@ public void globalVariableVisibilityTest() throws BallerinaTestException {

@Test(description = "Variable visibility test for local variables at the last line of main() method")
public void localVariableVisibilityTest() throws BallerinaTestException {
String testProjectName = "variable-tests";
String testModuleFileName = "main.bal";
debugTestRunner = new DebugTestRunner(testProjectName, testModuleFileName, true);

debugTestRunner.addBreakPoint(new BallerinaTestDebugPoint(debugTestRunner.testEntryFilePath, 327));
debugTestRunner.addBreakPoint(new BallerinaTestDebugPoint(debugTestRunner.testEntryFilePath, 360));
debugTestRunner.initDebugSession(DebugUtils.DebuggeeExecutionKind.RUN);
Expand Down Expand Up @@ -340,6 +357,10 @@ public void localVariableVisibilityTest() throws BallerinaTestException {
@Test(enabled = false, description = "Child variable visibility test for local variables at the last line of main" +
"() method")
public void localVariableChildrenVisibilityTest() throws BallerinaTestException {
String testProjectName = "variable-tests";
String testModuleFileName = "main.bal";
debugTestRunner = new DebugTestRunner(testProjectName, testModuleFileName, true);

debugTestRunner.addBreakPoint(new BallerinaTestDebugPoint(debugTestRunner.testEntryFilePath, 327));
debugTestRunner.initDebugSession(DebugUtils.DebuggeeExecutionKind.RUN);
debugHitInfo = debugTestRunner.waitForDebugHit(25000);
Expand Down Expand Up @@ -553,15 +574,16 @@ public void workerVariableVisibilityTest() throws BallerinaTestException {

@Test(description = "Binding pattern variables related visibility test")
public void bindingPatternVariableVisibilityTest() throws BallerinaTestException {

String testProjectName = "binding-pattern-tests";
String testProjectName = "variable-tests-2";
String testModuleFileName = "main.bal";
debugTestRunner = new DebugTestRunner(testProjectName, testModuleFileName, true);

debugTestRunner.addBreakPoint(new BallerinaTestDebugPoint(debugTestRunner.testEntryFilePath, 35));
debugTestRunner.addBreakPoint(new BallerinaTestDebugPoint(debugTestRunner.testEntryFilePath, 40));
debugTestRunner.addBreakPoint(new BallerinaTestDebugPoint(debugTestRunner.testEntryFilePath, 43));
debugTestRunner.addBreakPoint(new BallerinaTestDebugPoint(debugTestRunner.testEntryFilePath, 73));
debugTestRunner.addBreakPoint(new BallerinaTestDebugPoint(debugTestRunner.testEntryFilePath, 46));
debugTestRunner.addBreakPoint(new BallerinaTestDebugPoint(debugTestRunner.testEntryFilePath, 49));
debugTestRunner.addBreakPoint(new BallerinaTestDebugPoint(debugTestRunner.testEntryFilePath, 80));

debugTestRunner.initDebugSession(DebugUtils.DebuggeeExecutionKind.RUN);
Pair<BallerinaTestDebugPoint, StoppedEventArguments> debugHitInfo = debugTestRunner.waitForDebugHit(25000);
Expand All @@ -570,33 +592,42 @@ public void bindingPatternVariableVisibilityTest() throws BallerinaTestException
localVariables = debugTestRunner.fetchVariables(debugHitInfo.getRight(), DebugTestRunner.VariableScope.LOCAL);
debugTestRunner.assertVariable(localVariables, "profession", "\"Software Engineer\"", "string");

// list binding pattern variables
debugTestRunner.resumeProgram(debugHitInfo.getRight(), DebugTestRunner.DebugResumeKind.NEXT_BREAKPOINT);
debugHitInfo = debugTestRunner.waitForDebugHit(10000);
// TODO: enable after fixing runtime issue https://github.com/ballerina-platform/ballerina-lang/issues/43623

// // list binding pattern variables
// debugTestRunner.resumeProgram(debugHitInfo.getRight(), DebugTestRunner.DebugResumeKind.NEXT_BREAKPOINT);
// debugHitInfo = debugTestRunner.waitForDebugHit(10000);
// localVariables = debugTestRunner.fetchVariables(debugHitInfo.getRight(), DebugTestRunner.VariableScope.LOCAL);
// debugTestRunner.assertVariable(localVariables, "id", "1234", "int");
// debugTestRunner.assertVariable(localVariables, "firstName", "\"John Doe\"", "string");
//
// // mapping binding pattern variables
// debugTestRunner.resumeProgram(debugHitInfo.getRight(), DebugTestRunner.DebugResumeKind.NEXT_BREAKPOINT);
// debugHitInfo = debugTestRunner.waitForDebugHit(10000);

// mapping binding pattern variables
debugTestRunner.resumeProgram(debugHitInfo.getRight(), DebugTestRunner.DebugResumeKind.NEXT_BREAKPOINT);
debugHitInfo = debugTestRunner.waitForDebugHit(10000);
// TODO: enable after fixing runtime issue https://github.com/ballerina-platform/ballerina-lang/issues/43623
// localVariables = debugTestRunner.fetchVariables(debugHitInfo.getRight(), DebugTestRunner.VariableScope.LOCAL);
// debugTestRunner.assertVariable(localVariables, "givenName", "\"Anne\"", "string");
// debugTestRunner.assertVariable(localVariables, "surName", "\"Frank\"", "string");
//
// // error binding pattern variables
// debugTestRunner.resumeProgram(debugHitInfo.getRight(), DebugTestRunner.DebugResumeKind.NEXT_BREAKPOINT);
// debugHitInfo = debugTestRunner.waitForDebugHit(10000);

// error binding pattern variables
debugTestRunner.resumeProgram(debugHitInfo.getRight(), DebugTestRunner.DebugResumeKind.NEXT_BREAKPOINT);
debugHitInfo = debugTestRunner.waitForDebugHit(10000);
// TODO: enable after fixing runtime issue https://github.com/ballerina-platform/ballerina-lang/issues/43623
// localVariables = debugTestRunner.fetchVariables(debugHitInfo.getRight(), DebugTestRunner.VariableScope.LOCAL);
// debugTestRunner.assertVariable(localVariables, "cause", "\"Database Error\"", "error");
// debugTestRunner.assertVariable(localVariables, "code", "20", "int");
// debugTestRunner.assertVariable(localVariables, "reason", "\"deadlock condition\"", "string");
//
// // list binding patterns inside match statement
// debugTestRunner.resumeProgram(debugHitInfo.getRight(), DebugTestRunner.DebugResumeKind.NEXT_BREAKPOINT);
// debugHitInfo = debugTestRunner.waitForDebugHit(10000);

// list binding pattern inside foreach statement
debugTestRunner.resumeProgram(debugHitInfo.getRight(), DebugTestRunner.DebugResumeKind.NEXT_BREAKPOINT);
debugHitInfo = debugTestRunner.waitForDebugHit(10000);
localVariables = debugTestRunner.fetchVariables(debugHitInfo.getRight(), DebugTestRunner.VariableScope.LOCAL);
debugTestRunner.assertVariable(localVariables, "name", "\"John\"", "string");
debugTestRunner.assertVariable(localVariables, "age", "30", "int");

// list binding patterns inside match statement
debugTestRunner.resumeProgram(debugHitInfo.getRight(), DebugTestRunner.DebugResumeKind.NEXT_BREAKPOINT);
debugHitInfo = debugTestRunner.waitForDebugHit(10000);
// TODO: enable after fixing runtime issue https://github.com/ballerina-platform/ballerina-lang/issues/43623
// localVariables = debugTestRunner.fetchVariables(debugHitInfo.getRight(), DebugTestRunner.VariableScope.LOCAL);
// debugTestRunner.assertVariable(localVariables, "remove", "Remove", "string");
// debugTestRunner.assertVariable(localVariables, "all", "*", "string");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,28 @@ type SampleErrorData record {|
type SampleError error<SampleErrorData>;

public function main() {
// simple binding pattern
// 1. simple binding pattern
var profession = "Software Engineer";

// list binding pattern
// 2. list binding pattern
[int, [string, string]] [id, [firstName, _]] = getDetails();

// mapping binding pattern
// 3. mapping binding pattern
string givenName;
string surname;
{fname: givenName, lname: surname} = getPerson();

// error binding pattern
// 4. error binding pattern
var error(_, cause, code = code, reason = reason) = getSampleError();

// binding patterns inside a match statement
// 5. binding patterns inside a foreach statement
string names = "";
[string, int][] personInfoList = getPersonInfo();
foreach [string, int] [name, age] in personInfoList {
names += " " + name;
}

// 6. binding patterns inside a match statement
matchCommand(["Remove", "*", true]);
}

Expand Down Expand Up @@ -86,3 +93,7 @@ function matchCommand(any commands) {
}
}
}

function getPersonInfo() returns [string, int][] {
return [["John", 30]];
}

0 comments on commit 25415e4

Please sign in to comment.