Skip to content

Commit 9a4bebe

Browse files
committed
Add non-static lifetime snapshot test
1 parent 1101aa8 commit 9a4bebe

File tree

4 files changed

+60
-2
lines changed

4 files changed

+60
-2
lines changed

packages/cw-schema/src/default_impls.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
use crate::{Node, NodeType, Schemaifier};
2-
use alloc::{borrow::Cow, string::String, vec, vec::Vec};
2+
use alloc::{
3+
borrow::{Cow, ToOwned},
4+
string::String,
5+
vec,
6+
vec::Vec,
7+
};
38

49
impl Schemaifier for () {
510
fn visit_schema(visitor: &mut crate::SchemaVisitor) -> crate::DefinitionReference {
@@ -185,3 +190,12 @@ where
185190
T::visit_schema(visitor)
186191
}
187192
}
193+
194+
impl<T> Schemaifier for Cow<'_, T>
195+
where
196+
T: Schemaifier + ToOwned + ?Sized,
197+
{
198+
fn visit_schema(visitor: &mut crate::SchemaVisitor) -> crate::DefinitionReference {
199+
T::visit_schema(visitor)
200+
}
201+
}
Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,18 @@
11
#![allow(dead_code)]
22

33
use cw_schema::Schemaifier;
4+
use std::borrow::Cow;
45

56
#[derive(Schemaifier)]
67
struct NonStatic<'a> {
7-
test: &'a str,
8+
test1: &'a str,
9+
test2: Cow<'a, str>,
10+
test3: Cow<'static, str>,
11+
test4: &'static str,
12+
}
13+
14+
#[test]
15+
fn non_static_schema() {
16+
let schema = cw_schema::schema_of::<NonStatic<'_>>();
17+
insta::assert_json_snapshot!(schema);
818
}

packages/cw-schema/tests/same_name.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![allow(dead_code)]
2+
13
mod module1 {
24
#[derive(cw_schema::Schemaifier)]
35
pub struct Test {
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
---
2+
source: packages/cw-schema/tests/non_static.rs
3+
expression: schema
4+
---
5+
{
6+
"type": "v1",
7+
"root": 1,
8+
"definitions": [
9+
{
10+
"name": "str",
11+
"type": "string"
12+
},
13+
{
14+
"name": "NonStatic",
15+
"type": "struct",
16+
"properties": {
17+
"test1": {
18+
"value": 0
19+
},
20+
"test2": {
21+
"value": 0
22+
},
23+
"test3": {
24+
"value": 0
25+
},
26+
"test4": {
27+
"value": 0
28+
}
29+
}
30+
}
31+
]
32+
}

0 commit comments

Comments
 (0)