File: ErrorInfo.vb

package info (click to toggle)
mono-basic 3.8-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 26,600 kB
  • ctags: 6,969
  • sloc: cs: 34,086; xml: 26,150; makefile: 475; sh: 341
file content (108 lines) | stat: -rw-r--r-- 3,566 bytes parent folder | download | duplicates (2)
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


Public Class ErrorInfo
    Private m_Line As Integer
    Private m_Number As Integer
    Private m_Message As String

    Sub New()

    End Sub

    Sub New(ByVal Line As Integer, ByVal Number As Integer, ByVal Message As String)
        m_Line = Line
        m_Number = Number
        m_Message = Message
    End Sub

    Public Property Line As Integer
        Get
            Return m_Line
        End Get
        Set(ByVal value As Integer)
            m_Line = value
        End Set
    End Property

    Public Property Number As Integer
        Get
            Return m_Number
        End Get
        Set(ByVal value As Integer)
            m_Number = value
        End Set
    End Property

    Public Property Message As String
        Get
            Return m_Message
        End Get
        Set(ByVal value As String)
            m_Message = value
        End Set
    End Property

    Shared Function Compare(ByVal expected As ErrorInfo, ByVal actual As ErrorInfo, ByRef result As String) As Boolean
        Dim res As Boolean = True

        result = String.Empty

        If String.IsNullOrEmpty(expected.Message) = False AndAlso String.IsNullOrEmpty(actual.Message) = False AndAlso Not String.Equals(expected.Message, actual.Message) Then
            result += String.Format("Messages differ: Expected: '{0}' vs Actual: '{1}'{2}", expected.Message, actual.Message, Environment.NewLine)
            res = False
        End If

        If expected.Line <> 0 AndAlso actual.Line <> 0 AndAlso expected.Line <> actual.Line Then
            result += String.Format("Line number differ: Expected: '{0}' vs Actual: '{1}'{2}", expected.Line, actual.Line, Environment.NewLine)
            res = False
        End If

        If expected.Number <> actual.Number Then
            result += String.Format("Error number differ: Expected: '{0}' vs Actual: '{1}'{2}", expected.Number, actual.Number, Environment.NewLine)
            res = False
        End If

        Return res
    End Function

    Shared Function ParseLine(ByVal line As String) As ErrorInfo
        Dim idx As Integer
        Dim errline As Integer
        Dim errnumber As Integer
        Dim errmessage As String
        Dim foundSize As Integer = 9

        idx = line.IndexOf(" : error ")
        If idx = -1 Then
            idx = line.IndexOf(" : Command line error ")
            foundSize = 22
        End If
        If idx = -1 Then
            idx = line.IndexOf(" : warning ")
            foundSize = 11
        End If
        If idx = -1 Then Return Nothing

        If idx > 2 AndAlso line(idx - 1) = ")"c Then
            Dim pari As Integer = line.LastIndexOf("("c, idx)
            Dim strline As String = line.Substring(pari + 1, idx - pari - 2)
            If strline.IndexOf(","c) >= 0 Then
                strline = strline.Substring(0, strline.IndexOf(","c))
            End If
            errline = Integer.Parse(strline)
        End If

        line = line.Substring(idx + foundSize)
        If line.StartsWith("BC") Then
            line = line.Substring(2)
        Else
            line = line.Substring(4) 'VBNC
        End If

        idx = line.IndexOf(":"c)
        errnumber = Integer.Parse(line.Substring(0, idx), Globalization.NumberStyles.AllowTrailingWhite Or Globalization.NumberStyles.AllowLeadingWhite)
        errmessage = line.Substring(idx + 1).Trim()

        Return New ErrorInfo(errline, errnumber, errmessage)
    End Function
End Class