#![cfg(feature = "docs")]
#![allow(dead_code)]
use confroid::{env_example, markdown_table};
#[derive(confroid::Config, Debug)]
struct HttpConfig {
#[confroid(default = 8080)]
port: u16,
#[confroid(example = "localhost")]
host: String,
}
const DEFAULT_NAME: &str = "World";
#[derive(confroid::Config, Debug)]
struct Config {
http: HttpConfig,
#[confroid(default = "Hello")]
greeting: String,
#[confroid(default = DEFAULT_NAME, example = "John")]
name: String,
}
#[test]
fn env_example_matches_expected_layout() {
let expected = "\
# Config configuration
# The HTTP configuration.
# The port to listen on. (default: 8080)
HTTP__PORT=8080
# The host to listen on. (example: localhost)
HTTP__HOST=
# The greeting to use. (default: Hello)
GREETING=Hello
# The name of the user. (default: World, example: John)
NAME=World
";
assert_eq!(env_example::<Config>(), expected);
}
#[test]
fn markdown_table_lists_all_leaf_variables() {
let expected = "\
| Variable | Description | Default | Example |
| --- | --- | --- | --- |
| `HTTP__PORT` | The port to listen on. | `8080` | |
| `HTTP__HOST` | The host to listen on. | | `localhost` |
| `GREETING` | The greeting to use. | `Hello` | |
| `NAME` | The name of the user. | `World` | `John` |
";
assert_eq!(markdown_table::<Config>(), expected);
}
#[test]
fn bare_default_renders_via_display() {
#[derive(confroid::Config, Debug)]
struct WithBare {
#[confroid(default)]
retries: u16,
}
let out = env_example::<WithBare>();
assert!(out.contains("# Retry count. (default: 0)"), "got:\n{out}");
assert!(out.contains("RETRIES=0"), "got:\n{out}");
}