Added and updated documentation and tests

Some undocumented functions and methods are now documented and tested.

Some doc tests were modified to become compilable, going from `ignore`
to `no_run`, or runable, going from `no_run` to regular tests.
This commit is contained in:
Lucien Cartier-Tilet 2020-07-11 17:48:27 +02:00
parent 8ddd33d76d
commit 78541f10ba
Signed by: phundrak
GPG Key ID: BD7789E705CB8DCA
3 changed files with 33 additions and 12 deletions

View File

@ -24,17 +24,17 @@ const RULESET_CURRENT_VERSION: i32 = 1;
///
/// # Example
///
/// ```ignore
/// # use lang_evolve_core::settings::*;
/// # use lang_evolve_core::encode_settings;
/// use std::io::{Error, ErrorKind};
/// ```no_run
/// use std::path::Path;
/// let filetype = utils::get_file_type(Path::new("./path/to/file.json"));
/// let s = Settings::new();
/// use lang_evolve_core::utils;
///
/// let settings = Settings::new();
/// let filetype = utils::get_file_type(Path::new("settings.yml"));
///
/// let content = match filetype {
/// utils::SettingsType::Yaml => encode_settings!(serde_yaml, &s).unwrap(),
/// utils::SettingsType::Json => encode_settings!(serde_json, &s).unwrap(),
/// _ => panic!("Could not encode settings"),
/// SettingsType::Yaml => encode_settings!(serde_yaml, &settings),
/// SettingsType::Json => encode_settings!(serde_json, &settings),
/// _ => String::from("Error!"),
/// };
/// ```
///
@ -64,7 +64,7 @@ macro_rules! encode_settings {
///
/// # Example
///
/// ```ignore
/// ```no_run
/// # use lang_evolve_core::decode_settings;
/// let str = r#"{"version":"1","categories":[],"rules":[]}"#;
/// let settings = decode_settings!(serde_json, str);
@ -162,9 +162,15 @@ impl Settings {
///
/// # Example
///
/// ```no_run
/// ```
/// use std::path::Path;
/// use lang_evolve_core::settings::Settings;
/// # use lang_evolve_core::settings::Settings;
/// # let s = Settings::new();
/// # for path in vec!["settings.json", "settings.yaml", "settings.yml"] {
/// # let path = Path::new(path);
/// # s.export(&path).unwrap();
/// # }
///
/// let path_json = Path::new("settings.json");
/// let _s_json = Settings::import(&path_json).unwrap();
///

View File

@ -29,6 +29,15 @@ impl Rule {
/// the input text
/// * `to` - literal string that represents the regex text that should
/// replaced the text matched by `from`
///
/// # Example
/// ```
/// # use lazy_static::lazy_static;
/// # #[path = "mod.rs"]
/// # mod rule;
/// # use rule::Rule;
/// let rule = Rule::new("ab+c*", "ab");
/// ```
pub fn new(from: &str, to: &str) -> Self {
Rule {
from: Regex::new(from),

View File

@ -4,10 +4,16 @@ use std::{fmt, ops};
pub struct Regex(regex::Regex);
impl Regex {
/// Create a new Regex wrapper around regex::Regex;
///
/// # Arguments
///
/// * `s` - string litteral from which to create the new Regex
pub fn new(s: &str) -> Self {
Self(regex::Regex::new(s).unwrap())
}
/// Returns a string literal representation of the Regex
pub fn as_str(&self) -> &str {
self.0.as_str()
}