diff --git a/ast/src/span.rs b/ast/src/span.rs index c0708a37c8..28c35f9247 100644 --- a/ast/src/span.rs +++ b/ast/src/span.rs @@ -31,3 +31,23 @@ impl<'i> From> for Span<'i> { Span::new(def.input, def.start, def.end).unwrap() } } + +#[test] +fn test_span_def() { + // Wrapper serializable JSON struct + #[derive(Serialize)] + struct Element<'ast> { + #[serde(with = "SpanDef")] + span: Span<'ast>, + } + + // Starting value + let span = Span::new("hello world", 1, 5).unwrap(); + let element = Element { span }; + + // Attempt to serialize span to string. + let output = serde_json::to_string(&element).unwrap(); + + let expected_output = "{\"span\":{\"input\":\"ello\",\"start\":1,\"end\":5}}"; + assert_eq!(expected_output, output); +}