summary refs log tree commit diff stats
path: root/tests/common/errorpanic.rs
blob: 202c4be4c4582e3a5cfe46e5df561ed68f0c06f6 (plain) (blame)
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
// Copyright (c) 2021 Soni L.

use ::iosonism::strcursor::ReadError;
use ::iosonism::strcursor::StringReader;

/// An implementation of various Iosonism errors that just panics.
#[derive(Debug)]
pub enum ErrorPanic {
    // uninhabitable!
}

impl ::std::fmt::Display for ErrorPanic {
    fn fmt(&self, _: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
        match *self {
        }
    }
}

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

impl<'a, C: StringReader<'a>> ReadError<'a, C> for ErrorPanic {
    fn invalid_integer(context: &C, from: &str) -> Self {
        if !context.get_remaining().is_empty() {
            panic!(
                "invalid integer: {} at ...{}",
                from,
                context.get_remaining(),
            );
        } else {
            panic!("invalid integer: {}", from);
        }
    }
    fn expected_integer(context: &C) -> Self {
        if !context.get_remaining().is_empty() {
            panic!("expected integer at ...{}", context.get_remaining());
        } else {
            panic!("expected integer");
        }
    }
    fn invalid_float(context: &C, from: &str) -> Self {
        if !context.get_remaining().is_empty() {
            panic!(
                "invalid float: {} at ...{}",
                from,
                context.get_remaining(),
            );
        } else {
            panic!("invalid float: {}", from);
        }
    }
    fn expected_float(context: &C) -> Self {
        if !context.get_remaining().is_empty() {
            panic!("expected float at ...{}", context.get_remaining());
        } else {
            panic!("expected float");
        }
    }
    fn invalid_bool(context: &C, from: &str) -> Self {
        if !context.get_remaining().is_empty() {
            panic!(
                "invalid bool: {} at ...{}",
                from,
                context.get_remaining(),
            );
        } else {
            panic!("invalid bool: {}", from);
        }
    }
    fn expected_bool(context: &C) -> Self {
        if !context.get_remaining().is_empty() {
            panic!("expected bool at ...{}", context.get_remaining());
        } else {
            panic!("expected bool");
        }
    }
    fn expected_start_of_quote(context: &C) -> Self {
        if !context.get_remaining().is_empty() {
            panic!("expected start of quote at ...{}", context.get_remaining());
        } else {
            panic!("expected start of quote");
        }
    }
    fn expected_end_of_quote(context: &C) -> Self {
        if !context.get_remaining().is_empty() {
            panic!("expected end of quote at ...{}", context.get_remaining());
        } else {
            panic!("expected end of quote");
        }
    }
    fn invalid_escape(context: &C, from: &str) -> Self {
        if !context.get_remaining().is_empty() {
            panic!(
                "invalid escape: {} at ...{}",
                from,
                context.get_remaining(),
            );
        } else {
            panic!("invalid escape: {}", from);
        }
    }
    fn expected_symbol(context: &C, from: &str) -> Self {
        if !context.get_remaining().is_empty() {
            panic!(
                "expected symbol: {} at ...{}",
                from,
                context.get_remaining(),
            );
        } else {
            panic!("expected symbol: {}", from);
        }
    }
}