-
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
11 changed files
with
142 additions
and
37 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
open Ava | ||
|
||
module Common = { | ||
let value = 123n | ||
let any = %raw(`123n`) | ||
let invalidAny = %raw(`123.45`) | ||
let factory = () => S.bigint | ||
|
||
test("Successfully parses", t => { | ||
let schema = factory() | ||
|
||
t->Assert.deepEqual(any->S.parseAnyWith(schema), Ok(value), ()) | ||
}) | ||
|
||
test("Fails to parse", t => { | ||
let schema = factory() | ||
|
||
t->U.assertErrorResult( | ||
invalidAny->S.parseAnyWith(schema), | ||
{ | ||
code: InvalidType({expected: schema->S.toUnknown, received: invalidAny}), | ||
operation: Parse, | ||
path: S.Path.empty, | ||
}, | ||
) | ||
}) | ||
|
||
test("BigInt name", t => { | ||
let schema = factory() | ||
t->Assert.is(schema->S.name, "BigInt", ()) | ||
}) | ||
|
||
test("Successfully serializes", t => { | ||
let schema = factory() | ||
|
||
t->Assert.deepEqual(value->S.serializeToUnknownWith(schema), Ok(any), ()) | ||
}) | ||
|
||
test("Compiled parse code snapshot", t => { | ||
let schema = factory() | ||
|
||
t->U.assertCompiledCode(~schema, ~op=#Parse, `i=>{if(typeof i!=="bigint"){e[0](i)}return i}`) | ||
}) | ||
|
||
test("Compiled serialize code snapshot", t => { | ||
let schema = factory() | ||
|
||
t->U.assertCompiledCodeIsNoop(~schema, ~op=#Serialize) | ||
}) | ||
|
||
test("Reverse schema to self", t => { | ||
let schema = factory() | ||
t->Assert.is(schema->S.\"~experimantalReverse", schema->S.toUnknown, ()) | ||
}) | ||
|
||
test("Succesfully uses reversed schema for parsing back to initial value", t => { | ||
let schema = factory() | ||
t->U.assertReverseParsesBack(schema, value) | ||
}) | ||
} |
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
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
78237da
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
811931571
ops/sec (±0.16%
)811431552
ops/sec (±0.15%
)1.00
Serialize string
811225754
ops/sec (±0.20%
)812781945
ops/sec (±0.05%
)1.00
Advanced object schema factory
464591
ops/sec (±1.11%
)472293
ops/sec (±0.54%
)1.02
Parse advanced object
56718411
ops/sec (±0.28%
)56799894
ops/sec (±0.57%
)1.00
Assert advanced object - compile
163982852
ops/sec (±0.21%
)Assert advanced object
172815185
ops/sec (±0.06%
)171920805
ops/sec (±0.20%
)0.99
Create and parse advanced object
94711
ops/sec (±0.30%
)95083
ops/sec (±0.21%
)1.00
Parse advanced strict object
25234682
ops/sec (±0.54%
)25471962
ops/sec (±0.17%
)1.01
Assert advanced strict object
29530322
ops/sec (±0.25%
)30460141
ops/sec (±0.20%
)1.03
Serialize advanced object
66936833
ops/sec (±3.42%
)74797850
ops/sec (±0.32%
)1.12
This comment was automatically generated by workflow using github-action-benchmark.