use prompty::model::FunctionTool;
use prompty::model::context::{LoadContext, SaveContext};
#[test]
fn test_function_tool_load_json() {
let json = r####"
{
"kind": "function",
"parameters": {
"firstName": {
"kind": "string",
"default": "Jane"
},
"lastName": {
"kind": "string",
"default": "Doe"
},
"question": {
"kind": "string",
"default": "What is the meaning of life?"
}
},
"strict": true
}
"####;
let result = FunctionTool::from_json(json, &LoadContext::default());
assert!(result.is_ok(), "Failed to load from JSON: {:?}", result.err());
let instance = result.unwrap();
assert_eq!(instance.kind, "function");
assert!(instance.strict.is_some(), "Expected strict to be Some");
assert_eq!(instance.strict.as_ref().unwrap(), &true);
}
#[test]
fn test_function_tool_load_yaml() {
let yaml = r####"
kind: function
parameters:
firstName:
kind: string
default: Jane
lastName:
kind: string
default: Doe
question:
kind: string
default: What is the meaning of life?
strict: true
"####;
let result = FunctionTool::from_yaml(yaml, &LoadContext::default());
assert!(result.is_ok(), "Failed to load from YAML: {:?}", result.err());
let instance = result.unwrap();
assert_eq!(instance.kind, "function");
assert!(instance.strict.is_some(), "Expected strict to be Some");
}
#[test]
fn test_function_tool_roundtrip() {
let json = r####"
{
"kind": "function",
"parameters": {
"firstName": {
"kind": "string",
"default": "Jane"
},
"lastName": {
"kind": "string",
"default": "Doe"
},
"question": {
"kind": "string",
"default": "What is the meaning of life?"
}
},
"strict": true
}
"####;
let result = FunctionTool::from_json(json, &LoadContext::default());
assert!(result.is_ok(), "Failed to load: {:?}", result.err());
let instance = result.unwrap();
let json_output = instance.to_json(&SaveContext::default());
assert!(json_output.is_ok(), "Failed to serialize to JSON: {:?}", json_output.err());
}
#[test]
fn test_function_tool_load_json_1() {
let json = r####"
{
"kind": "function",
"parameters": [
{
"name": "firstName",
"kind": "string",
"default": "Jane"
},
{
"name": "lastName",
"kind": "string",
"default": "Doe"
},
{
"name": "question",
"kind": "string",
"default": "What is the meaning of life?"
}
],
"strict": true
}
"####;
let result = FunctionTool::from_json(json, &LoadContext::default());
assert!(result.is_ok(), "Failed to load from JSON: {:?}", result.err());
let instance = result.unwrap();
assert_eq!(instance.kind, "function");
assert!(instance.strict.is_some(), "Expected strict to be Some");
assert_eq!(instance.strict.as_ref().unwrap(), &true);
}
#[test]
fn test_function_tool_load_yaml_1() {
let yaml = r####"
kind: function
parameters:
- name: firstName
kind: string
default: Jane
- name: lastName
kind: string
default: Doe
- name: question
kind: string
default: What is the meaning of life?
strict: true
"####;
let result = FunctionTool::from_yaml(yaml, &LoadContext::default());
assert!(result.is_ok(), "Failed to load from YAML: {:?}", result.err());
let instance = result.unwrap();
assert_eq!(instance.kind, "function");
assert!(instance.strict.is_some(), "Expected strict to be Some");
}
#[test]
fn test_function_tool_roundtrip_1() {
let json = r####"
{
"kind": "function",
"parameters": [
{
"name": "firstName",
"kind": "string",
"default": "Jane"
},
{
"name": "lastName",
"kind": "string",
"default": "Doe"
},
{
"name": "question",
"kind": "string",
"default": "What is the meaning of life?"
}
],
"strict": true
}
"####;
let result = FunctionTool::from_json(json, &LoadContext::default());
assert!(result.is_ok(), "Failed to load: {:?}", result.err());
let instance = result.unwrap();
let json_output = instance.to_json(&SaveContext::default());
assert!(json_output.is_ok(), "Failed to serialize to JSON: {:?}", json_output.err());
}