Skip to content

Commit

Permalink
Update generator (#667)
Browse files Browse the repository at this point in the history
  • Loading branch information
meatball133 authored Aug 7, 2024
1 parent ad054eb commit d9258ed
Show file tree
Hide file tree
Showing 7 changed files with 86 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
steps:
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332
- name: Run generator tests
run: crystal spec test-generator/spec/*
run: crystal spec test-generator
test-generator-templates:
name: Check Generator Templates
runs-on: ubuntu-22.04
Expand Down
58 changes: 58 additions & 0 deletions test-generator/spec/assets/config-files/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
{
"exercises": {
"concept": [
{
"slug": "arys-amazing-lasagna",
"name": "Ary's Amazing Lasagna",
"uuid": "e2d8380e-d815-4458-a760-963e150bb439",
"concepts": [
"basics"
],
"prerequisites": [],
"status": "beta"
},
{
"slug": "crystal-hunter",
"name": "Crystal Hunter",
"uuid": "2e4f0820-655d-461f-a48e-9465eed99c75",
"concepts": [
"bools"
],
"prerequisites": [
"basics"
],
"status": "beta"
}
],
"practice": [
{
"slug": "hello-world",
"name": "Hello World",
"uuid": "4078cf4d-4361-4c55-aa18-63a3fe269be1",
"practices": [],
"prerequisites": [],
"difficulty": 1
},
{
"slug": "acronym",
"name": "Acronym",
"uuid": "5373e713-f2ab-4b1e-b934-92969174bc48",
"practices": [
"string-methods"
],
"prerequisites": [],
"difficulty": 1
},
{
"slug": "anagram",
"name": "Anagram",
"uuid": "2df0796e-951d-4f10-8a2e-5c54f2443f10",
"practices": [
"strings"
],
"prerequisites": [],
"difficulty": 1
}
]
}
}
File renamed without changes.
21 changes: 21 additions & 0 deletions test-generator/spec/generator_help_spec.cr
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
require "spec"
require "json"
require "../src/generator_help"

describe "GeneratorHelp" do
describe "check_config" do
it "should raise an error if the exercise isnt found" do
generator_help = GeneratorHelp.new("say")
costum_config_path = "./test-generator/spec/assets/config-files/config.json"
expect_raises Exception do
generator_help.check_config(costum_config_path)
end
end

it "should not raise an error if the exercise is found" do
generator_help = GeneratorHelp.new("anagram")
costum_config_path = "./test-generator/spec/assets/config-files/config.json"
generator_help.check_config(costum_config_path)
end
end
end
File renamed without changes.
11 changes: 6 additions & 5 deletions test-generator/src/generator_help.cr
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ require "./generator_plugins.cr"

class GeneratorHelp
include GeneratorPlugins

@json : JSON::Any
@first = true

def initialize(@exercise : String)
@first = true
@json = get_remote_files()
end

Expand Down Expand Up @@ -61,10 +62,10 @@ class GeneratorHelp
end
end

def check_config
config_file = File.read("./config.json")
JSON.parse(config_file)["exercises"]["practice"].as_a.each do |x|
return true if @exercise == x["slug"]
def check_config(custom_config : String = "./config.json")
config_file = File.read(custom_config)
JSON.parse(config_file)["exercises"]["practice"].as_a.each do |config_exercise|
return true if @exercise == config_exercise["slug"]
end
raise "Couldn't find the exercise in the config.json.\nMake sure you use the same slug name as in the config file."
end
Expand Down

0 comments on commit d9258ed

Please sign in to comment.