Skip to content

Commit

Permalink
Merge pull request #427 from nipunayf/improve-components-api
Browse files Browse the repository at this point in the history
Add test cases for the enhanced `ballerinaPackage/components` API
  • Loading branch information
KavinduZoysa authored Oct 10, 2024
2 parents a2ecb9c + 50794a3 commit 9d9bb3e
Show file tree
Hide file tree
Showing 5 changed files with 237 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,31 +13,31 @@
"endColumn": 1,
"resources": [
{
"name": "post",
"name": "post-book",
"filePath": "file.bal",
"startLine": 24,
"startColumn": 4,
"endLine": 29,
"endColumn": 5
},
{
"name": "get",
"name": "get-book/[ISBN isbn]",
"filePath": "file.bal",
"startLine": 32,
"startColumn": 4,
"endLine": 38,
"endColumn": 5
},
{
"name": "put",
"name": "put-book/[ISBN isbn]",
"filePath": "file.bal",
"startLine": 41,
"startColumn": 4,
"endLine": 47,
"endColumn": 5
},
{
"name": "delete",
"name": "delete-book/[ISBN isbn]",
"filePath": "file.bal",
"startLine": 50,
"startColumn": 4,
Expand Down Expand Up @@ -89,7 +89,9 @@
"endLine": 19,
"endColumn": 25
}
]
],
"configurableVariables": [],
"automations": []
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,6 @@
"startColumn": 0,
"endLine": 62,
"endColumn": 1
},
{
"name": "main",
"filePath": "file.bal",
"startLine": 91,
"startColumn": 0,
"endLine": 94,
"endColumn": 1
}
],
"services": [
Expand All @@ -30,7 +22,7 @@
"endColumn": 1,
"resources": [
{
"name": "get",
"name": "get-students",
"filePath": "file.bal",
"startLine": 66,
"startColumn": 4,
Expand Down Expand Up @@ -144,6 +136,17 @@
"endLine": 11,
"endColumn": 22
}
],
"configurableVariables": [],
"automations": [
{
"name": "main",
"filePath": "file.bal",
"startLine": 91,
"startColumn": 0,
"endLine": 94,
"endColumn": 1
}
]
}
]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
{
"source": "source3.bal",
"output": [
{
"functions": [
{
"name": "createDanceRoutine",
"filePath": "file.bal",
"startLine": 22,
"startColumn": 0,
"endLine": 28,
"endColumn": 1
}
],
"services": [],
"records": [
{
"name": "Performance",
"filePath": "file.bal",
"startLine": 30,
"startColumn": 0,
"endLine": 34,
"endColumn": 3
},
{
"name": "Dancer",
"filePath": "file.bal",
"startLine": 36,
"startColumn": 0,
"endLine": 40,
"endColumn": 2
}
],
"objects": [],
"classes": [],
"types": [],
"constants": [],
"enums": [],
"listeners": [],
"moduleVariables": [
{
"name": "value ",
"filePath": "file.bal",
"startLine": 20,
"startColumn": 0,
"endLine": 20,
"endColumn": 15
}
],
"configurableVariables": [
{
"name": "numberOfDancers ",
"filePath": "file.bal",
"startLine": 2,
"startColumn": 0,
"endLine": 2,
"endColumn": 37
},
{
"name": "performanceName ",
"filePath": "file.bal",
"startLine": 3,
"startColumn": 0,
"endLine": 3,
"endColumn": 50
},
{
"name": "ticketPrice ",
"filePath": "file.bal",
"startLine": 4,
"startColumn": 0,
"endLine": 4,
"endColumn": 38
},
{
"name": "hasIntermission ",
"filePath": "file.bal",
"startLine": 5,
"startColumn": 0,
"endLine": 5,
"endColumn": 44
},
{
"name": "danceMoves ",
"filePath": "file.bal",
"startLine": 6,
"startColumn": 0,
"endLine": 6,
"endColumn": 76
},
{
"name": "maxCapacity ",
"filePath": "file.bal",
"startLine": 7,
"startColumn": 0,
"endLine": 7,
"endColumn": 33
},
{
"name": "performances ",
"filePath": "file.bal",
"startLine": 8,
"startColumn": 0,
"endLine": 12,
"endColumn": 2
},
{
"name": "dancerRoles ",
"filePath": "file.bal",
"startLine": 13,
"startColumn": 0,
"endLine": 18,
"endColumn": 2
}
],
"automations": [
{
"name": "main",
"filePath": "file.bal",
"startLine": 42,
"startColumn": 0,
"endLine": 88,
"endColumn": 1
}
]
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
import ballerina/io;

configurable int numberOfDancers = 5;
configurable string performanceName = "Swan Lake";
configurable float ticketPrice = 50.0;
configurable boolean hasIntermission = true;
configurable string[] danceMoves = ["pirouette", "grand jete", "arabesque"];
configurable int maxCapacity = ?;
configurable table<Performance> key(name) performances = table [
{name: "Swan Lake", year: 1876, composer: "Tchaikovsky"},
{name: "The Nutcracker", year: 1892, composer: "Tchaikovsky"},
{name: "Giselle", year: 1841, composer: "Adolphe Adam"}
];
configurable map<string> dancerRoles = {
"Odette": "Principal female",
"Siegfried": "Principal male",
"Rothbart": "Antagonist",
"Odile": "Secondary female"
};

int value = 32;

function createDanceRoutine(string[] moves) returns string {
string routine = "";
foreach var move in moves {
routine += move + " - ";
}
return routine.substring(0, routine.length() - 3);
}

type Performance record {|
readonly string name;
int year;
string composer;
|};

type Dancer record {
string name;
int age;
string specialty;
};

public function main() {
// Create an array of dancers
Dancer[] dancers = [];
foreach int i in 1 ... numberOfDancers {
dancers.push({
name: "Dancer " + i.toString(),
age: 20 + i,
specialty: danceMoves[i % danceMoves.length()]
});
}

// Calculate total revenue
float totalRevenue = <float>numberOfDancers * ticketPrice;

// Create the dance routine
string routine = createDanceRoutine(danceMoves);

// Print performance details
io:println("Performance: ", performanceName);
io:println("Number of Dancers: ", numberOfDancers);
io:println("Ticket Price: $", ticketPrice);
io:println("Has Intermission: ", hasIntermission);
io:println("Dance Routine: ", routine);
io:println("Total Revenue: $", totalRevenue);

// Using the Elvis operator for maxCapacity
int actualCapacity = maxCapacity ?: 100;
io:println("Max Capacity: ", actualCapacity);

// Print dancer details
io:println("\nDancers:");
foreach var dancer in dancers {
io:println(dancer.name, " (Age: ", dancer.age, ", Specialty: ", dancer.specialty, ")");
}

// Using the table
io:println("\nFamous Ballet Performances:");
foreach var performance in performances {
io:println(performance.name, " (", performance.year, ") by ", performance.composer);
}

// Using the map<string>
io:println("\nDancer Roles:");
foreach var [role, description] in dancerRoles.entries() {
io:println(role, ": ", description);
}
}
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
org.gradle.caching=true
group=org.ballerinalang
version=1.4.0-SNAPSHOT
ballerinaLangVersion=2201.11.0-20240918-131000-55b5a679
ballerinaLangVersion=2201.11.0-20241010-093700-a5c703df

ballerinaGradlePluginVersion=2.0.1
checkStyleToolVersion=10.12.1
Expand Down

0 comments on commit 9d9bb3e

Please sign in to comment.