#![allow(dead_code)]
use std::{concat, fs};
use py_rs::PY;
#[derive(PY)]
#[py(export_to = "docs/")]
struct A {
name: String,
}
#[derive(PY)]
#[py(export_to = "docs/")]
struct B {
name: String,
}
#[derive(PY)]
#[py(export_to = "docs/")]
struct C {}
#[derive(PY)]
#[py(export_to = "docs/")]
struct D;
#[derive(PY)]
#[py(export_to = "docs/")]
enum E {}
#[derive(PY)]
#[py(export_to = "docs/")]
enum F {
VarA,
VarB(),
VarC {
variant_field: i32,
},
}
#[derive(PY)]
#[py(export_to = "docs/")]
struct G {
some_other_field: i32,
#[py(flatten)]
f: F,
}
#[derive(PY)]
#[py(export_to = "docs/")]
struct H {
foo: i32,
}
#[test]
fn export_a() {
A::export().unwrap();
let expected_content = if cfg!(feature = "format") {
concat!(
"# This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.\n",
"from pydantic import BaseModel\n",
"from enum import StrEnum\n",
"\n",
"\n",
"class A(BaseModel):\n",
"\t\"\"\"\n",
"\tDoc comment.\n",
"\tSupports new lines.\n",
"\t\n",
"\tTesting\n",
"\t\"\"\"\n",
"export type A = {\n",
" /**\n",
" * Doc of field\n",
" *\n",
" * Testing\n",
" */\n",
" name: string;\n",
"};\n",
)
} else {
concat!(
"// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.\n\n",
"/**\n",
" * Doc comment.\n",
" * Supports new lines.\n",
" *\n",
" * Testing\n",
" */\n",
"export type A = { \n",
"/**\n",
" * Doc of field\n",
" *\n",
" * Testing\n",
" */\n",
"name: string, };",
"\n",
)
};
let actual_content = fs::read_to_string(A::default_output_path().unwrap()).unwrap();
assert_eq!(actual_content, expected_content);
}
#[test]
fn export_b() {
B::export().unwrap();
let expected_content = if cfg!(feature = "format") {
concat!(
"// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.\n\n",
"/**\n",
" * Doc comment.\n",
" * Supports new lines.\n",
" *\n",
" * Testing\n",
" */\n",
"export type B = {\n",
" /**\n",
" * Doc of field\n",
" *\n",
" * Testing\n",
" */\n",
" name: string;\n",
"};\n",
)
} else {
concat!(
"// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.\n\n",
"/**\n",
" * Doc comment.\n",
" * Supports new lines.\n",
" *\n",
" * Testing\n",
" */\n",
"export type B = { \n",
"/**\n",
" * Doc of field\n",
" *\n",
" * Testing\n",
" */\n",
"name: string, };",
"\n",
)
};
let actual_content = fs::read_to_string(B::default_output_path().unwrap()).unwrap();
assert_eq!(actual_content, expected_content);
}
#[test]
fn export_c() {
C::export().unwrap();
let expected_content = if cfg!(feature = "format") {
concat!(
"// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.\n\n",
"/**\n",
" * Doc comment.\n",
" * Supports new lines.\n",
" *\n",
" * Testing\n",
" */\n",
"export type C = Record<string, never>;\n",
)
} else {
concat!(
"// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.\n\n",
"/**\n",
" * Doc comment.\n",
" * Supports new lines.\n",
" *\n",
" * Testing\n",
" */\n",
"export type C = Record<string, never>;",
"\n",
)
};
let actual_content = fs::read_to_string(C::default_output_path().unwrap()).unwrap();
assert_eq!(actual_content, expected_content);
}
#[test]
fn export_d() {
D::export().unwrap();
let expected_content = if cfg!(feature = "format") {
concat!(
"// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.\n\n",
"/**\n",
" * Doc comment.\n",
" * Supports new lines.\n",
" *\n",
" * Testing\n",
" */\n",
"export type D = null;\n",
)
} else {
concat!(
"// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.\n\n",
"/**\n",
" * Doc comment.\n",
" * Supports new lines.\n",
" *\n",
" * Testing\n",
" */\n",
"export type D = null;",
"\n",
)
};
let actual_content = fs::read_to_string(D::default_output_path().unwrap()).unwrap();
assert_eq!(actual_content, expected_content);
}
#[test]
fn export_e() {
E::export().unwrap();
let expected_content = if cfg!(feature = "format") {
concat!(
"// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.\n\n",
"/**\n",
" * Doc comment.\n",
" * Supports new lines.\n",
" *\n",
" * Testing\n",
" */\n",
"export type E = never;\n",
)
} else {
concat!(
"// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.\n\n",
"/**\n",
" * Doc comment.\n",
" * Supports new lines.\n",
" *\n",
" * Testing\n",
" */\n",
"export type E = never;",
"\n",
)
};
let actual_content = fs::read_to_string(E::default_output_path().unwrap()).unwrap();
assert_eq!(actual_content, expected_content);
}
#[test]
fn export_f() {
F::export().unwrap();
let expected_content = if cfg!(feature = "format") {
concat!(
"// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.\n\n",
"/**\n",
" * Doc comment.\n",
" * Supports new lines.\n",
" *\n",
" * Testing\n",
" */\n",
"export type F = \"VarA\" | { \"VarB\": never[] } | {\n",
" \"VarC\": {\n",
" /**\n",
" * Doc of field of variant\n",
" *\n",
" * Testing\n",
" */\n",
" variant_field: number;\n",
" };\n",
"};\n",
)
} else {
concat!(
"// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.\n\n",
"/**\n",
" * Doc comment.\n",
" * Supports new lines.\n",
" *\n",
" * Testing\n",
" */\n",
"export type F = \"VarA\" | { \"VarB\": never[] } | { \"VarC\": { \n",
"/**\n",
" * Doc of field of variant\n",
" *\n",
" * Testing\n",
" */\n",
"variant_field: number, } };",
"\n",
)
};
let actual_content = fs::read_to_string(F::default_output_path().unwrap()).unwrap();
assert_eq!(actual_content, expected_content);
}
#[test]
fn export_g() {
G::export().unwrap();
let expected_content = if cfg!(feature = "format") {
concat!(
"// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.\n\n",
"export type G =\n",
" & {\n",
" /**\n",
" * Docs\n",
" */\n",
" some_other_field: number;\n",
" }\n",
" & (\"VarA\" | { \"VarB\": never[] } | {\n",
" \"VarC\": {\n",
" /**\n",
" * Doc of field of variant\n",
" *\n",
" * Testing\n",
" */\n",
" variant_field: number;\n",
" };\n",
" });\n",
)
} else {
concat!(
"// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.\n",
"\n",
"export type G = { \n",
"/**\n",
" * Docs\n",
" */\n",
"some_other_field: number, } & (\"VarA\" | { \"VarB\": never[] } | { \"VarC\": { \n",
"/**\n",
" * Doc of field of variant\n",
" *\n",
" * Testing\n",
" */\n",
"variant_field: number, } });",
"\n",
)
};
let actual_content = fs::read_to_string(G::default_output_path().unwrap()).unwrap();
assert_eq!(actual_content, expected_content);
}
#[test]
fn export_h() {
H::export().unwrap();
let expected_content = if cfg!(feature = "format") {
concat!(
"// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.\n\n",
"/**\n",
" * Block doc comment\n",
" *\n",
" * works\n",
" */\n",
"export type H = { foo: number };\n",
)
} else {
concat!(
"// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.\n\n",
"/**\n",
" * Block doc comment\n",
" *\n",
" * works\n",
" */\n",
"export type H = { foo: number, };\n",
)
};
let actual_content = fs::read_to_string(H::default_output_path().unwrap()).unwrap();
assert_eq!(actual_content, expected_content);
}