tangled
alpha
login
or
join now
gearsco.de
/
pearl
2
fork
atom
An Erlang lexer and syntax highlighter in Gleam
2
fork
atom
overview
issues
pulls
pipelines
Add tests for complex tokens
gearsco.de
7 months ago
1951145e
dc65ae8e
+50
1 changed file
expand all
collapse all
unified
split
test
pearl_test.gleam
+50
test/pearl_test.gleam
···
45
45
assert_roundtrip(tokens_file, False)
46
46
}
47
47
48
48
+
pub fn numbers_test() {
49
49
+
let src =
50
50
+
"2.3E10 5.4e-3 16#ABCDEF 16#abcdef123 8#1234 2#101101 0123 0988 1_2_3_4_5
51
51
+
1_2.3_4e-5_6 14#123_456_aBC"
52
52
+
assert_tokens(src, [
53
53
+
token.Float("2.3E10"),
54
54
+
token.Float("5.4e-3"),
55
55
+
token.Integer("16#ABCDEF"),
56
56
+
token.Integer("16#abcdef123"),
57
57
+
token.Integer("8#1234"),
58
58
+
token.Integer("2#101101"),
59
59
+
token.Integer("0123"),
60
60
+
token.Integer("0988"),
61
61
+
token.Integer("1_2_3_4_5"),
62
62
+
token.Float("1_2.3_4e-5_6"),
63
63
+
token.Integer("14#123_456_aBC"),
64
64
+
])
65
65
+
}
66
66
+
67
67
+
pub fn atom_variable_test() {
68
68
+
let src = "this_is_an_atom This_is_a_variable 'This is an atom'"
69
69
+
assert_tokens(src, [
70
70
+
token.Atom("this_is_an_atom", False),
71
71
+
token.Variable("This_is_a_variable"),
72
72
+
token.Atom("This is an atom", True),
73
73
+
])
74
74
+
}
75
75
+
76
76
+
pub fn sigil_test() {
77
77
+
let src =
78
78
+
"~B/This is a raw sigil\\/ ~<Bracketed, with escapes <\\>>
79
79
+
~s|Sigil which allows \"quotes\"|"
80
80
+
assert_tokens(src, [
81
81
+
token.Sigil("B", token.SigilSlash, "This is a raw sigil\\"),
82
82
+
token.Sigil("", token.SigilAngle, "Bracketed, with escapes <\\>"),
83
83
+
token.Sigil("s", token.SigilPipe, "Sigil which allows \"quotes\""),
84
84
+
])
85
85
+
}
86
86
+
87
87
+
pub fn character_literal_test() {
88
88
+
let src = "$\" $\\^_ $\\xAb $\\x{abcDe1} $\\41"
89
89
+
assert_tokens(src, [
90
90
+
token.Character("\""),
91
91
+
token.Character("\\^_"),
92
92
+
token.Character("\\xAb"),
93
93
+
token.Character("\\x{abcDe1}"),
94
94
+
token.Character("\\41"),
95
95
+
])
96
96
+
}
97
97
+
48
98
pub fn unknown_character_test() {
49
99
let src = "a&b"
50
100
assert_errors(src, [pearl.UnknownCharacter("&")])