Skip to content

Commit 253fc23

Browse files
Reduce nesting of language tests (#83)
1 parent d3c78f6 commit 253fc23

28 files changed

+1904
-2022
lines changed

test/languages/abap_test.rb

+39-43
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,49 @@
11
require "test_helper"
22

3-
module SnippetExtractor
4-
module Languages
5-
class AbapTest < Minitest::Test
6-
def test_simple_example
7-
code = <<~CODE
8-
method run.
9-
* delete me
10-
write 'Hello World!'.
11-
"another comment
12-
endmethod.
13-
CODE
3+
class SnippetExtractor::Languages::AbapTest < Minitest::Test
4+
def test_simple_example
5+
code = <<~CODE
6+
method run.
7+
* delete me
8+
write 'Hello World!'.
9+
"another comment
10+
endmethod.
11+
CODE
1412

15-
expected = <<~CODE
16-
method run.
17-
write 'Hello World!'.
18-
endmethod.
19-
CODE
13+
expected = <<~CODE
14+
method run.
15+
write 'Hello World!'.
16+
endmethod.
17+
CODE
2018

21-
assert_equal expected, ExtractSnippet.(code, :abap)
22-
end
19+
assert_equal expected, SnippetExtractor::ExtractSnippet.(code, :abap)
20+
end
2321

24-
def test_strip_definition
25-
code = <<~CODE
26-
class foo definition.
27-
public section.
28-
methods run.
29-
private section.
30-
data stuff type standard table of string.
31-
endclass.
22+
def test_strip_definition
23+
code = <<~CODE
24+
class foo definition.
25+
public section.
26+
methods run.
27+
private section.
28+
data stuff type standard table of string.
29+
endclass.
3230
33-
class foo implementation.
34-
method run.
35-
* comment1
36-
write 'Hello world!'.
37-
"comment2
38-
endmethod.
39-
endclass.
40-
CODE
31+
class foo implementation.
32+
method run.
33+
* comment1
34+
write 'Hello world!'.
35+
"comment2
36+
endmethod.
37+
endclass.
38+
CODE
4139

42-
expected = <<~CODE
43-
method run.
44-
write 'Hello world!'.
45-
endmethod.
46-
endclass.
47-
CODE
40+
expected = <<~CODE
41+
method run.
42+
write 'Hello world!'.
43+
endmethod.
44+
endclass.
45+
CODE
4846

49-
assert_equal expected, ExtractSnippet.(code, :abap)
50-
end
51-
end
47+
assert_equal expected, SnippetExtractor::ExtractSnippet.(code, :abap)
5248
end
5349
end

test/languages/awk_test.rb

+39-46
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,49 @@
11
require "test_helper"
22

3-
module SnippetExtractor
4-
module Languages
5-
class AwkTest < Minitest::Test
6-
def test_full_example
7-
# rubocop:disable Layout/TrailingWhitespace
8-
code = <<~CODE
9-
#!/usr/bin/env gawk -f
3+
class SnippetExtractor::Languages::AwkTest < Minitest::Test
4+
def test_full_example
5+
code = <<~CODE
6+
#!/usr/bin/env gawk -f
107
11-
BEGIN {
12-
# As discussed at:
13-
# https://www.gnu.org/software/gawk/manual/html_node/gawk-split-records.html
14-
# for the context of the `RS` variable, `^` and `$` match at the
15-
# beginning and end of the __file__! So the record separator "^$" can
16-
# only match for empty files. Therefore, for non-empty files, no record
17-
# separator is found and the whole file is a single record.
18-
RS = "^$"
19-
}
8+
BEGIN {
9+
# As discussed at:
10+
# https://www.gnu.org/software/gawk/manual/html_node/gawk-split-records.html
11+
# for the context of the `RS` variable, `^` and `$` match at the
12+
# beginning and end of the __file__! So the record separator "^$" can
13+
# only match for empty files. Therefore, for non-empty files, no record
14+
# separator is found and the whole file is a single record.
15+
RS = "^$"
16+
}
2017
21-
END {
22-
gsub(/[[:space:]]/, "")
23-
if ($0 == "")
24-
print "Fine. Be that way!"
25-
else {
26-
yelling = /[A-Z]/ && !/[a-z]/
27-
asking = /\?$/
28-
switch (yelling "" asking) {
29-
case "11": print "Calm down, I know what I'm doing!"; break
30-
case "10": print "Whoa, chill out!"; break
31-
case "01": print "Sure."; break
32-
case "00": print "Whatever."; break
33-
}
18+
END {
19+
gsub(/[[:space:]]/, "")
20+
if ($0 == "")
21+
print "Fine. Be that way!"
22+
else {
23+
yelling = /[A-Z]/ && !/[a-z]/
24+
asking = /\?$/
25+
switch (yelling "" asking) {
26+
case "11": print "Calm down, I know what I'm doing!"; break
27+
case "10": print "Whoa, chill out!"; break
28+
case "01": print "Sure."; break
29+
case "00": print "Whatever."; break
3430
}
3531
}
36-
CODE
37-
38-
expected = <<~CODE
39-
BEGIN {
40-
RS = "^$"
41-
}
32+
}
33+
CODE
4234

43-
END {
44-
gsub(/[[:space:]]/, "")
45-
if ($0 == "")
46-
print "Fine. Be that way!"
47-
else {
48-
yelling = /[A-Z]/ && !/[a-z]/
49-
CODE
50-
# rubocop:enable Layout/TrailingWhitespace
35+
expected = <<~CODE
36+
BEGIN {
37+
RS = "^$"
38+
}
5139
52-
assert_equal expected, ExtractSnippet.(code, :awk)
53-
end
54-
end
40+
END {
41+
gsub(/[[:space:]]/, "")
42+
if ($0 == "")
43+
print "Fine. Be that way!"
44+
else {
45+
yelling = /[A-Z]/ && !/[a-z]/
46+
CODE
47+
assert_equal expected, SnippetExtractor::ExtractSnippet.(code, :awk)
5548
end
5649
end

test/languages/ballerina_test.rb

+52-56
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,56 @@
11
require "test_helper"
22

3-
module SnippetExtractor
4-
module Languages
5-
class BallerinaTest < Minitest::Test
6-
def test_full_example
7-
code = <<~CODE
8-
import ballerina/io
9-
10-
// Package gigasecond constains functionality to add a gigasecond
11-
// to a period of time
12-
13-
# Add one billion seconds to a time
14-
#
15-
# + timestamp - a string representing the starting time
16-
# + return - a string representing the end time
17-
function addGigasecond(string timestamp) returns string {
18-
Utc epoch = check time:utcFromString(timestamp);
19-
return epoch.utcAddSeconds(1000000000).utcToString();
20-
}
21-
CODE
22-
23-
expected = <<~CODE
24-
function addGigasecond(string timestamp) returns string {
25-
Utc epoch = check time:utcFromString(timestamp);
26-
return epoch.utcAddSeconds(1000000000).utcToString();
27-
}
28-
CODE
29-
30-
assert_equal expected, ExtractSnippet.(code, :ballerina)
31-
end
32-
33-
def test_stop_at_first_loc
34-
code = <<~CODE
35-
import ballerina/io
36-
37-
// Package gigasecond constains functionality to add a gigasecond
38-
// to a period of time
39-
40-
# a Doc Comment
41-
function addGigasecond(string timestamp) returns string {
42-
// expects input in RFC 3339 format (e.g., 2007-12-03T10:15:30.00Z)
43-
Utc epoch = check time:utcFromString(timestamp);
44-
return epoch.utcAddSeconds(1000000000).utcToString();
45-
}
46-
CODE
47-
48-
expected = <<~CODE
49-
function addGigasecond(string timestamp) returns string {
50-
// expects input in RFC 3339 format (e.g., 2007-12-03T10:15:30.00Z)
51-
Utc epoch = check time:utcFromString(timestamp);
52-
return epoch.utcAddSeconds(1000000000).utcToString();
53-
}
54-
CODE
55-
56-
assert_equal expected, ExtractSnippet.(code, :ballerina)
57-
end
58-
end
3+
class SnippetExtractor::Languages::BallerinaTest < Minitest::Test
4+
def test_full_example
5+
code = <<~CODE
6+
import ballerina/io
7+
8+
// Package gigasecond constains functionality to add a gigasecond
9+
// to a period of time
10+
11+
# Add one billion seconds to a time
12+
#
13+
# + timestamp - a string representing the starting time
14+
# + return - a string representing the end time
15+
function addGigasecond(string timestamp) returns string {
16+
Utc epoch = check time:utcFromString(timestamp);
17+
return epoch.utcAddSeconds(1000000000).utcToString();
18+
}
19+
CODE
20+
21+
expected = <<~CODE
22+
function addGigasecond(string timestamp) returns string {
23+
Utc epoch = check time:utcFromString(timestamp);
24+
return epoch.utcAddSeconds(1000000000).utcToString();
25+
}
26+
CODE
27+
28+
assert_equal expected, SnippetExtractor::ExtractSnippet.(code, :ballerina)
29+
end
30+
31+
def test_stop_at_first_loc
32+
code = <<~CODE
33+
import ballerina/io
34+
35+
// Package gigasecond constains functionality to add a gigasecond
36+
// to a period of time
37+
38+
# a Doc Comment
39+
function addGigasecond(string timestamp) returns string {
40+
// expects input in RFC 3339 format (e.g., 2007-12-03T10:15:30.00Z)
41+
Utc epoch = check time:utcFromString(timestamp);
42+
return epoch.utcAddSeconds(1000000000).utcToString();
43+
}
44+
CODE
45+
46+
expected = <<~CODE
47+
function addGigasecond(string timestamp) returns string {
48+
// expects input in RFC 3339 format (e.g., 2007-12-03T10:15:30.00Z)
49+
Utc epoch = check time:utcFromString(timestamp);
50+
return epoch.utcAddSeconds(1000000000).utcToString();
51+
}
52+
CODE
53+
54+
assert_equal expected, SnippetExtractor::ExtractSnippet.(code, :ballerina)
5955
end
6056
end

0 commit comments

Comments
 (0)