Skip to content

Commit

Permalink
Add tests and linting
Browse files Browse the repository at this point in the history
  • Loading branch information
nitaliano committed Nov 19, 2024
1 parent 7715c5a commit 8a74f97
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 3 deletions.
2 changes: 1 addition & 1 deletion packages/toml-parser/build.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
extern crate napi_build;

fn main() {
napi_build::setup();
napi_build::setup();
}
5 changes: 4 additions & 1 deletion packages/toml-parser/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
"main": "./index.node",
"version": "0.0.1",
"scripts": {
"build": "napi build --release"
"build": "napi build --release",
"test": "cargo test",
"lint": "cargo fmt --check",
"lint:fix": "cargo fmt && cargo fmt --check"
},
"dependencies": {
"@napi-rs/cli": "^2.18.4"
Expand Down
25 changes: 24 additions & 1 deletion packages/toml-parser/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ use std::collections::HashMap;
use napi::bindgen_prelude::*;
use napi_derive::napi;

use toml;
use serde_json;
use toml;

type TomlContent = HashMap<String, toml::value::Value>;

Expand All @@ -24,3 +24,26 @@ pub fn parse_toml(toml_str: String) -> Result<String> {
}
}
}

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

#[test]
fn can_parse_toml() {
let toml_str = r#"
[testcli]
test_key = "test"
[testcli.test_nested]
test_arr = [1, 2, 3]
"#
.to_string();
let result = parse_toml(toml_str);
assert_eq!(result.is_ok(), true);
assert_eq!(
result.unwrap(),
r#"{"testcli":{"test_key":"test","test_nested":{"test_arr":[1,2,3]}}}"#
);
}
}

0 comments on commit 8a74f97

Please sign in to comment.