Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions specta-typescript/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,12 @@ use specta::{
/// use specta::Type;
/// use specta_typescript::Any;
///
/// # #[cfg(feature = "serde")] {
/// #[derive(Serialize, Type)]
/// pub struct Demo {
/// pub field: Any<String>,
/// }
/// # }
/// ```
pub struct Any<T = ()>(T);

Expand Down Expand Up @@ -102,10 +104,12 @@ impl<T: serde::Serialize> serde::Serialize for Any<T> {
/// use specta::Type;
/// use specta_typescript::Unknown;
///
/// # #[cfg(feature = "serde")] {
/// #[derive(Serialize, Type)]
/// pub struct Demo {
/// pub field: Unknown<String>,
/// }
/// # }
/// ```
pub struct Unknown<T = ()>(T);

Expand Down Expand Up @@ -174,10 +178,12 @@ impl<T: serde::Serialize> serde::Serialize for Unknown<T> {
/// use specta::Type;
/// use specta_typescript::Never;
///
/// # #[cfg(feature = "serde")] {
/// #[derive(Serialize, Type)]
/// pub struct Demo {
/// pub field: Never<String>,
/// }
/// # }
/// ```
pub struct Never<T = ()>(T);

Expand Down
6 changes: 5 additions & 1 deletion tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ path = "tests/lib.rs"
harness = true

[dependencies]
specta = { path = "../specta", features = ["derive", "serde_json", "serde_yaml", "unstable_json_macro", "toml"] }
specta = { path = "../specta", features = ["derive", "serde_json", "serde_yaml", "unstable_json_macro", "toml", "chrono", "either", "ulid", "glam"] }
specta-serde = { path = "../specta-serde" }
specta-typescript = { path = "../specta-typescript" }
specta-util = { path = "../specta-util", features = ["serde"] } # TODO: Remove `serde` feature
Expand All @@ -23,3 +23,7 @@ serde_json = "1.0.140"
serde_yaml = "0.9.34"
toml = "0.8.20"
insta = "1.42.2"
chrono = { version = "0.4", default-features = false, features = ["clock"] }
either = { version = "1.15", default-features = false }
ulid = { version = "1.2", default-features = false, features = [] }
glam = { version = "0.30", default-features = false, features = ["std"] }
20 changes: 0 additions & 20 deletions tests/json.rs

This file was deleted.

1 change: 1 addition & 0 deletions tests/tests/export.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ pub struct ReferingToUnexportedType {

// TODO: Enable this test on Windows again. It's ordering of types is different for seemingly no reason.
#[cfg(all(not(target_os = "windows"), all(feature = "export", feature = "ts")))]
// TODO: This feature guard is bogus because this test package doesn't define any features.
#[test]
fn test_export_feature() {
use specta::{
Expand Down
6 changes: 5 additions & 1 deletion tests/tests/json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,13 @@ fn test_json_macro() {

// TODO: Fix these
// assert_ts!(() => json!({ "a": "b" }), r#"{ "a": "b" }"#);
// assert_ts!(() => json!({ "hello": "world" }), "{ hello: string }");
// assert_ts!(() => json!({
// "hello": "world",
// }), "{ hello: string }");
// assert_ts!(() => json!({ "a": 5, "c": true, "d": false, "e": 42u8, "f": 2.7 }), r#""#);
// assert_ts!(() => json!([]), "[]");
// assert_ts!(() => json!(["a", "b", "c"]), "");
// assert_ts!(() => json!(["a", "b", "c"]), "string[]");
// assert_ts!(() => json!([{}, {}, {}]), "");
// assert_ts!(() => json!([{ "n": "0" }, { "n": "1" }, { "n": "2" }]), "");
}
4 changes: 1 addition & 3 deletions tests/tests/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,7 @@ mod ty_override;
mod type_collection;
mod type_map;
mod typescript;
// TODO: Bring this back
// #[cfg(all(feature = "ulid", feature = "typescript"))]
// mod ulid;
mod ulid;

#[test]
fn test_compile_errors() {
Expand Down
2 changes: 1 addition & 1 deletion tests/tests/remote_impls.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#[test]
#[cfg(feature = "glam")]
fn typescript_types_glam() {
use crate::ts::assert_ts;

Expand Down Expand Up @@ -34,6 +33,7 @@ fn typescript_types_glam() {

#[test]
#[cfg(feature = "bevy_ecs")]
// TODO: This feature guard is bogus because this test package doesn't define any features.
fn typescript_types_bevy_ecs() {
use specta_typescript::{self, BigIntExportBehavior, ExportConfig, ExportPath};

Expand Down
7 changes: 2 additions & 5 deletions tests/tests/ts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -324,11 +324,8 @@ fn typescript_types() {
assert_ts!(PhantomData<String>, r#"null"#);
assert_ts!(Infallible, r#"never"#);

#[cfg(feature = "either")]
{
assert_ts!(either::Either<String, i32>, r#"string | number"#);
assert_ts!(either::Either<i16, i32>, r#"number"#);
}
assert_ts!(either::Either<String, i32>, r#"string | number"#);
assert_ts!(either::Either<i16, i32>, r#"number"#);

assert_ts!(Any, r#"any"#);

Expand Down
4 changes: 2 additions & 2 deletions tests/tests/ts_rs/generics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ struct GenericAutoBound2<T: PartialEq> {
#[specta(export = false)]
struct Container1 {
foo: Generic1<u32>,
bar: Box<HashSet<Generic1<u32>>>,
baz: Box<BTreeMap<String, Rc<Generic1<String>>>>,
bar: HashSet<Generic1<u32>>,
baz: BTreeMap<String, Rc<Generic1<String>>>,
}

#[test]
Expand Down
1 change: 1 addition & 0 deletions tests/tests/ts_rs/indexmap.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#![cfg(feature = "indexmap")]
// TODO: This feature guard is bogus because this test package doesn't define any features.

use indexmap::{IndexMap, IndexSet};
use specta::Type;
Expand Down
1 change: 0 additions & 1 deletion tests/tests/ts_rs/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
mod arrays;
#[cfg(feature = "chrono")]
mod chrono;
mod field_rename;
mod flatten;
Expand Down
1 change: 0 additions & 1 deletion tests/tests/ts_rs/union_serde.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ enum Untagged {
None,
}

#[cfg(feature = "serde")]
#[test]
fn test_serde_enum() {
assert_ts!(SimpleEnumA, r#"{ kind: "A" } | { kind: "B" }"#);
Expand Down
1 change: 0 additions & 1 deletion tests/tests/ts_rs/union_with_internal_tag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ enum EnumWithInternalTag2 {
}

#[test]
#[cfg(feature = "serde")]
fn test_enums_with_internal_tags() {
assert_ts!(
EnumWithInternalTag,
Expand Down
1 change: 0 additions & 1 deletion tests/tests/type_collection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ fn type_collection_duplicate_register_ty() {

// TODO: Bring this back
// #[test]
// #[cfg(feature = "typescript")]
// fn type_collection_ts() {
// let result = TypeCollection::default()
// .register::<A>()
Expand Down
Loading