Skip to content

Commit

Permalink
feat(main): modularize code base and implement tests (#12)
Browse files Browse the repository at this point in the history
* feat(filetype): implement parsing of filename and comment style

* feat(filetype): implement enum for all filetypes, testing

* feat(comment): implement struct for comment styling

* build(deps): add once_cell dep and remove lazy_static

* feat(mod): include modules and use comments

* feat(mod): filetype enum implementation and tests

* feat(mod): comment styling struct and tests

* feat(filetype): change logic with new enum and structs

* build(cargo): bump version 0.2.0 → 0.2.1

* fix(format): cargo fmt --all changes

* fix(lint): allow dead code for clippy
  • Loading branch information
wilhelmagren committed Oct 1, 2023
1 parent 938adf4 commit cb81d8f
Show file tree
Hide file tree
Showing 4 changed files with 442 additions and 55 deletions.
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "docstring-rs"
version = "0.2.0"
version = "0.2.1"
authors = [ "Wilhelm Ågren <wilhelmagren98@gmail.com>" ]
description = "📒 Generate or update docstrings for new and existing files. "
readme = "README.md"
Expand All @@ -18,4 +18,5 @@ chrono = "0.4.31"
clap = { version = "4.4.4", features = ["derive"] }
env_logger = "0.10.0"
log = "0.4.20"
once_cell = "1.18.0"
text_io = "0.1.12"
73 changes: 73 additions & 0 deletions src/comment.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/*
* MIT License
*
* Copyright (c) 2023 Wilhelm Ågren
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
* File created: 2023-10-01
* Last updated: 2023-10-01
*/

///
#[derive(Debug, Clone, Eq, PartialEq)]
pub struct CommentStyle<'a> {
multi_line_start: &'a str,
normal_comment: &'a str,
multi_line_end: &'a str,
}

///
impl<'a> CommentStyle<'a> {
pub fn new(start: &'a str, normal: &'a str, end: &'a str) -> Self {
CommentStyle {
multi_line_start: start,
normal_comment: normal,
multi_line_end: end,
}
}

pub fn start(&self) -> &'a str {
self.multi_line_start
}

pub fn normal(&self) -> &'a str {
self.normal_comment
}

pub fn end(&self) -> &'a str {
self.multi_line_end
}
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn pub_funcs() {
let start: &str = "##/";
let normal: &str = "# ";
let end: &str = "/##";
let cs = CommentStyle::new(start, normal, end);
assert_eq!(cs.start(), start);
assert_eq!(cs.normal(), normal);
assert_eq!(cs.end(), end);
}
}

0 comments on commit cb81d8f

Please sign in to comment.