-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #112 from nomoixyz/docs/missing-modules
Docs/missing modules
- Loading branch information
Showing
12 changed files
with
121 additions
and
15 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
[book] | ||
authors = ['nomoi.xyz'] | ||
src = 'src' | ||
title = 'Vulcan Book' | ||
title = '' | ||
[output.html] | ||
no-section-label = true | ||
additional-js = ['solidity.min.js'] | ||
additional-css = ['book.css'] | ||
git-repository-url = 'https://github.com/nomoixyz/vulcan' | ||
git-repository-url = 'https://github.com/foundry-rs/foundry' | ||
|
||
[output.html.fold] | ||
enable = true |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# Format | ||
|
||
The format function defined under the `fmt` module enables you to format strings dynamically by using a template string and the ABI encoded arguments: | ||
|
||
```solidity | ||
import {Test, expect, console, fmt} from "vulcan/test.sol"; | ||
contract TestMyContract is Test { | ||
function testFormat() external { | ||
string memory template = "{address} hello {string} world {bool}"; | ||
// You can also use abbreviations: "{a} hello {s} world {b}"; | ||
template = "{a} hello {s} world {b}"; | ||
string memory result = fmt.format(template, abi.encode(address(123), "foo", true)); | ||
expect(result).toEqual("0x000000000000000000000000000000000000007B hello foo world true"); | ||
// For numerical values, you can even specify the number of decimals to format with | ||
expect(fmt.format("{uint:d18}", abi.encode(1e17))).toEqual("0.1"); | ||
} | ||
} | ||
``` | ||
|
||
This example demonstrates the use of a string template with placeholders and a custom formatting function to generate a formatted string. It is a simple and efficient way to manage dynamic values on strings. |
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,20 @@ | ||
# Utils | ||
|
||
This module provides a set of utility functions that make use of other modules in Vulcan. | ||
|
||
```solidity | ||
import {Test, expect, println, format} from "vulcan/test.sol"; | ||
contract TestMyContract is Test { | ||
function testUtils() external { | ||
// Print a string | ||
println("Hello world!"); | ||
// Print a formatted string - see Format module for more details | ||
println("Hello {string}!", abi.encode("world")); | ||
// Format a string | ||
expect(format("Hello {string}!", abi.encode("world"))).toEqual("Hello world!"); | ||
} | ||
} | ||
``` |
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,29 @@ | ||
# Format | ||
|
||
#### **`format(string template, bytes args) → (string)`** | ||
|
||
## Template Reference | ||
|
||
The template is a string that can contain placeholders for the arguments. The placeholders are defined by curly braces `{}` and can be of the following types: | ||
|
||
- **Address**: `{address}` or `{a}` | ||
- **Bytes32**: `{bytes32}` or `{b32}` | ||
- **String**: `{string}` or `{s}` | ||
- **Bytes**: `{bytes}` or `{b}` | ||
- **Uint**: `{uint}` or `{u}` | ||
- **Int**: `{int}` or `{i}` | ||
- **Boolean**: `{bool}` | ||
|
||
### Modifiers | ||
|
||
Some placeholder types can be followed by a colon `:` and a format specifier. The format specifier is a single character that defines how the argument should be formatted, and can also contain additional arguments. The following format specifiers are supported: | ||
|
||
#### Decimals (`dX`) | ||
|
||
Supported types: `uint`, `int` | ||
|
||
Formats the provided value to a string representation that uses the specified amount of decimals. One of the main use cases is to format token amounts. | ||
|
||
Examples: | ||
- `{uint:d18}` formats the value `1e18` to `"1.0"` | ||
- `{uint:d2}` formats the value `10` to `"0.1"` |
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