diff --git a/exercises/grep/canonical-data.json b/exercises/grep/canonical-data.json index 62793ece35..8c7839a05f 100644 --- a/exercises/grep/canonical-data.json +++ b/exercises/grep/canonical-data.json @@ -1,276 +1,297 @@ -{ - "#": [ - "JSON doesn't allow for multi-line strings, so all outputs are presented ", - "here as arrays of strings. It's up to the test generator to join the ", - "lines together with line breaks.", - "", - "The tests are divided into two groups: ", - "* Grepping a single file", - "* Grepping multiple files at once", - "", - "The language track implementing this exercise should", - "ensure that when the tests run, three files are created", - "with the following contents. The file names and their", - "contents are listed in the 'files' section below." - ], - "files": [ +{ + "exercise": "grep", + "version": "1.0.0", + "comments": [ + " JSON doesn't allow for multi-line strings, so all ", + " outputs are presented here as arrays of strings. ", + " It's up to the test generator to join the lines ", + " together with line breaks. ", + " ", + " The tests are divided into two groups: ", + " - Grepping a single file ", + " - Grepping multiple files at once ", + " ", + " The language track implementing this exercise ", + " should ensure that when the tests run, three files ", + " are created with the following contents. The file ", + " names and their contents are listed below: ", + " ", + " iliad.txt ", + " --------------------------------------------- ", + " |Achilles sing, O Goddess! Peleus' son; | ", + " |His wrath pernicious, who ten thousand woes| ", + " |Caused to Achaia's host, sent many a soul | ", + " |Illustrious into Ades premature, | ", + " |And Heroes gave (so stood the will of Jove)| ", + " |To dogs and to all ravening fowls a prey, | ", + " |When fierce dispute had separated once | ", + " |The noble Chief Achilles from the son | ", + " |Of Atreus, Agamemnon, King of men. | ", + " --------------------------------------------- ", + " ", + " midsummer-night.txt ", + " ----------------------------------------------- ", + " |I do entreat your grace to pardon me. | ", + " |I know not by what power I am made bold, | ", + " |Nor how it may concern my modesty, | ", + " |In such a presence here to plead my thoughts;| ", + " |But I beseech your grace that I may know | ", + " |The worst that may befall me in this case, | ", + " |If I refuse to wed Demetrius. | ", + " ----------------------------------------------- ", + " ", + " paradise-lost.txt ", + " ------------------------------------------------- ", + " |Of Mans First Disobedience, and the Fruit | ", + " |Of that Forbidden Tree, whose mortal tast | ", + " |Brought Death into the World, and all our woe, | ", + " |With loss of Eden, till one greater Man | ", + " |Restore us, and regain the blissful Seat, | ", + " |Sing Heav'nly Muse, that on the secret top | ", + " |Of Oreb, or of Sinai, didst inspire | ", + " |That Shepherd, who first taught the chosen Seed| ", + " ------------------------------------------------- " + ], + "cases": [ + { + "description": "Test grepping a single file", + "cases": [ { - "name": "iliad.txt", - "contents": [ - "Achilles sing, O Goddess! Peleus' son;", - "His wrath pernicious, who ten thousand woes", - "Caused to Achaia's host, sent many a soul", - "Illustrious into Ades premature,", - "And Heroes gave (so stood the will of Jove)", - "To dogs and to all ravening fowls a prey,", - "When fierce dispute had separated once", - "The noble Chief Achilles from the son", - "Of Atreus, Agamemnon, King of men." - ] - }, + "description": "One file, one match, no flags", + "property": "grep", + "pattern": "Agamemnon", + "flags": [], + "files": ["iliad.txt"], + "expected": [ + "Of Atreus, Agamemnon, King of men." + ] + }, + { + "description": "One file, one match, print line numbers flag", + "property": "grep", + "pattern": "Forbidden", + "flags": ["-n"], + "files": ["paradise-lost.txt"], + "expected": [ + "2:Of that Forbidden Tree, whose mortal tast" + ] + }, + { + "description": "One file, one match, case-insensitive flag", + "property": "grep", + "pattern": "FORBIDDEN", + "flags": ["-i"], + "files": ["paradise-lost.txt"], + "expected": [ + "Of that Forbidden Tree, whose mortal tast" + ] + }, + { + "description": "One file, one match, print file names flag", + "property": "grep", + "pattern": "Forbidden", + "flags": ["-l"], + "files": ["paradise-lost.txt"], + "expected": [ + "paradise-lost.txt" + ] + }, + { + "description": "One file, one match, match entire lines flag", + "property": "grep", + "pattern": "With loss of Eden, till one greater Man", + "flags": ["-x"], + "files": ["paradise-lost.txt"], + "expected": [ + "With loss of Eden, till one greater Man" + ] + }, + { + "description": "One file, one match, multiple flags", + "property": "grep", + "pattern": "OF ATREUS, Agamemnon, KIng of MEN.", + "flags": ["-n", "-i", "-x"], + "files": ["iliad.txt"], + "expected": [ + "9:Of Atreus, Agamemnon, King of men." + ] + }, + { + "description": "One file, several matches, no flags", + "property": "grep", + "pattern": "may", + "flags": [], + "files": ["midsummer-night.txt"], + "expected": [ + "Nor how it may concern my modesty,", + "But I beseech your grace that I may know", + "The worst that may befall me in this case," + ] + }, + { + "description": "One file, several matches, print line numbers flag", + "property": "grep", + "pattern": "may", + "flags": ["-n"], + "files": ["midsummer-night.txt"], + "expected": [ + "3:Nor how it may concern my modesty,", + "5:But I beseech your grace that I may know", + "6:The worst that may befall me in this case," + ] + }, + { + "description": "One file, several matches, match entire lines flag", + "property": "grep", + "pattern": "may", + "flags": ["-x"], + "files": ["midsummer-night.txt"], + "expected": [] + }, + { + "description": "One file, several matches, case-insensitive flag", + "property": "grep", + "pattern": "ACHILLES", + "flags": ["-i"], + "files": ["iliad.txt"], + "expected": [ + "Achilles sing, O Goddess! Peleus' son;", + "The noble Chief Achilles from the son" + ] + }, { - "name": "midsummer-night.txt", - "contents": [ - "I do entreat your grace to pardon me.", - "I know not by what power I am made bold,", - "Nor how it may concern my modesty,", - "In such a presence here to plead my thoughts;", - "But I beseech your grace that I may know", - "The worst that may befall me in this case,", - "If I refuse to wed Demetrius." - ] + "description": "One file, several matches, inverted flag", + "property": "grep", + "pattern": "Of", + "flags": ["-v"], + "files": ["paradise-lost.txt"], + "expected": [ + "Brought Death into the World, and all our woe,", + "With loss of Eden, till one greater Man", + "Restore us, and regain the blissful Seat,", + "Sing Heav'nly Muse, that on the secret top", + "That Shepherd, who first taught the chosen Seed" + ] }, { - "name": "paradise-lost.txt", - "contents": [ - "Of Mans First Disobedience, and the Fruit", - "Of that Forbidden Tree, whose mortal tast", - "Brought Death into the World, and all our woe,", - "With loss of Eden, till one greater Man", - "Restore us, and regain the blissful Seat,", - "Sing Heav'nly Muse, that on the secret top", - "Of Oreb, or of Sinai, didst inspire", - "That Shepherd, who first taught the chosen Seed" - ] + "description": "One file, no matches, various flags", + "property": "grep", + "pattern": "Gandalf", + "flags": ["-n", "-l", "-x", "-i"], + "files": ["iliad.txt"], + "expected": [] } - ], - "single-file": { - "description": ["Test grepping a single file"], - "cases": [ - { - "description": "One file, one match, no flags", - "pattern": "Agamemnon", - "flags": [], - "files": ["iliad.txt"], - "expected": [ - "Of Atreus, Agamemnon, King of men." - ] - }, - { - "description": "One file, one match, print line numbers flag", - "pattern": "Forbidden", - "flags": ["-n"], - "files": ["paradise-lost.txt"], - "expected": [ - "2:Of that Forbidden Tree, whose mortal tast" - ] - }, - { - "description": "One file, one match, case-insensitive flag", - "pattern": "FORBIDDEN", - "flags": ["-i"], - "files": ["paradise-lost.txt"], - "expected": [ - "Of that Forbidden Tree, whose mortal tast" - ] - }, - { - "description": "One file, one match, print file names flag", - "pattern": "Forbidden", - "flags": ["-l"], - "files": ["paradise-lost.txt"], - "expected": [ - "paradise-lost.txt" - ] - }, - { - "description": "One file, one match, match entire lines flag", - "pattern": "With loss of Eden, till one greater Man", - "flags": ["-x"], - "files": ["paradise-lost.txt"], - "expected": [ - "With loss of Eden, till one greater Man" - ] - }, - { - "description": "One file, one match, multiple flags", - "pattern": "OF ATREUS, Agamemnon, KIng of MEN.", - "flags": ["-n", "-i", "-x"], - "files": ["iliad.txt"], - "expected": [ - "9:Of Atreus, Agamemnon, King of men." - ] - }, - { - "description": "One file, several matches, no flags", - "pattern": "may", - "flags": [], - "files": ["midsummer-night.txt"], - "expected": [ - "Nor how it may concern my modesty,", - "But I beseech your grace that I may know", - "The worst that may befall me in this case," - ] - }, - { - "description": "One file, several matches, print line numbers flag", - "pattern": "may", - "flags": ["-n"], - "files": ["midsummer-night.txt"], - "expected": [ - "3:Nor how it may concern my modesty,", - "5:But I beseech your grace that I may know", - "6:The worst that may befall me in this case," - ] - }, - { - "description": "One file, several matches, match entire lines flag", - "pattern": "may", - "flags": ["-x"], - "files": ["midsummer-night.txt"], - "expected": [] - }, - { - "description": "One file, several matches, case-insensitive flag", - "pattern": "ACHILLES", - "flags": ["-i"], - "files": ["iliad.txt"], - "expected": [ - "Achilles sing, O Goddess! Peleus' son;", - "The noble Chief Achilles from the son" - ] - }, - { - "description": "One file, several matches, inverted flag", - "pattern": "Of", - "flags": ["-v"], - "files": ["paradise-lost.txt"], - "expected": [ - "Brought Death into the World, and all our woe,", - "With loss of Eden, till one greater Man", - "Restore us, and regain the blissful Seat,", - "Sing Heav'nly Muse, that on the secret top", - "That Shepherd, who first taught the chosen Seed" - ] - }, - { - "description": "One file, no matches, various flags", - "pattern": "Gandalf", - "flags": ["-n", "-l", "-x", "-i"], - "files": ["iliad.txt"], - "expected": [] - } - ] + ] }, - "multiple-files": { - "description": ["Test grepping multiples files at once"], - "cases": [ - { - "description": "Multiple files, one match, no flags", - "pattern": "Agamemnon", - "flags": [], - "files": ["iliad.txt", "midsummer-night.txt", "paradise-lost.txt"], - "expected": [ - "iliad.txt:Of Atreus, Agamemnon, King of men." - ] - }, - { - "description": "Multiple files, several matches, no flags", - "pattern": "may", - "flags": [], - "files": ["iliad.txt", "midsummer-night.txt", "paradise-lost.txt"], - "expected": [ - "midsummer-night.txt:Nor how it may concern my modesty,", - "midsummer-night.txt:But I beseech your grace that I may know", - "midsummer-night.txt:The worst that may befall me in this case," - ] - }, - { - "description": "Multiple files, several matches, print line numbers flag", - "pattern": "that", - "flags": ["-n"], - "files": ["iliad.txt", "midsummer-night.txt", "paradise-lost.txt"], - "expected": [ - "midsummer-night.txt:5:But I beseech your grace that I may know", - "midsummer-night.txt:6:The worst that may befall me in this case,", - "paradise-lost.txt:2:Of that Forbidden Tree, whose mortal tast", - "paradise-lost.txt:6:Sing Heav'nly Muse, that on the secret top" - ] - }, - { - "description": "Multiple files, one match, print file names flag", - "pattern": "who", - "flags": ["-l"], - "files": ["iliad.txt", "midsummer-night.txt", "paradise-lost.txt"], - "expected": [ - "iliad.txt", - "paradise-lost.txt" - ] - }, - { - "description": "Multiple files, several matches, case-insensitive flag", - "pattern": "TO", - "flags": ["-i"], - "files": ["iliad.txt", "midsummer-night.txt", "paradise-lost.txt"], - "expected": [ - "iliad.txt:Caused to Achaia's host, sent many a soul", - "iliad.txt:Illustrious into Ades premature,", - "iliad.txt:And Heroes gave (so stood the will of Jove)", - "iliad.txt:To dogs and to all ravening fowls a prey,", - "midsummer-night.txt:I do entreat your grace to pardon me.", - "midsummer-night.txt:In such a presence here to plead my thoughts;", - "midsummer-night.txt:If I refuse to wed Demetrius.", - "paradise-lost.txt:Brought Death into the World, and all our woe,", - "paradise-lost.txt:Restore us, and regain the blissful Seat,", - "paradise-lost.txt:Sing Heav'nly Muse, that on the secret top" - ] - }, - { - "description": "Multiple files, several matches, inverted flag", - "pattern": "a", - "flags": ["-v"], - "files": ["iliad.txt", "midsummer-night.txt", "paradise-lost.txt"], - "expected": [ - "iliad.txt:Achilles sing, O Goddess! Peleus' son;", - "iliad.txt:The noble Chief Achilles from the son", - "midsummer-night.txt:If I refuse to wed Demetrius." - ] - }, - { - "description": "Multiple files, one match, match entire lines flag", - "pattern": "But I beseech your grace that I may know", - "flags": ["-x"], - "files": ["iliad.txt", "midsummer-night.txt", "paradise-lost.txt"], - "expected": [ - "midsummer-night.txt:But I beseech your grace that I may know" - ] - }, - { - "description": "Multiple files, one match, multiple flags", - "pattern": "WITH LOSS OF EDEN, TILL ONE GREATER MAN", - "flags": ["-n", "-i", "-x"], - "files": ["iliad.txt", "midsummer-night.txt", "paradise-lost.txt"], - "expected": [ - "paradise-lost.txt:4:With loss of Eden, till one greater Man" - ] - }, - { - "description": "Multiple files, no matches, various flags", - "pattern": "Frodo", - "flags": ["-n", "-l", "-x", "-i"], - "files": ["iliad.txt", "midsummer-night.txt", "paradise-lost.txt"], - "expected": [] - } - ] + { + "description": "Test grepping multiples files at once", + "cases": [ + { + "description": "Multiple files, one match, no flags", + "property": "grep", + "pattern": "Agamemnon", + "flags": [], + "files": ["iliad.txt", "midsummer-night.txt", "paradise-lost.txt"], + "expected": [ + "iliad.txt:Of Atreus, Agamemnon, King of men." + ] + }, + { + "description": "Multiple files, several matches, no flags", + "property": "grep", + "pattern": "may", + "flags": [], + "files": ["iliad.txt", "midsummer-night.txt", "paradise-lost.txt"], + "expected": [ + "midsummer-night.txt:Nor how it may concern my modesty,", + "midsummer-night.txt:But I beseech your grace that I may know", + "midsummer-night.txt:The worst that may befall me in this case," + ] + }, + { + "description": "Multiple files, several matches, print line numbers flag", + "property": "grep", + "pattern": "that", + "flags": ["-n"], + "files": ["iliad.txt", "midsummer-night.txt", "paradise-lost.txt"], + "expected": [ + "midsummer-night.txt:5:But I beseech your grace that I may know", + "midsummer-night.txt:6:The worst that may befall me in this case,", + "paradise-lost.txt:2:Of that Forbidden Tree, whose mortal tast", + "paradise-lost.txt:6:Sing Heav'nly Muse, that on the secret top" + ] + }, + { + "description": "Multiple files, one match, print file names flag", + "property": "grep", + "pattern": "who", + "flags": ["-l"], + "files": ["iliad.txt", "midsummer-night.txt", "paradise-lost.txt"], + "expected": [ + "iliad.txt", + "paradise-lost.txt" + ] + }, + { + "description": "Multiple files, several matches, case-insensitive flag", + "property": "grep", + "pattern": "TO", + "flags": ["-i"], + "files": ["iliad.txt", "midsummer-night.txt", "paradise-lost.txt"], + "expected": [ + "iliad.txt:Caused to Achaia's host, sent many a soul", + "iliad.txt:Illustrious into Ades premature,", + "iliad.txt:And Heroes gave (so stood the will of Jove)", + "iliad.txt:To dogs and to all ravening fowls a prey,", + "midsummer-night.txt:I do entreat your grace to pardon me.", + "midsummer-night.txt:In such a presence here to plead my thoughts;", + "midsummer-night.txt:If I refuse to wed Demetrius.", + "paradise-lost.txt:Brought Death into the World, and all our woe,", + "paradise-lost.txt:Restore us, and regain the blissful Seat,", + "paradise-lost.txt:Sing Heav'nly Muse, that on the secret top" + ] + }, + { + "description": "Multiple files, several matches, inverted flag", + "property": "grep", + "pattern": "a", + "flags": ["-v"], + "files": ["iliad.txt", "midsummer-night.txt", "paradise-lost.txt"], + "expected": [ + "iliad.txt:Achilles sing, O Goddess! Peleus' son;", + "iliad.txt:The noble Chief Achilles from the son", + "midsummer-night.txt:If I refuse to wed Demetrius." + ] + }, + { + "description": "Multiple files, one match, match entire lines flag", + "property": "grep", + "pattern": "But I beseech your grace that I may know", + "flags": ["-x"], + "files": ["iliad.txt", "midsummer-night.txt", "paradise-lost.txt"], + "expected": [ + "midsummer-night.txt:But I beseech your grace that I may know" + ] + }, + { + "description": "Multiple files, one match, multiple flags", + "property": "grep", + "pattern": "WITH LOSS OF EDEN, TILL ONE GREATER MAN", + "flags": ["-n", "-i", "-x"], + "files": ["iliad.txt", "midsummer-night.txt", "paradise-lost.txt"], + "expected": [ + "paradise-lost.txt:4:With loss of Eden, till one greater Man" + ] + }, + { + "description": "Multiple files, no matches, various flags", + "property": "grep", + "pattern": "Frodo", + "flags": ["-n", "-l", "-x", "-i"], + "files": ["iliad.txt", "midsummer-night.txt", "paradise-lost.txt"], + "expected": [] + } + ] } -} \ No newline at end of file + ] +}