on master help sign in
Add sample Crystal file
commitb30f9a1677a4726b498828dfab1de2dcfc67c995 authorSpencer Williams <spencerwi@gmail.com> dateTue 6 Oct 2020, 22:14 (6 years ago) parente6c3f96
2 files changed+234
tests/syntax-tests/highlighted/Crystal/test.cr+117 tests/syntax-tests/source/Crystal/test.cr+117
tests/syntax-tests/highlighted/Crystal/test.crnew file+117
@@ -0,0 +1,117 @@
1+# An example file to test Crystal syntax highlighting in bat
2+my_var : Nil = nil
3+my_var_also : Int32 = 42
4+my_other_var = 4.0
5+another_float = 4.0_f32
6+another_float_2 = 4e10
7+another_float_3 = -0.5
8+big_one = 1_000_000.111_111e-4
9+ternary = 1 > 2 : 3 ? 4
10+my_symbol = :ThisOne?
11+my_other_symbol = :No_That_One!
12+plus = :+
13+minus = :-
14+my_string : String = "this string right here, with an interpolated value of #{my_var_also}"
15+my_array : Array(Int32) = [1,2,3,4]
16+my_tuple : Tuple(Int32, Int32, Int32, Int32) = {1,2,3,4}
17+my_named_tuple : NamedTuple(one: Int32, two: Int32) = {"one": 1, "two": 2}
18+my_hash : Hash(String, Int32) = {"one" => 1, "two" => 2}
19+my_proc : Proc(Int32, Int32) = ->(x : Int32){ x * x}
20+my_other_proc : Proc(String) = ->{ "Wow, neat!" }
21+puts my_string
22+puts(my_string)
23+
24+enum Colors
25+ Red
26+ Green
27+ Blue
28+end
29+
30+class Greeter
31+ @instance_field = Colors::Red
32+ @@class_field = Colors::Green
33+
34+ def initialize(@name = "world")
35+ end
36+
37+ def greet 
38+ puts "Hello, #{@name}"
39+ end
40+
41+ def render_greeting : String
42+ "Hello, #{@name}"
43+ end
44+
45+ def with_greeting
46+ yield render_greeting
47+ end
48+
49+ def is_color_default?
50+ @instance_field == @@class_field
51+ end
52+
53+ def self.greet_static(name : String) : Unit
54+ puts "Hello, #{name}"
55+ end
56+end
57+
58+greeter = Greeter.new("bat")
59+greeter.with_greeting do |greeting|
60+ puts greeting
61+end
62+
63+puts <<-EOF
64+ this is a heredoc and it has a value in it of #{greeter.render_greeting}!
65+EOF
66+
67+# This is a command:
68+`echo yay!`
69+$?.success?
70+
71+my_color = Colors::Red
72+
73+puts 
74+ case my_color
75+ when Colors::Red, .red?
76+ "Red"
77+ when Colors::Green, .green?
78+ "Green"
79+ when Colors::Blue, .blue?
80+ "Blue"
81+ else
82+ "I dunno, man. Chartreuse? Maroon?"
83+ end
84+
85+class MyGenericClass(T)
86+ def initialize(@wrapped_value : T)
87+ end
88+
89+ def get
90+ return @wrapped_value
91+ end
92+end
93+
94+
95+def do_stuff_with_range(r : Range(Int|String))
96+ return if r.empty?
97+ return unless !(r.empty?)
98+ r.each do |item|
99+ if /e/.match(item.to_s)
100+ puts "#{item} contains the letter e!"
101+ elsif item.to_s.empty?
102+ break
103+ else
104+ next # this is unnecessary, but whatever
105+ end
106+ end
107+end
108+
109+
110+macro print_range(range)
111+ {% for i in range %}
112+ puts {{i.id}}
113+ {% end %}
114+end
115+
116+print_range(1..3)
117+print_range(1...3)
tests/syntax-tests/source/Crystal/test.crnew file+117
@@ -0,0 +1,117 @@
1+# An example file to test Crystal syntax highlighting in bat
2+my_var : Nil = nil
3+my_var_also : Int32 = 42
4+my_other_var = 4.0
5+another_float = 4.0_f32
6+another_float_2 = 4e10
7+another_float_3 = -0.5
8+big_one = 1_000_000.111_111e-4
9+ternary = 1 > 2 : 3 ? 4
10+my_symbol = :ThisOne?
11+my_other_symbol = :No_That_One!
12+plus = :+
13+minus = :-
14+my_string : String = "this string right here, with an interpolated value of #{my_var_also}"
15+my_array : Array(Int32) = [1,2,3,4]
16+my_tuple : Tuple(Int32, Int32, Int32, Int32) = {1,2,3,4}
17+my_named_tuple : NamedTuple(one: Int32, two: Int32) = {"one": 1, "two": 2}
18+my_hash : Hash(String, Int32) = {"one" => 1, "two" => 2}
19+my_proc : Proc(Int32, Int32) = ->(x : Int32){ x * x}
20+my_other_proc : Proc(String) = ->{ "Wow, neat!" }
21+puts my_string
22+puts(my_string)
23+
24+enum Colors
25+ Red
26+ Green
27+ Blue
28+end
29+
30+class Greeter
31+ @instance_field = Colors::Red
32+ @@class_field = Colors::Green
33+
34+ def initialize(@name = "world")
35+ end
36+
37+ def greet
38+ puts "Hello, #{@name}"
39+ end
40+
41+ def render_greeting : String
42+ "Hello, #{@name}"
43+ end
44+
45+ def with_greeting
46+ yield render_greeting
47+ end
48+
49+ def is_color_default?
50+ @instance_field == @@class_field
51+ end
52+
53+ def self.greet_static(name : String) : Unit
54+ puts "Hello, #{name}"
55+ end
56+end
57+
58+greeter = Greeter.new("bat")
59+greeter.with_greeting do |greeting|
60+ puts greeting
61+end
62+
63+puts <<-EOF
64+ this is a heredoc and it has a value in it of #{greeter.render_greeting}!
65+EOF
66+
67+# This is a command:
68+`echo yay!`
69+$?.success?
70+
71+my_color = Colors::Red
72+
73+puts
74+ case my_color
75+ when Colors::Red, .red?
76+ "Red"
77+ when Colors::Green, .green?
78+ "Green"
79+ when Colors::Blue, .blue?
80+ "Blue"
81+ else
82+ "I dunno, man. Chartreuse? Maroon?"
83+ end
84+
85+class MyGenericClass(T)
86+ def initialize(@wrapped_value : T)
87+ end
88+
89+ def get
90+ return @wrapped_value
91+ end
92+end
93+
94+
95+def do_stuff_with_range(r : Range(Int|String))
96+ return if r.empty?
97+ return unless !(r.empty?)
98+ r.each do |item|
99+ if /e/.match(item.to_s)
100+ puts "#{item} contains the letter e!"
101+ elsif item.to_s.empty?
102+ break
103+ else
104+ next # this is unnecessary, but whatever
105+ end
106+ end
107+end
108+
109+
110+macro print_range(range)
111+ {% for i in range %}
112+ puts {{i.id}}
113+ {% end %}
114+end
115+
116+print_range(1..3)
117+print_range(1...3)