use rstructor::{Instructor, SchemaType};
use serde::{Deserialize, Serialize};
#[derive(Instructor, Serialize, Deserialize, Debug)]
struct ArrayLiteralTests {
#[llm(description = "Array of strings", example = ["apple", "banana", "cherry"])]
string_array: Vec<String>,
#[llm(description = "Array of integers", example = [1, 2, 3, 4])]
int_array: Vec<i32>,
#[llm(description = "Array of floats", example = [1.1, 2.2, 3.3])]
float_array: Vec<f64>,
#[llm(description = "Array of booleans", example = [true, false, true])]
bool_array: Vec<bool>,
#[llm(description = "Empty array", example = [])]
empty_array: Vec<String>,
#[llm(description = "Float values", examples = [10.5, 20.5, 30.5])]
example_floats: f64,
#[llm(description = "Name examples", examples = ["John", "Jane", "Alice", "Bob"])]
example_names: String,
}
#[test]
fn test_array_literal_string_array() {
let schema = ArrayLiteralTests::schema();
let schema_json = schema.to_json();
let string_array_example = &schema_json["properties"]["string_array"]["example"];
assert!(string_array_example.is_array());
let array = string_array_example.as_array().unwrap();
assert_eq!(array.len(), 3);
assert_eq!(array[0], "apple");
assert_eq!(array[1], "banana");
assert_eq!(array[2], "cherry");
}
#[test]
fn test_array_literal_int_array() {
let schema = ArrayLiteralTests::schema();
let schema_json = schema.to_json();
let int_array_example = &schema_json["properties"]["int_array"]["example"];
assert!(int_array_example.is_array());
let array = int_array_example.as_array().unwrap();
assert_eq!(array.len(), 4);
assert_eq!(array[0], 1);
assert_eq!(array[1], 2);
assert_eq!(array[2], 3);
assert_eq!(array[3], 4);
}
#[test]
fn test_array_literal_float_array() {
let schema = ArrayLiteralTests::schema();
let schema_json = schema.to_json();
let float_array_example = &schema_json["properties"]["float_array"]["example"];
assert!(float_array_example.is_array());
let array = float_array_example.as_array().unwrap();
assert_eq!(array.len(), 3);
assert_eq!(array[0], 1.1);
assert_eq!(array[1], 2.2);
assert_eq!(array[2], 3.3);
}
#[test]
fn test_array_literal_bool_array() {
let schema = ArrayLiteralTests::schema();
let schema_json = schema.to_json();
let bool_array_example = &schema_json["properties"]["bool_array"]["example"];
assert!(bool_array_example.is_array());
let array = bool_array_example.as_array().unwrap();
assert_eq!(array.len(), 3);
assert_eq!(array[0], true);
assert_eq!(array[1], false);
assert_eq!(array[2], true);
}
#[test]
fn test_array_literal_empty_array() {
let schema = ArrayLiteralTests::schema();
let schema_json = schema.to_json();
let empty_array_example = &schema_json["properties"]["empty_array"]["example"];
assert!(empty_array_example.is_array());
let array = empty_array_example.as_array().unwrap();
assert_eq!(array.len(), 0);
}
#[test]
fn test_array_literal_multiple_examples() {
let schema = ArrayLiteralTests::schema();
let schema_json = schema.to_json();
let examples = &schema_json["properties"]["example_floats"]["examples"];
assert!(examples.is_array());
let array = examples.as_array().unwrap();
assert_eq!(array.len(), 3);
assert_eq!(array[0], 10.5);
assert_eq!(array[1], 20.5);
assert_eq!(array[2], 30.5);
let examples = &schema_json["properties"]["example_names"]["examples"];
assert!(examples.is_array());
let array = examples.as_array().unwrap();
assert_eq!(array.len(), 4);
assert_eq!(array[0], "John");
assert_eq!(array[1], "Jane");
assert_eq!(array[2], "Alice");
assert_eq!(array[3], "Bob");
}