mirror of
https://github.com/AleoHQ/leo.git
synced 2025-01-03 07:16:50 +03:00
Add test for span
This commit is contained in:
parent
695ca8d998
commit
6a199d1256
@ -31,3 +31,23 @@ impl<'i> From<SpanDef<'i>> 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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user