-
Notifications
You must be signed in to change notification settings - Fork 1
/
encosures_test.go
147 lines (139 loc) · 7.04 KB
/
encosures_test.go
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
package splitter
import (
"fmt"
"github.com/stretchr/testify/require"
"strings"
"testing"
)
var testEnclosures = map[string]*Enclosure{
"DoubleQuotes": DoubleQuotes,
"DoubleQuotesBackSlashEscaped": DoubleQuotesBackSlashEscaped,
"DoubleQuotesDoubleEscaped": DoubleQuotesDoubleEscaped,
"SingleQuotes": SingleQuotes,
"SingleQuotesBackSlashEscaped": SingleQuotesBackSlashEscaped,
"SingleQuotesDoubleEscaped": SingleQuotesDoubleEscaped,
"SingleInvertedQuotes": SingleInvertedQuotes,
"SingleInvertedQuotesBackSlashEscaped": SingleInvertedQuotesBackSlashEscaped,
"SingleInvertedQuotesDoubleEscaped": SingleInvertedQuotesDoubleEscaped,
"DoublePointingAngleQuotes": DoublePointingAngleQuotes,
"SinglePointingAngleQuotes": SinglePointingAngleQuotes,
"SinglePointingAngleQuotesBackSlashEscaped": SinglePointingAngleQuotesBackSlashEscaped,
"LeftRightDoubleDoubleQuotes": LeftRightDoubleDoubleQuotes,
"LeftRightDoubleSingleQuotes": LeftRightDoubleSingleQuotes,
"LeftRightDoublePrimeQuotes": LeftRightDoublePrimeQuotes,
"SingleLowHigh9Quotes": SingleLowHigh9Quotes,
"DoubleLowHigh9Quotes": DoubleLowHigh9Quotes,
"Parenthesis": Parenthesis,
"CurlyBrackets": CurlyBrackets,
"SquareBrackets": SquareBrackets,
"LtGtAngleBrackets": LtGtAngleBrackets,
"LeftRightPointingAngleBrackets": LeftRightPointingAngleBrackets,
"SubscriptParenthesis": SubscriptParenthesis,
"SuperscriptParenthesis": SuperscriptParenthesis,
"SmallParenthesis": SmallParenthesis,
"SmallCurlyBrackets": SmallCurlyBrackets,
"DoubleParenthesis": DoubleParenthesis,
"MathWhiteSquareBrackets": MathWhiteSquareBrackets,
"MathAngleBrackets": MathAngleBrackets,
"MathDoubleAngleBrackets": MathDoubleAngleBrackets,
"MathWhiteTortoiseShellBrackets": MathWhiteTortoiseShellBrackets,
"MathFlattenedParenthesis": MathFlattenedParenthesis,
"OrnateParenthesis": OrnateParenthesis,
"AngleBrackets": AngleBrackets,
"DoubleAngleBrackets": DoubleAngleBrackets,
"FullWidthParenthesis": FullWidthParenthesis,
"FullWidthSquareBrackets": FullWidthSquareBrackets,
"FullWidthCurlyBrackets": FullWidthCurlyBrackets,
"SubstitutionBrackets": SubstitutionBrackets,
"SubstitutionQuotes": SubstitutionQuotes,
"DottedSubstitutionBrackets": DottedSubstitutionBrackets,
"DottedSubstitutionQuotes": DottedSubstitutionQuotes,
"TranspositionBrackets": TranspositionBrackets,
"TranspositionQuotes": TranspositionQuotes,
"RaisedOmissionBrackets": RaisedOmissionBrackets,
"RaisedOmissionQuotes": RaisedOmissionQuotes,
"LowParaphraseBrackets": LowParaphraseBrackets,
"LowParaphraseQuotes": LowParaphraseQuotes,
"SquareWithQuillBrackets": SquareWithQuillBrackets,
"WhiteParenthesis": WhiteParenthesis,
"WhiteCurlyBrackets": WhiteCurlyBrackets,
"WhiteSquareBrackets": WhiteSquareBrackets,
"WhiteLenticularBrackets": WhiteLenticularBrackets,
"WhiteTortoiseShellBrackets": WhiteTortoiseShellBrackets,
"FullWidthWhiteParenthesis": FullWidthWhiteParenthesis,
"BlackTortoiseShellBrackets": BlackTortoiseShellBrackets,
"BlackLenticularBrackets": BlackLenticularBrackets,
"PointingCurvedAngleBrackets": PointingCurvedAngleBrackets,
"TortoiseShellBrackets": TortoiseShellBrackets,
"SmallTortoiseShellBrackets": SmallTortoiseShellBrackets,
"ZNotationImageBrackets": ZNotationImageBrackets,
"ZNotationBindingBrackets": ZNotationBindingBrackets,
"MediumOrnamentalParenthesis": MediumOrnamentalParenthesis,
"LightOrnamentalTortoiseShellBrackets": LightOrnamentalTortoiseShellBrackets,
"MediumOrnamentalFlattenedParenthesis": MediumOrnamentalFlattenedParenthesis,
"MediumOrnamentalPointingAngleBrackets": MediumOrnamentalPointingAngleBrackets,
"MediumOrnamentalCurlyBrackets": MediumOrnamentalCurlyBrackets,
"HeavyOrnamentalPointingAngleQuotes": HeavyOrnamentalPointingAngleQuotes,
"HeavyOrnamentalPointingAngleBrackets": HeavyOrnamentalPointingAngleBrackets,
}
func TestEnclosures(t *testing.T) {
for name, enc := range testEnclosures {
t.Run(fmt.Sprintf("%s", name), func(t *testing.T) {
require.NotEqual(t, rune(0), enc.Start)
require.NotEqual(t, rune(0), enc.End)
if strings.Contains(name, "Quote") {
require.True(t, enc.IsQuote)
require.Equal(t, enc.Escape == rune(0), !enc.Escapable)
if enc.Escapable {
require.NotEqual(t, rune(0), enc.Escape)
}
} else {
require.False(t, enc.IsQuote)
require.False(t, enc.Escapable)
require.Equal(t, rune(0), enc.Escape)
}
})
}
}
func TestMakeEscapable(t *testing.T) {
escpd, err := MakeEscapable(DoubleQuotes, '\\')
require.NoError(t, err)
require.Equal(t, DoubleQuotes.Start, escpd.Start)
require.Equal(t, DoubleQuotes.End, escpd.End)
require.Equal(t, '\\', escpd.Escape)
require.NotEqual(t, escpd.Escape, DoubleQuotes.Escape)
require.True(t, escpd.Escapable)
require.True(t, escpd.isEscapable())
require.False(t, escpd.isDoubleEscaping())
escpd, err = MakeEscapable(DoubleQuotes, '"')
require.NoError(t, err)
require.Equal(t, DoubleQuotes.Start, escpd.Start)
require.Equal(t, DoubleQuotes.End, escpd.End)
require.Equal(t, '"', escpd.Escape)
require.True(t, escpd.Escapable)
require.True(t, escpd.isEscapable())
require.True(t, escpd.isDoubleEscaping())
_, err = MakeEscapable(Parenthesis, '\\')
require.NoError(t, err)
_, err = MakeEscapable(Parenthesis, '(')
require.Error(t, err)
require.Equal(t, `bracket enclosures cannot be double-escaped`, err.Error())
_, err = MakeEscapable(Parenthesis, ')')
require.Error(t, err)
require.Equal(t, `bracket enclosures cannot be double-escaped`, err.Error())
}
func TestMustMakeEscapable(t *testing.T) {
escpd := MustMakeEscapable(Parenthesis, '\\')
require.Equal(t, Parenthesis.Start, escpd.Start)
require.Equal(t, Parenthesis.End, escpd.End)
require.Equal(t, '\\', escpd.Escape)
require.True(t, escpd.Escapable)
require.True(t, escpd.isEscapable())
require.False(t, escpd.isDoubleEscaping())
require.Panics(t, func() {
MustMakeEscapable(Parenthesis, '(')
})
require.Panics(t, func() {
MustMakeEscapable(Parenthesis, ')')
})
}