-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
123 additions
and
53 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"ocaml.sandbox": { | ||
"kind": "opam", | ||
"switch": "struct" | ||
} | ||
} |
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
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
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,45 @@ | ||
// Generated by ReScript, PLEASE EDIT WITH CARE | ||
|
||
import * as U from "../utils/U.bs.mjs"; | ||
import Ava from "ava"; | ||
import * as S$RescriptStruct from "rescript-struct/src/S.bs.mjs"; | ||
|
||
var ratingStruct = S$RescriptStruct.union([ | ||
S$RescriptStruct.literal("G"), | ||
S$RescriptStruct.literal("PG"), | ||
S$RescriptStruct.literal("PG13"), | ||
S$RescriptStruct.literal("R") | ||
]); | ||
|
||
var filmStruct = S$RescriptStruct.$$Object.factory(function (s) { | ||
return { | ||
Id: s.f("Id", S$RescriptStruct.$$float), | ||
Title: s.f("Title", S$RescriptStruct.string), | ||
Tags: s.f("Tags", S$RescriptStruct.$$Option.getOr(S$RescriptStruct.option(S$RescriptStruct.array(S$RescriptStruct.string)), [])), | ||
Rating: s.f("Rating", ratingStruct), | ||
Age: s.f("Age", S$RescriptStruct.deprecate(S$RescriptStruct.option(S$RescriptStruct.$$int), "Use rating instead")) | ||
}; | ||
}); | ||
|
||
Ava("Example", (function (t) { | ||
U.assertEqualStructs(t, filmStruct, S$RescriptStruct.object(function (s) { | ||
return { | ||
Id: s.f("Id", S$RescriptStruct.$$float), | ||
Title: s.f("Title", S$RescriptStruct.string), | ||
Tags: s.o("Tags", S$RescriptStruct.array(S$RescriptStruct.string), []), | ||
Rating: s.f("Rating", S$RescriptStruct.union([ | ||
S$RescriptStruct.literal("G"), | ||
S$RescriptStruct.literal("PG"), | ||
S$RescriptStruct.literal("PG13"), | ||
S$RescriptStruct.literal("R") | ||
])), | ||
Age: s.f("Age", S$RescriptStruct.deprecate(S$RescriptStruct.option(S$RescriptStruct.$$int), "Use rating instead")) | ||
}; | ||
}), undefined); | ||
})); | ||
|
||
export { | ||
ratingStruct , | ||
filmStruct , | ||
} | ||
/* ratingStruct Not a pure module */ |
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,43 @@ | ||
open Ava | ||
open U | ||
|
||
@struct | ||
type rating = | ||
| @as("G") GeneralAudiences | ||
| @as("PG") ParentalGuidanceSuggested | ||
| @as("PG13") ParentalStronglyCautioned | ||
| @as("R") Restricted | ||
@struct | ||
type film = { | ||
@as("Id") | ||
id: float, | ||
@as("Title") | ||
title: string, | ||
@as("Tags") | ||
tags: @struct(S.array(S.string)->S.option->S.Option.getOr([])) array<string>, | ||
@as("Rating") | ||
rating: rating, | ||
@as("Age") | ||
deprecatedAgeRestriction: @struct(S.int->S.option->S.deprecate("Use rating instead")) option<int>, | ||
} | ||
|
||
test("Example", t => { | ||
t->assertEqualStructs( | ||
filmStruct, | ||
S.object(s => { | ||
id: s.field("Id", S.float), | ||
title: s.field("Title", S.string), | ||
tags: s.fieldOr("Tags", S.array(S.string), []), | ||
rating: s.field( | ||
"Rating", | ||
S.union([ | ||
S.literal(GeneralAudiences), | ||
S.literal(ParentalGuidanceSuggested), | ||
S.literal(ParentalStronglyCautioned), | ||
S.literal(Restricted), | ||
]), | ||
), | ||
deprecatedAgeRestriction: s.field("Age", S.option(S.int)->S.deprecate("Use rating instead")), | ||
}), | ||
) | ||
}) |
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
65862f1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Benchmark
Parse string
591498829
ops/sec (±0.08%
)706149725
ops/sec (±0.41%
)1.19
Serialize string
588410362
ops/sec (±0.45%
)693539015
ops/sec (±2.10%
)1.18
Advanced object struct factory
267650
ops/sec (±0.43%
)286556
ops/sec (±0.58%
)1.07
Parse advanced object
32079500
ops/sec (±0.18%
)22341504
ops/sec (±0.24%
)0.70
Create and parse advanced object
24377
ops/sec (±0.50%
)58042
ops/sec (±1.08%
)2.38
Parse advanced strict object
15463286
ops/sec (±0.23%
)13141235
ops/sec (±0.73%
)0.85
Serialize advanced object
578255912
ops/sec (±0.11%
)32617508
ops/sec (±0.33%
)0.05640670042989548
This comment was automatically generated by workflow using github-action-benchmark.
65862f1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Possible performance regression was detected for benchmark.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold
1.50
.Create and parse advanced object
24377
ops/sec (±0.50%
)58042
ops/sec (±1.08%
)2.38
This comment was automatically generated by workflow using github-action-benchmark.