mirror of
https://github.com/zaphar/ucg.git
synced 2025-07-21 18:10:42 -04:00
DOCS: Document our standard library.
This commit is contained in:
parent
116a2b716a
commit
17a9882f40
@ -1,6 +1,6 @@
|
||||
+++
|
||||
title = "HowTo Guides"
|
||||
weight = 3
|
||||
weight = 4
|
||||
sort_by = "weight"
|
||||
in_search_index = true
|
||||
+++
|
||||
|
15
docsite/site/content/stdlib/_index.md
Normal file
15
docsite/site/content/stdlib/_index.md
Normal file
@ -0,0 +1,15 @@
|
||||
+++
|
||||
title = "The UCG Standard Library"
|
||||
slug = "stdlib"
|
||||
weight = 3
|
||||
sort_by = "weight"
|
||||
in_search_index = true
|
||||
+++
|
||||
|
||||
UCG has some builtin libraries for common tasks. List processing, Tuple
|
||||
manipulation, and some helpful testing assertions can all be found in the
|
||||
standard library.
|
||||
|
||||
Each library is documented here in it's own section. Most operations in
|
||||
the standard library are in the form of modules and by convention you get
|
||||
the result of an operation from the `result` field after running the module.
|
68
docsite/site/content/stdlib/lists.md
Normal file
68
docsite/site/content/stdlib/lists.md
Normal file
@ -0,0 +1,68 @@
|
||||
+++
|
||||
title = "UCG List Modules"
|
||||
weight = 1
|
||||
sort_by = "weight"
|
||||
in_search_index = true
|
||||
+++
|
||||
|
||||
The UCG list modules can be imported like so `let l = import "std/lists.ucg";` It has a number of useful operations.
|
||||
|
||||
## reverse
|
||||
|
||||
The reverse module reverses a list. It has a single required parameter:
|
||||
|
||||
* `list` the list to reverse.
|
||||
|
||||
```
|
||||
let l = import "std/lists.ucg";
|
||||
l.reverse{list=[1, 2, 3]}.result == [3, 2, 1];
|
||||
```
|
||||
|
||||
## str_join
|
||||
|
||||
The str_join module joins a list with the string representation of each element.
|
||||
It has two parameters:
|
||||
|
||||
* `list` which is required. The list to reverse.
|
||||
* `sep` which is optional and defines the separater to use when joining the elements. Defaults to a single space
|
||||
|
||||
```
|
||||
let l = import "std/lists.ucg";
|
||||
l.str_join{
|
||||
sep=" ",
|
||||
list=[1, 2, 3]
|
||||
}.result == "1,2,3";
|
||||
```
|
||||
|
||||
## len
|
||||
|
||||
The len module returns the length of a list. It has a single required parameter.
|
||||
|
||||
* `list` The list to reverse.
|
||||
|
||||
```
|
||||
let l = import "std/lists.ucg";
|
||||
l.len{list=[0, 1, 2, 3]}.result == 4;
|
||||
```
|
||||
|
||||
## enumerate
|
||||
|
||||
The enumerate module enumerates the elements of a list. It has three parameters.
|
||||
|
||||
* `list` which is required and is the list to enumerate.
|
||||
* `start` which is optional and defines the start number of the enumeration. (defaults to 0)
|
||||
* `step` which is optional and defines the step amount for the enumeration. (defaults to 1)
|
||||
|
||||
```
|
||||
let l = import "std/lists.ucg";
|
||||
|
||||
// with defaults
|
||||
l.enumerate{list=[1, 2, 3]}.result == [[0, 1], [1, 2], [3, 4]];
|
||||
|
||||
// With all parameters
|
||||
l.enumerate{
|
||||
start=1,
|
||||
step=2,
|
||||
list=["foo", "bar", "foobar"],
|
||||
}.result == [[1, "foo"], [3, "bar"], [5, "foobar"]];
|
||||
```
|
91
docsite/site/content/stdlib/testing.md
Normal file
91
docsite/site/content/stdlib/testing.md
Normal file
@ -0,0 +1,91 @@
|
||||
+++
|
||||
title = "UCG Testing Modules"
|
||||
weight = 3
|
||||
sort_by = "weight"
|
||||
in_search_index = true
|
||||
+++
|
||||
|
||||
The UCG testing modules can be imported like so `let t = import "std/testing.ucg";`
|
||||
It has a number of helpful assertions you can use in unit testing.
|
||||
|
||||
## The asserts modules
|
||||
|
||||
The asserts module exposes a number of asserts. It contains nested modules for each
|
||||
available assertion. You can configure the asserts module with a default description if desired.
|
||||
|
||||
Each of the asserts results in a `result` field that is a tuple with the shape that
|
||||
the assert statement expects.
|
||||
|
||||
The asserts module has one parameter.
|
||||
|
||||
* `default_description` which is optional and defaults to "TODO description"
|
||||
|
||||
### ok assertion
|
||||
|
||||
The `ok` assertion module tests that something is true. It has two parameters.
|
||||
|
||||
* `test` which is required and is represents the expression to test.
|
||||
* `desc` which is an optional description to output for your test. This defaults to
|
||||
the `default_description` that the `asserts` modules was set to.
|
||||
|
||||
```
|
||||
let t = import "std/testing.ucg".asserts{};
|
||||
|
||||
assert t.ok{
|
||||
test=true,
|
||||
};
|
||||
```
|
||||
|
||||
### no_ok assertion
|
||||
|
||||
The `not_ok` assertion module tests that something is not true. It has two
|
||||
parameters.
|
||||
|
||||
* `test` which is required and is represents the expression to test.
|
||||
* `desc` which is an optional description to output for your test. This defaults to
|
||||
the `default_description` that the `asserts` modules was set to.
|
||||
|
||||
```
|
||||
let t = import "std/testing.ucg".asserts{};
|
||||
|
||||
assert t.ok{
|
||||
test=true,
|
||||
};
|
||||
```
|
||||
|
||||
### equal assertion
|
||||
|
||||
The `equal` assertion module tests that two items are equal. It has two parameters.
|
||||
|
||||
* `left` which is required and is the left hand side expression to compare
|
||||
* `right` which is required is the right hand side expression to compare.
|
||||
|
||||
This module will create a description for you from the compared values.
|
||||
|
||||
```
|
||||
let t = import "std/testing.ucg".asserts{};
|
||||
|
||||
assert t.equal{
|
||||
left=1,
|
||||
right=1,
|
||||
};
|
||||
```
|
||||
|
||||
### not_equal assertion
|
||||
|
||||
The `not_equal` assertion module tests that two items are not equal. It has two
|
||||
parameters.
|
||||
|
||||
* `left` which is required and is the left hand side expression to compare
|
||||
* `right` which is required is the right hand side expression to compare.
|
||||
|
||||
This module will create a description for you from the compared values.
|
||||
|
||||
```
|
||||
let t = import "std/testing.ucg".asserts{};
|
||||
|
||||
assert t.not_equal{
|
||||
left=1,
|
||||
right=2,
|
||||
};
|
||||
```
|
44
docsite/site/content/stdlib/tuples.md
Normal file
44
docsite/site/content/stdlib/tuples.md
Normal file
@ -0,0 +1,44 @@
|
||||
+++
|
||||
title = "UCG Tuple Modules"
|
||||
weight = 2
|
||||
sort_by = "weight"
|
||||
in_search_index = true
|
||||
+++
|
||||
|
||||
The UCG tuples modules can be imported like so `let t = import "std/tuples.ucg";`
|
||||
and contains a number of useful operations on tuples.
|
||||
|
||||
## fields
|
||||
|
||||
The `fields` module retrieves all the field names in a tuple. It has one
|
||||
parameter.
|
||||
|
||||
* `tpl` which is required and is the tuple to process.
|
||||
|
||||
```
|
||||
let tpl = import "std/tuples.ucg";
|
||||
tpl.fields{tpl={foo=1, bar=2}}.result == ["foo", "bar"];
|
||||
```
|
||||
|
||||
## values
|
||||
|
||||
The `values` module retrieves all the values in a tuple. It has one parameter.
|
||||
|
||||
* `tpl` which is required and is the tuple to process.
|
||||
|
||||
```
|
||||
let tpl = import "std/tuples.ucg";
|
||||
tpl.values{tpl={foo=1, bar=2}}.result == [1, 2];
|
||||
```
|
||||
|
||||
## iter
|
||||
|
||||
The `iter` module retrieves a list of all the field and value pairs in a tuple.
|
||||
It has one parameter.
|
||||
|
||||
* `tpl` which is required and is the tuple to process.
|
||||
|
||||
```
|
||||
let tpl = import "std/tuples.ucg";
|
||||
tpl.enumerate{tpl={foo=1, bar=2}}.result == [["foo", 1], ["bar", 2]];
|
||||
```
|
Loading…
x
Reference in New Issue
Block a user