diff --git a/src/sync/sync.nim b/src/sync/sync.nim index 7ef4a442..b1a0748f 100644 --- a/src/sync/sync.nim +++ b/src/sync/sync.nim @@ -47,7 +47,7 @@ type func init*(T: typedesc[TrackExerciseSlugs], exercises: Exercises): T = T( `concept`: getSlugs(exercises.`concept`), - practice: getSlugs(exercises.practice) + practice: getSlugs(exercises.practice, withDeprecated = false) ) proc getSlugs*(exercises: Exercises, conf: Conf, diff --git a/src/sync/sync_common.nim b/src/sync/sync_common.nim index 77ede4f5..ab02a527 100644 --- a/src/sync/sync_common.nim +++ b/src/sync/sync_common.nim @@ -25,11 +25,13 @@ proc postHook*(e: ConceptExercise | PracticeExercise) = stderr.writeLine msg quit 1 -func getSlugs*(e: seq[ConceptExercise] | seq[PracticeExercise]): seq[Slug] = +func getSlugs*(e: seq[ConceptExercise] | seq[PracticeExercise], + withDeprecated = true): seq[Slug] = ## Returns a seq of the slugs in `e`, in alphabetical order. - result = newSeq[Slug](e.len) - for i, item in e: - result[i] = item.slug + result = newSeqOfCap[Slug](e.len) + for item in e: + if withDeprecated or item.status != sDeprecated: + result.add item.slug sort result func truncateAndAdd*(s: var string, truncateLen: int, slug: Slug) = diff --git a/src/sync/tracks.nim b/src/sync/tracks.nim index cd8f49a4..b62a83a2 100644 --- a/src/sync/tracks.nim +++ b/src/sync/tracks.nim @@ -27,7 +27,8 @@ func testsPath*(trackDir: TrackDir, slug: PracticeExerciseSlug): string = joinPath(trackDir.string, "exercises", "practice", slug.string, ".meta", "tests.toml") -proc getPracticeExerciseSlugs(trackDir: TrackDir): seq[PracticeExerciseSlug] = +proc getPracticeExerciseSlugs(trackDir: TrackDir, + withDeprecated: bool): seq[PracticeExerciseSlug] = ## Parses the root `config.json` file in `trackDir` and returns a seq of its ## Practice Exercise slugs, in alphabetical order. let configFile = trackDir / "config.json" @@ -40,8 +41,10 @@ proc getPracticeExerciseSlugs(trackDir: TrackDir): seq[PracticeExerciseSlug] = result = newSeqOfCap[PracticeExerciseSlug](practiceExercises.len) for exercise in practiceExercises: - if exercise.hasKey("slug"): - if exercise["slug"].kind == JString: + if exercise.hasKey("slug") and exercise["slug"].kind == JString: + if withDeprecated or not exercise.hasKey("status") or + exercise["status"].kind != JString or + exercise["status"].getStr() != "deprecated": let slug = exercise["slug"].getStr() result.add PracticeExerciseSlug(slug) else: @@ -101,7 +104,8 @@ iterator findPracticeExercises*(conf: Conf): PracticeExercise {.inline.} = let trackDir = TrackDir(conf.trackDir) let userExercise = PracticeExerciseSlug(conf.action.exercise) - let practiceExerciseSlugs = getPracticeExerciseSlugs(trackDir) + let practiceExerciseSlugs = getPracticeExerciseSlugs(trackDir, + withDeprecated = false) for slug in practiceExerciseSlugs: if userExercise.len == 0 or userExercise == slug: diff --git a/tests/test_binary.nim b/tests/test_binary.nim index a258e655..09b28f32 100644 --- a/tests/test_binary.nim +++ b/tests/test_binary.nim @@ -73,7 +73,6 @@ proc testsForSync(binaryPath: static string) = bodyUnsyncedMetadata = """ [warn] metadata: unsynced: acronym [warn] metadata: unsynced: armstrong-numbers - [warn] metadata: unsynced: binary [warn] metadata: unsynced: collatz-conjecture [warn] metadata: unsynced: darts [warn] metadata: unsynced: grade-school @@ -452,7 +451,7 @@ proc testsForSync(binaryPath: static string) = const expectedOutput = fmt""" {header} {bodyUnsyncedMetadata} - Updated the metadata for 14 Practice Exercises + Updated the metadata for 13 Practice Exercises {footerSyncedMetadata} """.unindent() const expectedDiff = """ @@ -464,10 +463,6 @@ proc testsForSync(binaryPath: static string) = +++ exercises/practice/armstrong-numbers/.meta/config.json - "blurb": "Determine if a number is an Armstrong number", + "blurb": "Determine if a number is an Armstrong number.", - --- exercises/practice/binary/.meta/config.json - +++ exercises/practice/binary/.meta/config.json - - "blurb": "Convert a binary number, represented as a string (e.g. '101010'), to its decimal equivalent using first principles", - + "blurb": "Convert a binary number, represented as a string (e.g. '101010'), to its decimal equivalent using first principles.", --- exercises/practice/collatz-conjecture/.meta/config.json +++ exercises/practice/collatz-conjecture/.meta/config.json - "blurb": "Calculate the number of steps to reach 1 using the Collatz conjecture", diff --git a/tests/test_tracks.nim b/tests/test_tracks.nim index a4d93f4d..c1095f3f 100644 --- a/tests/test_tracks.nim +++ b/tests/test_tracks.nim @@ -19,7 +19,7 @@ proc main = test "returns the expected number of exercises": check: - practiceExercises.len == 68 + practiceExercises.len == 67 test "returns the expected object for `hello-world`": const expectedHelloWorld = @@ -32,7 +32,7 @@ proc main = ) check: - practiceExercises[20] == expectedHelloWorld + practiceExercises[19] == expectedHelloWorld test "returns the expected object for `two-fer`": const expectedTwoFer = @@ -47,7 +47,7 @@ proc main = ) check: - practiceExercises[65] == expectedTwoFer + practiceExercises[64] == expectedTwoFer main() {.used.}