pharmsol-dsl 0.27.1

Backend-neutral frontend crate for the pharmsol model DSL.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
use std::fmt;
use std::sync::Arc;

use serde::Serialize;

#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub struct Span {
    pub start: usize,
    pub end: usize,
}

impl Span {
    pub const fn new(start: usize, end: usize) -> Self {
        Self { start, end }
    }

    pub const fn empty(offset: usize) -> Self {
        Self {
            start: offset,
            end: offset,
        }
    }

    pub fn join(self, other: Self) -> Self {
        Self {
            start: self.start.min(other.start),
            end: self.end.max(other.end),
        }
    }

    pub const fn shifted(self, delta: usize) -> Self {
        Self {
            start: self.start + delta,
            end: self.end + delta,
        }
    }
}

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct DiagnosticCode {
    value: &'static str,
}

impl DiagnosticCode {
    pub const fn new(value: &'static str) -> Self {
        Self { value }
    }

    pub const fn as_str(self) -> &'static str {
        self.value
    }
}

impl fmt::Display for DiagnosticCode {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        f.write_str(self.value)
    }
}

pub const DSL_PARSE_GENERIC: DiagnosticCode = DiagnosticCode::new("DSL1000");
pub const DSL_SEMANTIC_GENERIC: DiagnosticCode = DiagnosticCode::new("DSL2000");
pub const DSL_LOWERING_GENERIC: DiagnosticCode = DiagnosticCode::new("DSL3000");
pub const DSL_BACKEND_GENERIC: DiagnosticCode = DiagnosticCode::new("DSL4000");

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum DiagnosticSeverity {
    Error,
}

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum DiagnosticPhase {
    Parse,
    Semantic,
    Lowering,
    Backend,
}

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum DiagnosticLabelKind {
    Primary,
    Secondary,
    Context,
}

#[derive(Debug, Clone, PartialEq, Eq)]
pub struct DiagnosticLabel {
    pub kind: DiagnosticLabelKind,
    pub span: Span,
    pub message: Option<String>,
}

impl DiagnosticLabel {
    pub fn primary(span: Span) -> Self {
        Self {
            kind: DiagnosticLabelKind::Primary,
            span,
            message: None,
        }
    }

    pub fn secondary(span: Span, message: impl Into<String>) -> Self {
        Self {
            kind: DiagnosticLabelKind::Secondary,
            span,
            message: Some(message.into()),
        }
    }

    pub fn context(span: Span, message: impl Into<String>) -> Self {
        Self {
            kind: DiagnosticLabelKind::Context,
            span,
            message: Some(message.into()),
        }
    }
}

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Applicability {
    Always,
    MaybeIncorrect,
}

#[derive(Debug, Clone, PartialEq, Eq)]
pub struct TextEdit {
    pub span: Span,
    pub replacement: String,
}

#[derive(Debug, Clone, PartialEq, Eq)]
pub struct DiagnosticSuggestion {
    pub message: String,
    pub edits: Vec<TextEdit>,
    pub applicability: Applicability,
}

#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Diagnostic {
    pub code: DiagnosticCode,
    pub severity: DiagnosticSeverity,
    pub phase: DiagnosticPhase,
    pub message: String,
    pub labels: Vec<DiagnosticLabel>,
    pub notes: Vec<String>,
    pub helps: Vec<String>,
    pub suggestions: Vec<DiagnosticSuggestion>,
}

impl Diagnostic {
    pub fn error(
        code: DiagnosticCode,
        phase: DiagnosticPhase,
        message: impl Into<String>,
        span: Span,
    ) -> Self {
        Self {
            code,
            severity: DiagnosticSeverity::Error,
            phase,
            message: message.into(),
            labels: vec![DiagnosticLabel::primary(span)],
            notes: Vec::new(),
            helps: Vec::new(),
            suggestions: Vec::new(),
        }
    }

    pub fn primary_span(&self) -> Span {
        self.labels
            .iter()
            .find(|label| label.kind == DiagnosticLabelKind::Primary)
            .map(|label| label.span)
            .unwrap_or_default()
    }

    pub fn with_label(mut self, label: DiagnosticLabel) -> Self {
        self.labels.push(label);
        self
    }

    pub fn with_secondary_label(mut self, span: Span, message: impl Into<String>) -> Self {
        self.labels.push(DiagnosticLabel::secondary(span, message));
        self
    }

    pub fn with_context_label(mut self, span: Span, message: impl Into<String>) -> Self {
        self.labels.push(DiagnosticLabel::context(span, message));
        self
    }

    pub fn with_note(mut self, note: impl Into<String>) -> Self {
        self.notes.push(note.into());
        self
    }

    pub fn with_help(mut self, help: impl Into<String>) -> Self {
        self.helps.push(help.into());
        self
    }

    pub fn with_suggestion(mut self, suggestion: DiagnosticSuggestion) -> Self {
        self.suggestions.push(suggestion);
        self
    }

    pub fn shifted(mut self, delta: usize) -> Self {
        for label in &mut self.labels {
            label.span = label.span.shifted(delta);
        }
        for suggestion in &mut self.suggestions {
            for edit in &mut suggestion.edits {
                edit.span = edit.span.shifted(delta);
            }
        }
        self
    }

    pub fn render(&self, src: &str) -> String {
        let mut rendered = String::new();
        rendered.push_str(&format!(
            "{}[{}]: {}\n",
            self.severity.as_str(),
            self.code,
            self.message
        ));
        let primary = self.primary_span();
        let (line, column, _, _) = line_info(src, primary.start.min(src.len()));
        rendered.push_str(&format!("  --> line {}, column {}\n", line, column));

        if !self.labels.is_empty() {
            let gutter = self
                .labels
                .iter()
                .map(|label| line_info(src, label.span.start.min(src.len())).0)
                .max()
                .unwrap_or(line)
                .to_string()
                .len();
            rendered.push_str(&format!("{:>width$} |\n", "", width = gutter));
            for label in &self.labels {
                rendered.push_str(&render_label(src, label, &self.message, gutter));
            }
        }
        for note in &self.notes {
            rendered.push_str(&format!("  = note: {}\n", note,));
        }
        for help in &self.helps {
            rendered.push_str(&format!("  = help: {}\n", help,));
        }
        for suggestion in &self.suggestions {
            rendered.push_str(&format!("  = suggestion: {}\n", suggestion.message,));
        }
        rendered
    }
}

#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
pub struct DiagnosticReport {
    pub source: DiagnosticReportSource,
    pub diagnostics: Vec<DiagnosticReportEntry>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub rendered: Option<String>,
}

impl DiagnosticReport {
    pub fn from_diagnostics(
        source_name: impl Into<String>,
        source_text: Option<&str>,
        diagnostics: &[Diagnostic],
    ) -> Self {
        Self {
            source: DiagnosticReportSource {
                name: source_name.into(),
                byte_len: source_text.map(str::len),
            },
            diagnostics: diagnostics
                .iter()
                .map(|diagnostic| DiagnosticReportEntry::from_diagnostic(diagnostic, source_text))
                .collect(),
            rendered: source_text.map(|src| render_diagnostics(diagnostics, src)),
        }
    }

    pub fn to_json(&self) -> Result<String, serde_json::Error> {
        serde_json::to_string(self)
    }

    pub fn to_json_pretty(&self) -> Result<String, serde_json::Error> {
        serde_json::to_string_pretty(self)
    }
}

#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
pub struct DiagnosticReportSource {
    pub name: String,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub byte_len: Option<usize>,
}

#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
pub struct DiagnosticReportEntry {
    pub code: String,
    pub severity: String,
    pub phase: String,
    pub message: String,
    pub labels: Vec<DiagnosticReportLabel>,
    pub notes: Vec<String>,
    pub helps: Vec<String>,
    pub suggestions: Vec<DiagnosticReportSuggestion>,
}

impl DiagnosticReportEntry {
    fn from_diagnostic(diagnostic: &Diagnostic, source_text: Option<&str>) -> Self {
        Self {
            code: diagnostic.code.as_str().to_string(),
            severity: diagnostic.severity.as_str().to_string(),
            phase: diagnostic.phase.as_str().to_string(),
            message: diagnostic.message.clone(),
            labels: diagnostic
                .labels
                .iter()
                .map(|label| DiagnosticReportLabel::from_label(label, source_text))
                .collect(),
            notes: diagnostic.notes.clone(),
            helps: diagnostic.helps.clone(),
            suggestions: diagnostic
                .suggestions
                .iter()
                .map(|suggestion| {
                    DiagnosticReportSuggestion::from_suggestion(suggestion, source_text)
                })
                .collect(),
        }
    }
}

#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
pub struct DiagnosticReportLabel {
    pub kind: String,
    pub span: DiagnosticReportSpan,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub message: Option<String>,
}

impl DiagnosticReportLabel {
    fn from_label(label: &DiagnosticLabel, source_text: Option<&str>) -> Self {
        Self {
            kind: label.kind.as_str().to_string(),
            span: DiagnosticReportSpan::from_span(label.span, source_text),
            message: label.message.clone(),
        }
    }
}

#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
pub struct DiagnosticReportSuggestion {
    pub message: String,
    pub edits: Vec<DiagnosticReportEdit>,
    pub applicability: String,
}

impl DiagnosticReportSuggestion {
    fn from_suggestion(suggestion: &DiagnosticSuggestion, source_text: Option<&str>) -> Self {
        Self {
            message: suggestion.message.clone(),
            edits: suggestion
                .edits
                .iter()
                .map(|edit| DiagnosticReportEdit::from_edit(edit, source_text))
                .collect(),
            applicability: suggestion.applicability.as_str().to_string(),
        }
    }
}

#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
pub struct DiagnosticReportEdit {
    pub span: DiagnosticReportSpan,
    pub replacement: String,
}

impl DiagnosticReportEdit {
    fn from_edit(edit: &TextEdit, source_text: Option<&str>) -> Self {
        Self {
            span: DiagnosticReportSpan::from_span(edit.span, source_text),
            replacement: edit.replacement.clone(),
        }
    }
}

#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
pub struct DiagnosticReportSpan {
    pub start: usize,
    pub end: usize,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub start_line: Option<usize>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub start_column: Option<usize>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub end_line: Option<usize>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub end_column: Option<usize>,
}

impl DiagnosticReportSpan {
    fn from_span(span: Span, source_text: Option<&str>) -> Self {
        let (start_line, start_column, end_line, end_column) = if let Some(src) = source_text {
            let (start_line, start_column, _, _) = line_info(src, span.start.min(src.len()));
            let (end_line, end_column, _, _) = line_info(src, span.end.min(src.len()));
            (
                Some(start_line),
                Some(start_column),
                Some(end_line),
                Some(end_column),
            )
        } else {
            (None, None, None, None)
        };

        Self {
            start: span.start,
            end: span.end,
            start_line,
            start_column,
            end_line,
            end_column,
        }
    }
}

impl DiagnosticSeverity {
    fn as_str(self) -> &'static str {
        match self {
            Self::Error => "error",
        }
    }
}

impl DiagnosticPhase {
    fn as_str(self) -> &'static str {
        match self {
            Self::Parse => "parse",
            Self::Semantic => "semantic",
            Self::Lowering => "lowering",
            Self::Backend => "backend",
        }
    }
}

impl DiagnosticLabelKind {
    fn as_str(self) -> &'static str {
        match self {
            Self::Primary => "primary",
            Self::Secondary => "secondary",
            Self::Context => "context",
        }
    }
}

impl Applicability {
    fn as_str(self) -> &'static str {
        match self {
            Self::Always => "always",
            Self::MaybeIncorrect => "maybe_incorrect",
        }
    }
}

#[derive(Clone, PartialEq, Eq)]
pub struct ParseError {
    diagnostics: Vec<Diagnostic>,
    source: Option<Arc<str>>,
}

impl ParseError {
    pub fn new(message: impl Into<String>, span: Span) -> Self {
        Self::from_diagnostic(Diagnostic::error(
            DSL_PARSE_GENERIC,
            DiagnosticPhase::Parse,
            message,
            span,
        ))
    }

    pub fn from_diagnostic(diagnostic: Diagnostic) -> Self {
        Self {
            diagnostics: vec![diagnostic],
            source: None,
        }
    }

    pub fn from_diagnostics(diagnostics: Vec<Diagnostic>) -> Self {
        debug_assert!(
            !diagnostics.is_empty(),
            "parse errors must contain at least one diagnostic"
        );
        Self {
            diagnostics,
            source: None,
        }
    }

    pub fn with_note(mut self, note: impl Into<String>) -> Self {
        self.diagnostics[0].notes.push(note.into());
        self
    }

    pub fn with_help(mut self, help: impl Into<String>) -> Self {
        self.diagnostics[0].helps.push(help.into());
        self
    }

    pub fn with_secondary_label(mut self, span: Span, message: impl Into<String>) -> Self {
        self.diagnostics[0]
            .labels
            .push(DiagnosticLabel::secondary(span, message));
        self
    }

    pub fn with_context_label(mut self, span: Span, message: impl Into<String>) -> Self {
        self.diagnostics[0]
            .labels
            .push(DiagnosticLabel::context(span, message));
        self
    }

    pub fn with_suggestion(mut self, suggestion: DiagnosticSuggestion) -> Self {
        self.diagnostics[0].suggestions.push(suggestion);
        self
    }

    pub fn diagnostic(&self) -> &Diagnostic {
        &self.diagnostics[0]
    }

    pub fn diagnostics(&self) -> &[Diagnostic] {
        &self.diagnostics
    }

    pub fn into_diagnostic(self) -> Diagnostic {
        self.diagnostics
            .into_iter()
            .next()
            .expect("parse error diagnostic")
    }

    pub fn render(&self, src: &str) -> String {
        render_diagnostics(&self.diagnostics, src)
    }

    pub fn diagnostic_report(&self, source_name: impl Into<String>) -> DiagnosticReport {
        DiagnosticReport::from_diagnostics(source_name, self.source(), &self.diagnostics)
    }

    pub fn with_source(mut self, source: impl Into<Arc<str>>) -> Self {
        self.source = Some(source.into());
        self
    }

    pub fn source(&self) -> Option<&str> {
        self.source.as_deref()
    }

    pub fn shifted(mut self, delta: usize) -> Self {
        for diagnostic in &mut self.diagnostics {
            *diagnostic = diagnostic.clone().shifted(delta);
        }
        self
    }
}

impl fmt::Debug for ParseError {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        fmt::Display::fmt(self, f)
    }
}

impl fmt::Display for ParseError {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        if let Some(source) = self.source() {
            return f.write_str(&self.render(source));
        }
        let span = self.diagnostic().primary_span();
        write!(
            f,
            "{} at bytes {}..{}",
            self.diagnostic().message,
            span.start,
            span.end
        )
    }
}

impl std::error::Error for ParseError {}

fn render_diagnostics(diagnostics: &[Diagnostic], src: &str) -> String {
    diagnostics
        .iter()
        .map(|diagnostic| diagnostic.render(src))
        .collect::<Vec<_>>()
        .join("\n")
}

fn render_label(
    src: &str,
    label: &DiagnosticLabel,
    fallback_message: &str,
    gutter: usize,
) -> String {
    let offset = label.span.start.min(src.len());
    let (line, _, line_start, line_end) = line_info(src, offset);
    let line_text = &src[line_start..line_end];
    let marker_start = src[line_start..offset].chars().count();
    let highlight_end = label.span.end.min(line_end).max(offset);
    let marker_len = src[offset..highlight_end].chars().count().max(1);
    let marker = match label.kind {
        DiagnosticLabelKind::Primary => '^',
        DiagnosticLabelKind::Secondary => '-',
        DiagnosticLabelKind::Context => '~',
    };
    let label_message = label.message.as_deref().unwrap_or(match label.kind {
        DiagnosticLabelKind::Primary => fallback_message,
        DiagnosticLabelKind::Secondary | DiagnosticLabelKind::Context => "",
    });

    let mut rendered = String::new();
    rendered.push_str(&format!(
        "{:>width$} | {}\n",
        line,
        line_text,
        width = gutter
    ));
    rendered.push_str(&format!(
        "{:>width$} | {}{}",
        "",
        " ".repeat(marker_start),
        marker.to_string().repeat(marker_len),
        width = gutter
    ));
    if !label_message.is_empty() {
        rendered.push_str(&format!(" {}", label_message));
    }
    rendered.push('\n');
    rendered
}

fn line_info(src: &str, offset: usize) -> (usize, usize, usize, usize) {
    let mut line = 1;
    let mut line_start = 0;
    for (idx, ch) in src.char_indices() {
        if idx >= offset {
            break;
        }
        if ch == '\n' {
            line += 1;
            line_start = idx + 1;
        }
    }

    let line_end = src[line_start..]
        .find('\n')
        .map(|idx| line_start + idx)
        .unwrap_or(src.len());
    let column = src[line_start..offset].chars().count() + 1;
    (line, column, line_start, line_end)
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn render_includes_code_and_primary_label_message() {
        let src = "dx(gut) = 1 +\n";
        let diagnostic = Diagnostic::error(
            DSL_PARSE_GENERIC,
            DiagnosticPhase::Parse,
            "expected expression after `+`",
            Span::new(12, 13),
        );

        let rendered = diagnostic.render(src);
        assert!(
            rendered.contains("error[DSL1000]: expected expression after `+`"),
            "{}",
            rendered
        );
        assert!(rendered.contains("--> line 1, column 13"), "{}", rendered);
        assert!(
            rendered.contains("^ expected expression after `+`"),
            "{}",
            rendered
        );
    }

    #[test]
    fn render_displays_secondary_and_context_labels() {
        let src = "model broken {\n  outputs {\n    cp = 1 +\n  }\n}\n";
        let diagnostic = Diagnostic::error(
            DSL_PARSE_GENERIC,
            DiagnosticPhase::Parse,
            "expected expression after `+`",
            Span::new(35, 36),
        )
        .with_context_label(Span::new(17, 24), "outputs block starts here")
        .with_secondary_label(Span::new(31, 33), "operator missing a right-hand side")
        .with_help("add a value after `+`");

        let rendered = diagnostic.render(src);
        assert!(
            rendered.contains("~ outputs block starts here"),
            "{}",
            rendered
        );
        assert!(
            rendered.contains("-- operator missing a right-hand side"),
            "{}",
            rendered
        );
        assert!(
            rendered.contains("= help: add a value after `+`"),
            "{}",
            rendered
        );
    }

    #[test]
    fn diagnostic_report_serializes_source_and_offsets() {
        let src = "dx(gut) = 1 +\n";
        let diagnostic = Diagnostic::error(
            DSL_PARSE_GENERIC,
            DiagnosticPhase::Parse,
            "expected expression after `+`",
            Span::new(12, 13),
        )
        .with_help("add a value after `+`");

        let report = DiagnosticReport::from_diagnostics("inline.dsl", Some(src), &[diagnostic]);
        let json = report.to_json().expect("serialize diagnostic report");
        let value: serde_json::Value = serde_json::from_str(&json).expect("parse json");

        assert_eq!(value["source"]["name"], "inline.dsl");
        assert_eq!(value["source"]["byte_len"], src.len());
        assert_eq!(value["diagnostics"][0]["code"], "DSL1000");
        assert_eq!(value["diagnostics"][0]["severity"], "error");
        assert_eq!(value["diagnostics"][0]["phase"], "parse");
        assert_eq!(value["diagnostics"][0]["labels"][0]["span"]["start"], 12);
        assert_eq!(
            value["diagnostics"][0]["labels"][0]["span"]["start_line"],
            1
        );
        assert_eq!(
            value["diagnostics"][0]["labels"][0]["span"]["start_column"],
            13
        );
        assert!(value["rendered"]
            .as_str()
            .expect("rendered output")
            .contains("error[DSL1000]"));
    }
}