-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #427 from nipunayf/improve-components-api
Add test cases for the enhanced `ballerinaPackage/components` API
- Loading branch information
Showing
5 changed files
with
237 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
128 changes: 128 additions & 0 deletions
128
...ow-model-generator-ls-extension/src/test/resources/package_components/config/config3.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
] | ||
} | ||
] | ||
} |
89 changes: 89 additions & 0 deletions
89
...low-model-generator-ls-extension/src/test/resources/package_components/source/source3.bal
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters