Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docs improvements #408

Merged
merged 6 commits into from
Jan 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions crates/bytecode/src/compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ enum ErrorKind {
u16::MAX
)]
JumpOffsetIsTooLarge(usize),
#[error("Function has too many {property} ({amount})")]
#[error("function has too many {property} ({amount})")]
FunctionPropertyLimit { property: String, amount: usize },
#[error("missing argument in for loop")]
MissingArgumentInForLoop,
Expand Down Expand Up @@ -64,7 +64,7 @@ enum ErrorKind {
OutOfPositionMatchEllipsis,
#[error("root chain node out of position")]
OutOfPositionRootNodeInChain,
#[error("The compiled bytecode is larger than the maximum size of 4GB (size: {0} bytes)")]
#[error("the compiled bytecode is larger than the maximum size of 4GB (size: {0} bytes)")]
ResultingBytecodeIsTooLarge(usize),
#[error("too many targets in assignment ({0})")]
TooManyAssignmentTargets(usize),
Expand All @@ -79,7 +79,7 @@ enum ErrorKind {
UnassignedBreakValue,
#[error("unexpected Ellipsis")]
UnexpectedEllipsis,
#[error("unexpected Wildcard")]
#[error("attempting to access an ignored value")]
UnexpectedWildcard,
#[error("expected {expected} patterns in match arm, found {unexpected}")]
UnexpectedMatchPatternCount { expected: usize, unexpected: usize },
Expand Down
4 changes: 2 additions & 2 deletions crates/bytecode/src/module_loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ pub enum ModuleLoaderErrorKind {
Compiler(#[from] CompilerError),
#[error(transparent)]
Io(#[from] io::Error),
#[error("Failed to get parent of path ('{0}')")]
#[error("failed to get parent of path ('{0}')")]
FailedToGetPathParent(PathBuf),
#[error("Unable to find module '{0}'")]
#[error("unable to find module '{0}'")]
UnableToFindModule(String),
}

Expand Down
1 change: 1 addition & 0 deletions crates/cli/docs/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ Welcome to Koto
» 'hello!'
➝ hello!
```

## Help

The [language guide][guide] and the [core library reference][core],
Expand Down
49 changes: 39 additions & 10 deletions crates/cli/docs/core_lib/test.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,20 +107,49 @@ assert_near 1 % 0.2, 0.2
|tests: Map| -> Null
```

Runs the tests contained in the map.
Runs the `@test` functions contained in the map.

`@pre_test` and `@post_test` functions can be implemented in the same way as when exporting
[module tests](../language_guide.md#module-tests).
`@pre_test` will be run before each `@test`, and `@post_test` will be run after.


### Example

```koto,skip_check
my_tests =
@pre_test: || self.test_data = 1, 2, 3
@post_test: || self.test_data = null
```koto
make_x = |n|
data: n
@+: |other| make_x self.data + other.data
@-: |other| make_x self.data - other.data

x_tests =
@pre_test: ||
self.x1 = make_x 100
self.x2 = make_x 200

@test data_size: || assert_eq self.test_data.size(), 3
@test failure: || assert_eq self.test_data.size(), 0
@post_test: ||
print 'Test complete'

@test addition: ||
print 'Testing addition'
assert_eq self.x1 + self.x2, make_x 300

@test subtraction: ||
print 'Testing subtraction'
assert_eq self.x1 - self.x2, make_x -100

@test failing_test: ||
print 'About to fail'
assert false

try
test.run_tests my_tests
catch error
print "An error occurred while running my_tests:\n {error}"
test.run_tests x_tests
catch _
print 'A test failed'
check! Testing addition
check! Test complete
check! Testing subtraction
check! Test complete
check! About to fail
check! A test failed
```
Loading
Loading