chore: fix fmt
This commit is contained in:
parent
2c217c5261
commit
7a21db58bd
67
src/tests.rs
67
src/tests.rs
@ -1,13 +1,12 @@
|
|||||||
// use super::*;
|
// use super::*;
|
||||||
use nu_protocol::{Record, Span, Value};
|
use crate::helpers::{unwrap_value_key, value_to_serde_json, wrap_top_level_if_needed};
|
||||||
use tera::Tera;
|
use crate::{Render, TeraPlugin};
|
||||||
use crate::helpers::{unwrap_value_key, value_to_serde_json, wrap_top_level_if_needed};
|
use nu_protocol::{Record, Span, Value};
|
||||||
use crate::{Render, TeraPlugin};
|
use tera::Tera;
|
||||||
|
|
||||||
|
/// Runs the plugin test examples using nu_plugin_test_support.
|
||||||
/// Runs the plugin test examples using nu_plugin_test_support.
|
#[test]
|
||||||
#[test]
|
fn test_examples() -> Result<(), nu_protocol::ShellError> {
|
||||||
fn test_examples() -> Result<(), nu_protocol::ShellError> {
|
|
||||||
use nu_plugin_test_support::PluginTest;
|
use nu_plugin_test_support::PluginTest;
|
||||||
|
|
||||||
// This will automatically run the examples specified in your command and compare their actual
|
// This will automatically run the examples specified in your command and compare their actual
|
||||||
@ -15,9 +14,9 @@
|
|||||||
// can't be tested this way, but we recommend including it if possible.
|
// can't be tested this way, but we recommend including it if possible.
|
||||||
|
|
||||||
PluginTest::new("tera", TeraPlugin.into())?.test_command_examples(&Render)
|
PluginTest::new("tera", TeraPlugin.into())?.test_command_examples(&Render)
|
||||||
}
|
}
|
||||||
#[test]
|
#[test]
|
||||||
fn test_value_to_serde_json_record() {
|
fn test_value_to_serde_json_record() {
|
||||||
let record = Record::from_raw_cols_vals(
|
let record = Record::from_raw_cols_vals(
|
||||||
vec!["name".to_string(), "age".to_string()],
|
vec!["name".to_string(), "age".to_string()],
|
||||||
vec![
|
vec![
|
||||||
@ -32,10 +31,10 @@
|
|||||||
let json = value_to_serde_json(val).unwrap();
|
let json = value_to_serde_json(val).unwrap();
|
||||||
assert_eq!(json["name"], "Akasha");
|
assert_eq!(json["name"], "Akasha");
|
||||||
assert_eq!(json["age"], 42);
|
assert_eq!(json["age"], 42);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_value_to_serde_json_list() {
|
fn test_value_to_serde_json_list() {
|
||||||
let val = Value::list(
|
let val = Value::list(
|
||||||
vec![
|
vec![
|
||||||
Value::int(1, Span::test_data()),
|
Value::int(1, Span::test_data()),
|
||||||
@ -45,45 +44,45 @@
|
|||||||
);
|
);
|
||||||
let json = value_to_serde_json(val).unwrap();
|
let json = value_to_serde_json(val).unwrap();
|
||||||
assert_eq!(json, serde_json::json!([1, 2]));
|
assert_eq!(json, serde_json::json!([1, 2]));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_value_to_serde_json_string() {
|
fn test_value_to_serde_json_string() {
|
||||||
let val = Value::string("hello", Span::test_data());
|
let val = Value::string("hello", Span::test_data());
|
||||||
let json = value_to_serde_json(val).unwrap();
|
let json = value_to_serde_json(val).unwrap();
|
||||||
assert_eq!(json, serde_json::json!("hello"));
|
assert_eq!(json, serde_json::json!("hello"));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_unwrap_value_key_simple() {
|
fn test_unwrap_value_key_simple() {
|
||||||
let json = serde_json::json!({"value": {"name": "Akasha"}});
|
let json = serde_json::json!({"value": {"name": "Akasha"}});
|
||||||
let unwrapped = unwrap_value_key(json);
|
let unwrapped = unwrap_value_key(json);
|
||||||
assert_eq!(unwrapped["name"], "Akasha");
|
assert_eq!(unwrapped["name"], "Akasha");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_unwrap_value_key_nested() {
|
fn test_unwrap_value_key_nested() {
|
||||||
let json = serde_json::json!({"value": {"value": {"name": "Akasha"}}});
|
let json = serde_json::json!({"value": {"value": {"name": "Akasha"}}});
|
||||||
let unwrapped = unwrap_value_key(json);
|
let unwrapped = unwrap_value_key(json);
|
||||||
assert_eq!(unwrapped["name"], "Akasha");
|
assert_eq!(unwrapped["name"], "Akasha");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_unwrap_value_key_non_object() {
|
fn test_unwrap_value_key_non_object() {
|
||||||
let json = serde_json::json!(42);
|
let json = serde_json::json!(42);
|
||||||
let unwrapped = unwrap_value_key(json);
|
let unwrapped = unwrap_value_key(json);
|
||||||
assert_eq!(unwrapped["value"], 42);
|
assert_eq!(unwrapped["value"], 42);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_unwrap_value_key_object() {
|
fn test_unwrap_value_key_object() {
|
||||||
let json = serde_json::json!({"name": "Akasha"});
|
let json = serde_json::json!({"name": "Akasha"});
|
||||||
let unwrapped = unwrap_value_key(json);
|
let unwrapped = unwrap_value_key(json);
|
||||||
assert_eq!(unwrapped["name"], "Akasha");
|
assert_eq!(unwrapped["name"], "Akasha");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_render_pipeline() {
|
fn test_render_pipeline() {
|
||||||
let template = "Hello, {{ name }}!";
|
let template = "Hello, {{ name }}!";
|
||||||
let mut tera = Tera::default();
|
let mut tera = Tera::default();
|
||||||
tera.add_raw_template("test", template).unwrap();
|
tera.add_raw_template("test", template).unwrap();
|
||||||
@ -100,4 +99,4 @@
|
|||||||
let context = tera::Context::from_serialize(context_json).unwrap();
|
let context = tera::Context::from_serialize(context_json).unwrap();
|
||||||
let output = tera.render("test", &context).unwrap();
|
let output = tera.render("test", &context).unwrap();
|
||||||
assert_eq!(output, "Hello, Akasha!");
|
assert_eq!(output, "Hello, Akasha!");
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user