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:
Christian Rinderknecht 2020-01-02 17:00:07 +00:00
commit 2b25fbe4b9
7 changed files with 98 additions and 0 deletions

View 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-->

View File

@ -15,6 +15,7 @@
"Advanced": [
"advanced/timestamps-addresses",
"advanced/entrypoints-contracts",
"advanced/include",
"advanced/first-contract"
],
"API": [

View File

@ -0,0 +1,3 @@
// Demonstrate CameLIGO inclusion statements, see includer.mligo
let foo : int = 144

View File

@ -0,0 +1,3 @@
// Demonstrate ReasonLIGO inclusion statements, see includer.religo
let foo : int = 144;

View File

@ -0,0 +1,5 @@
// Demonstrate CameLIGO inclusion statements, see included.mligo
#include "included.mligo"
let bar : int = foo

View File

@ -0,0 +1,5 @@
// Demonstrate ReasonLIGO inclusion statements, see included.religo
#include "included.religo"
let bar : int = foo;

View File

@ -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 ;