Merge branch 'docs/include-doc' into 'dev'
[LIGO-330] Add inclusion directive docs and inclusion tests for CameLIGO and ReasonLIGO Closes #116 See merge request ligolang/ligo!293
This commit is contained in:
commit
2b25fbe4b9
71
gitlab-pages/docs/advanced/include.md
Normal file
71
gitlab-pages/docs/advanced/include.md
Normal file
@ -0,0 +1,71 @@
|
||||
---
|
||||
id: include
|
||||
title: Including Other Contracts
|
||||
---
|
||||
|
||||
Lets say we have a contract that's getting a bit too big. If it has a modular
|
||||
structure, you might find it useful to use the `#include` statement to split the
|
||||
contract up over multiple files.
|
||||
|
||||
|
||||
You take the code that you want to include and put it in a separate file, for
|
||||
example `included.ligo`:
|
||||
|
||||
<!--DOCUSAURUS_CODE_TABS-->
|
||||
|
||||
<!--PascaLIGO-->
|
||||
```pascaligo
|
||||
|
||||
// Demonstrate PascaLIGO inclusion statements, see includer.ligo
|
||||
|
||||
const foo : int = 144
|
||||
```
|
||||
|
||||
<!--CameLIGO-->
|
||||
```cameligo
|
||||
|
||||
// Demonstrate CameLIGO inclusion statements, see includer.mligo
|
||||
|
||||
let foo : int = 144
|
||||
```
|
||||
|
||||
<!--ReasonLIGO-->
|
||||
```reasonligo
|
||||
|
||||
// Demonstrate ReasonLIGO inclusion statements, see includer.religo
|
||||
|
||||
let foo : int = 144;
|
||||
```
|
||||
|
||||
<!--END_DOCUSAURUS_CODE_TABS-->
|
||||
|
||||
|
||||
And then you can include this code using the `#include` statement like so:
|
||||
|
||||
<!--DOCUSAURUS_CODE_TABS-->
|
||||
|
||||
<!--PascaLIGO-->
|
||||
```pascaligo
|
||||
|
||||
#include "included.ligo"
|
||||
|
||||
const bar : int = foo
|
||||
```
|
||||
|
||||
<!--CameLIGO-->
|
||||
```cameligo
|
||||
|
||||
#include "included.mligo"
|
||||
|
||||
let bar : int = foo
|
||||
```
|
||||
|
||||
<!--ReasonLIGO-->
|
||||
```reasonligo
|
||||
|
||||
#include "included.religo"
|
||||
|
||||
let bar : int = foo;
|
||||
```
|
||||
|
||||
<!--END_DOCUSAURUS_CODE_TABS-->
|
@ -15,6 +15,7 @@
|
||||
"Advanced": [
|
||||
"advanced/timestamps-addresses",
|
||||
"advanced/entrypoints-contracts",
|
||||
"advanced/include",
|
||||
"advanced/first-contract"
|
||||
],
|
||||
"API": [
|
||||
|
3
src/test/contracts/included.mligo
Normal file
3
src/test/contracts/included.mligo
Normal file
@ -0,0 +1,3 @@
|
||||
// Demonstrate CameLIGO inclusion statements, see includer.mligo
|
||||
|
||||
let foo : int = 144
|
3
src/test/contracts/included.religo
Normal file
3
src/test/contracts/included.religo
Normal file
@ -0,0 +1,3 @@
|
||||
// Demonstrate ReasonLIGO inclusion statements, see includer.religo
|
||||
|
||||
let foo : int = 144;
|
5
src/test/contracts/includer.mligo
Normal file
5
src/test/contracts/includer.mligo
Normal file
@ -0,0 +1,5 @@
|
||||
// Demonstrate CameLIGO inclusion statements, see included.mligo
|
||||
|
||||
#include "included.mligo"
|
||||
|
||||
let bar : int = foo
|
5
src/test/contracts/includer.religo
Normal file
5
src/test/contracts/includer.religo
Normal file
@ -0,0 +1,5 @@
|
||||
// Demonstrate ReasonLIGO inclusion statements, see included.religo
|
||||
|
||||
#include "included.religo"
|
||||
|
||||
let bar : int = foo;
|
@ -604,6 +604,14 @@ let include_ () : unit result =
|
||||
let%bind program = type_file "./contracts/includer.ligo" in
|
||||
expect_eq_evaluate program "bar" (e_int 144)
|
||||
|
||||
let include_mligo () : unit result =
|
||||
let%bind program = mtype_file "./contracts/includer.mligo" in
|
||||
expect_eq_evaluate program "bar" (e_int 144)
|
||||
|
||||
let include_religo () : unit result =
|
||||
let%bind program = retype_file "./contracts/includer.religo" in
|
||||
expect_eq_evaluate program "bar" (e_int 144)
|
||||
|
||||
let record_ez_int names n =
|
||||
ez_e_record @@ List.map (fun x -> x, e_int n) names
|
||||
|
||||
@ -1899,6 +1907,8 @@ let main = test_suite "Integration (End to End)" [
|
||||
test "quote declaration" quote_declaration ;
|
||||
test "quote declarations" quote_declarations ;
|
||||
test "#include directives" include_ ;
|
||||
test "#include directives (mligo)" include_mligo ;
|
||||
test "#include directives (religo)" include_religo ;
|
||||
test "counter contract" counter_contract ;
|
||||
test "super counter contract" super_counter_contract ;
|
||||
test "super counter contract" super_counter_contract_mligo ;
|
||||
|
Loading…
Reference in New Issue
Block a user