Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Parser] Support for generics. #39

Merged
merged 3 commits into from
Mar 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,4 @@ src/finitio/stdlib/*.js
build/*
pkg
finitio*.tgz

4 changes: 2 additions & 2 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,10 @@ module.exports = function(grunt) {

shell: {
peggy: {
command: 'peggy src/finitio/parser/parser.pegjs --allowed-start-rules system,type,heading,attribute,contract,constraint,literal,metadata,lambda_expr,type_def,import_def --cache -o src/finitio/parser/parser.js'
command: 'peggy src/finitio/parser/parser.pegjs --allowed-start-rules system,type,heading,attribute,contract,constraint,literal,metadata,lambda_expr,type_def,generic_def,import_def,type_instantiate --cache -o src/finitio/parser/parser.js'
},
stdlib: {
command: './bin/finitio-js --bundle --url http://finitio.io/0.4/stdlib/data src/finitio/stdlib/data.fio > src/finitio/stdlib/data.js',
command: './bin/finitio-js bundle src/finitio/stdlib/data.fio --url http://finitio.io/0.4/stdlib/data > src/finitio/stdlib/data.js',
},
tsup: {
command: 'tsup',
Expand Down
76 changes: 76 additions & 0 deletions features/finitio/use-cases/types/high-order-types.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
Feature: Using Finitio High-Order types

Background:

Given the System is
"""
Data<T,A> = {
type : T
id : Integer
attributes : A
}

Resource<Type,Attrs> = {
data : Data<Type,Attrs>
links : [String]
}

Collection<Type,Attrs> = {
data : [Data<Type,Attrs>]
links : [String]
}

People.Type = String(s | s=="People")
People.Attrs = {
firstname: String
lastname: String
}

People = Resource<People.Type,People.Attrs>
Peoples = Collection<People.Type,People.Attrs>
"""

Scenario: Coercing a valid representation of an object

Given I dress the following JSON document with People:
"""
{
"data": {
"type": "People",
"id": 1,
"attributes": {
"firstname": "Bernard",
"lastname": "Lambeau"
}
},
"links": []
}
"""

Then it should be a success

Scenario: Coercing a valid representation of a collection

Given I dress the following JSON document with Peoples:
"""
{
"data": [{
"type": "People",
"id": 1,
"attributes": {
"firstname": "Bernard",
"lastname": "Lambeau"
}
},{
"type": "People",
"id": 2,
"attributes": {
"firstname": "Yoann",
"lastname": "Guyot"
}
}],
"links": []
}
"""

Then it should be a success
1 change: 0 additions & 1 deletion features/step_definitions/steps.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ module.exports = function() {
return callback();
} catch (e) {
error = e;
console.log(e.explainTree());
return callback.fail(e);
}
});
Expand Down
Loading
Loading