Skip to content

Commit

Permalink
Add non-static lifetime snapshot test
Browse files Browse the repository at this point in the history
  • Loading branch information
aumetra committed Aug 27, 2024
1 parent 1101aa8 commit 9a4bebe
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 2 deletions.
16 changes: 15 additions & 1 deletion packages/cw-schema/src/default_impls.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
use crate::{Node, NodeType, Schemaifier};
use alloc::{borrow::Cow, string::String, vec, vec::Vec};
use alloc::{
borrow::{Cow, ToOwned},
string::String,
vec,
vec::Vec,
};

impl Schemaifier for () {
fn visit_schema(visitor: &mut crate::SchemaVisitor) -> crate::DefinitionReference {
Expand Down Expand Up @@ -185,3 +190,12 @@ where
T::visit_schema(visitor)
}
}

impl<T> Schemaifier for Cow<'_, T>
where
T: Schemaifier + ToOwned + ?Sized,
{
fn visit_schema(visitor: &mut crate::SchemaVisitor) -> crate::DefinitionReference {
T::visit_schema(visitor)
}
}
12 changes: 11 additions & 1 deletion packages/cw-schema/tests/non_static.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
#![allow(dead_code)]

use cw_schema::Schemaifier;
use std::borrow::Cow;

#[derive(Schemaifier)]
struct NonStatic<'a> {
test: &'a str,
test1: &'a str,
test2: Cow<'a, str>,
test3: Cow<'static, str>,
test4: &'static str,
}

#[test]
fn non_static_schema() {
let schema = cw_schema::schema_of::<NonStatic<'_>>();
insta::assert_json_snapshot!(schema);
}
2 changes: 2 additions & 0 deletions packages/cw-schema/tests/same_name.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![allow(dead_code)]

mod module1 {
#[derive(cw_schema::Schemaifier)]
pub struct Test {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
---
source: packages/cw-schema/tests/non_static.rs
expression: schema
---
{
"type": "v1",
"root": 1,
"definitions": [
{
"name": "str",
"type": "string"
},
{
"name": "NonStatic",
"type": "struct",
"properties": {
"test1": {
"value": 0
},
"test2": {
"value": 0
},
"test3": {
"value": 0
},
"test4": {
"value": 0
}
}
}
]
}

0 comments on commit 9a4bebe

Please sign in to comment.