This repository has been archived by the owner on Mar 16, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 41
/
loop_keywords_spec.rb
95 lines (71 loc) · 2.66 KB
/
loop_keywords_spec.rb
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
require 'spec_helper'
describe RubyLint::Analysis::LoopKeywords do
context 'next' do
example 'error when using next outside of a loop' do
report = build_report('next', described_class)
entries = report.entries
entries[0].message.should == 'next can only be used inside a loop/block'
entries[0].line.should == 1
entries[0].column.should == 1
end
example 'do not error when using next in a loop' do
code = '[].each { next }'
report = build_report(code, described_class)
report.entries.should be_empty
end
example 'do not error when using next inside a while loop' do
code = 'while true; next; end'
report = build_report(code, described_class)
report.entries.should be_empty
end
example 'do not error when using next inside an until loop' do
code = 'until true; next; end'
report = build_report(code, described_class)
report.entries.should be_empty
end
example 'do not error when using next inside a for loop' do
code = 'for x in y; next; end'
report = build_report(code, described_class)
report.entries.should be_empty
end
example 'do not error when using next inside a loop loop' do
code = 'loop { next }'
report = build_report(code, described_class)
report.entries.should be_empty
end
end
context 'break' do
example 'error when using break outside of a loop' do
report = build_report('break', described_class)
entries = report.entries
entries[0].message.should == 'break can only be used inside a loop/block'
entries[0].line.should == 1
entries[0].column.should == 1
end
example 'do not error when using break in a loop' do
code = '[].each { break }'
report = build_report(code, described_class)
report.entries.should be_empty
end
example 'do not error when using break inside a while loop' do
code = 'while true; break; end'
report = build_report(code, described_class)
report.entries.should be_empty
end
example 'do not error when using break inside an until loop' do
code = 'until true; break; end'
report = build_report(code, described_class)
report.entries.should be_empty
end
example 'do not error when using break inside a for loop' do
code = 'for x in y; break; end'
report = build_report(code, described_class)
report.entries.should be_empty
end
example 'do not error when using break inside a loop loop' do
code = 'loop { break }'
report = build_report(code, described_class)
report.entries.should be_empty
end
end
end