Skip to content

Commit 6d9271c

Browse files
authored
Clean up unused options in templates, pass test array directly into template (#733)
1 parent 23adfa6 commit 6d9271c

File tree

11 files changed

+21
-90
lines changed

11 files changed

+21
-90
lines changed

bin/README.md

-7
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,6 @@ If it finds a `canonical-data.json` file for the exercise in question (via `bin/
1515

1616
Example of a yaml file:
1717
```yaml
18-
modules:
19-
- use: Data::Dump
20-
- use: Foo::Bar
21-
22-
# For class methods
23-
methods: 'foo bar'
24-
2518
# This is a string containing Raku code, to be inserted before any properties
2619
tests: |-
2720
my $baz;

exercises/practice/affine-cipher/.meta/template-data.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
methods: encode decode
21
properties:
32
encode:
43
test: |-
@@ -42,6 +41,7 @@ properties:
4241
}
4342
4443
unit: class
44+
4545
example: |-
4646
constant @alphabet = 'a'..'z';
4747
constant $m = @alphabet.elems;

exercises/practice/clock/.meta/template-data.yaml

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
methods: time add subtract
21
properties:
32
create:
43
test: |-
@@ -54,6 +53,7 @@ properties:
5453
}
5554
5655
unit: class
56+
5757
example: |-
5858
has Int:D $.hour = 0;
5959
has Int:D $.minute = 0;
@@ -76,6 +76,7 @@ example: |-
7676
$!hour = ($!hour + $!minute div 60) % 24;
7777
$!minute %= 60;
7878
}
79+
7980
stub: |-
8081
has $.hour;
8182
has $.minute;

exercises/practice/grade-school/.meta/template-data.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
methods: add roster
21
tests: |
32
my GradeSchool $grade-school;
3+
44
properties:
55
add:
66
test: |-

exercises/practice/linked-list/.meta/template-data.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
methods: push pop shift unshift count delete
21
properties:
32
list:
43
test: |-
@@ -27,6 +26,7 @@ properties:
2726
}).join("\n") ~ "\n};\n";
2827
2928
unit: class
29+
3030
example: |-
3131
class Node {
3232
has Node ( $.head, $.tail ) is rw;

exercises/practice/queen-attack/.meta/template-data.yaml

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
package: Queen
2-
methods: can-attack
2+
33
tests: |
44
my Queen %queen;
5+
56
properties:
67
create:
78
test: |-

exercises/practice/robot-name/.meta/template-data.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package: Robot
2-
methods: name reset-name
3-
tests: |-
2+
3+
tests: |
44
srand 1; # begin: 1
55
my Robot:D $robot := Robot.new;
66
my Str:D @robot-names = $robot.name;

lib/Exercism/Generator.rakumod

+3-5
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,10 @@ submethod build-property-tests {
7878
@output[0].=trim-trailing;
7979
@output[0] ~= " # begin: %case<uuid>\n";
8080
}
81-
@tests.push(@output.join.trim-trailing ~ ' # ' ~ (@output > 1 ?? 'end' !! 'case') ~ ": %case<uuid>\n");
81+
@tests.push(@output.join.trim-trailing ~ ' # ' ~ (@output > 1 ?? 'end' !! 'case') ~ ": %case<uuid>");
8282
}
8383
else {
84-
@tests.push("flunk; # case: %case<uuid>\n")
84+
@tests.push("flunk; # case: %case<uuid>")
8585
}
8686
}
8787
return @tests;
@@ -112,12 +112,10 @@ method examples ( --> Hash() ) {
112112

113113
method !render ( Str $module_file? --> Str:D ) {
114114
my %data = %.data;
115-
%data<cases> //= $.json-tests;
116115
%data<package> //= $.package;
117116
%data<unit> //= 'module';
118117
if %data<properties> {
119-
%data<tests> ~= ("\n" if %data<tests>) ~ self.property-tests.join("\n").trim;
120-
%data<cases> = Nil;
118+
%data<property_tests> = self.property-tests;
121119
}
122120

123121
Template::Mustache.render(

t/generator/methods.rakutest

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ subtest '1 case UUID' => {
3737
:uuid<af9ffe10-dc13-42d8-a742-e7bdafac449d>,
3838
).item], 'Case taken from UUID';
3939

40-
is-deeply .property-tests.Array, ["Hello, World! # case: af9ffe10-dc13-42d8-a742-e7bdafac449d\n"];
40+
is-deeply .property-tests.Array, ['Hello, World! # case: af9ffe10-dc13-42d8-a742-e7bdafac449d'];
4141

4242
is .json-tests, q:to/JSON/.trim, 'Cases converted to JSON array';
4343
[

t/generator/renders.rakutest

+1-55
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ use lib ( my $base-dir = $?FILE.IO.resolve.parent(3) ).add('lib');
33
use Exercism::Generator;
44

55
subtest 'Rendered test files' => {
6-
plan 5;
7-
86
given new-generator() {
97
is .test, q:to/TEST/, 'No data';
108
#!/usr/bin/env raku
@@ -16,17 +14,7 @@ subtest 'Rendered test files' => {
1614
TEST
1715
}
1816

19-
given new-generator( :data(:plan(1)) ) {
20-
is .test, q:to/TEST/, 'A plan';
21-
#!/usr/bin/env raku
22-
use Test;
23-
use lib $?FILE.IO.parent(2).add('lib');
24-
use TestExercise;
25-
plan 1;
26-
TEST
27-
}
28-
29-
given new-generator( :data(:tests('ok True;')) ) {
17+
given new-generator( :data(:tests("ok True;\n")) ) {
3018
is .test, q:to/TEST/, 'A test';
3119
#!/usr/bin/env raku
3220
use Test;
@@ -38,48 +26,6 @@ subtest 'Rendered test files' => {
3826
done-testing;
3927
TEST
4028
}
41-
42-
given new-generator( :json-tests<[]> ) {
43-
is .test, q:to/TEST/, 'JSON tests';
44-
#!/usr/bin/env raku
45-
use Test;
46-
use JSON::Fast;
47-
use lib $?FILE.IO.parent(2).add('lib');
48-
use TestExercise;
49-
50-
my @test-cases = from-json($=pod[*-1].contents).List;
51-
52-
done-testing;
53-
54-
=head2 Test Cases
55-
=begin code
56-
[]
57-
=end code
58-
TEST
59-
}
60-
61-
given new-generator(
62-
:data(:tests('ok $_ for @test-cases;')),
63-
:json-tests<[true]>,
64-
) {
65-
is .test, q:to/TEST/, 'Tests with JSON';
66-
#!/usr/bin/env raku
67-
use Test;
68-
use JSON::Fast;
69-
use lib $?FILE.IO.parent(2).add('lib');
70-
use TestExercise;
71-
72-
my @test-cases = from-json($=pod[*-1].contents).List;
73-
ok $_ for @test-cases;
74-
75-
done-testing;
76-
77-
=head2 Test Cases
78-
=begin code
79-
[true]
80-
=end code
81-
TEST
82-
}
8329
}
8430

8531
done-testing;

templates/test.mustache

+7-15
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,11 @@
11
#!/usr/bin/env raku{{=#`{{ }}=}}#`{{! Mustache tags double up as Raku embedded comments}}
2-
use Test;#`{{#cases}}
3-
use JSON::Fast;#`{{/cases}}#`{{#modules}}
4-
use #`{{&use}};#`{{/modules}}
2+
use Test;
53
use lib $?FILE.IO.parent(2).add('lib');#`{{#lib_comment}} #`[#`{{&lib_comment}}]#`{{/lib_comment}}
6-
use #`{{&package}};#`{{#plan}}
7-
plan #`{{&plan}};#`{{#plan_comment}} #`[#`{{&plan_comment}}]#`{{/plan_comment}}#`{{/plan}}#`{{#cases}}
4+
use #`{{&package}};
5+
#`{{#tests}}
86

9-
my @test-cases = from-json($=pod[*-1].contents).List;#`{{/cases}}#`{{#tests}}#`{{^cases}}
10-
#`{{/cases}}
7+
#`{{&tests}}#`{{/tests}}#`{{#property_tests}}
8+
#`{{&.}}
9+
#`{{/property_tests}}
1110

12-
#`{{&tests}}#`{{/tests}}#`{{^plan}}
13-
14-
done-testing;#`{{/plan}}#`{{#cases}}
15-
16-
=head2 Test Cases
17-
=begin code
18-
#`{{&cases}}
19-
=end code#`{{/cases}}
11+
done-testing;

0 commit comments

Comments
 (0)